1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

Moved PVC+Services to resources package

This commit is contained in:
Ewout Prangsma 2018-03-23 15:01:56 +01:00
parent 2dc7ceeda2
commit d76295ab27
No known key found for this signature in database
GPG key ID: 4DBAD380D93D0698
4 changed files with 40 additions and 25 deletions

View file

@ -176,7 +176,7 @@ func (d *Deployment) run() {
}
// Create services
if err := d.createServices(d.apiObject); err != nil {
if err := d.resources.EnsureServices(); err != nil {
d.failOnError(err, "Failed to create services")
return
}
@ -188,7 +188,7 @@ func (d *Deployment) run() {
}
// Create PVCs
if err := d.ensurePVCs(d.apiObject); err != nil {
if err := d.resources.EnsurePVCs(); err != nil {
d.failOnError(err, "Failed to create persistent volume claims")
return
}

View file

@ -74,7 +74,11 @@ func (d *Deployment) inspectDeployment(lastInterval time.Duration) time.Duration
}
// Ensure all resources are created
if err := d.ensurePVCs(d.apiObject); err != nil {
if err := d.resources.EnsureServices(); err != nil {
hasError = true
d.CreateEvent(k8sutil.NewErrorEvent("Service creation failed", err, d.apiObject))
}
if err := d.resources.EnsurePVCs(); err != nil {
hasError = true
d.CreateEvent(k8sutil.NewErrorEvent("PVC creation failed", err, d.apiObject))
}

View file

@ -20,7 +20,7 @@
// Author Ewout Prangsma
//
package deployment
package resources
import (
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
@ -28,14 +28,17 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
)
// ensurePVCs creates all PVC's listed in member status
func (d *Deployment) ensurePVCs(apiObject *api.ArangoDeployment) error {
kubecli := d.deps.KubeCli
// EnsurePVCs creates all PVC's listed in member status
func (r *Resources) EnsurePVCs() error {
kubecli := r.context.GetKubeCli()
apiObject := r.context.GetAPIObject()
deploymentName := apiObject.GetName()
ns := apiObject.GetNamespace()
owner := apiObject.AsOwner()
iterator := r.context.GetServerGroupIterator()
status := r.context.GetStatus()
if err := apiObject.ForeachServerGroup(func(group api.ServerGroup, spec api.ServerGroupSpec, status *api.MemberStatusList) error {
if err := iterator.ForeachServerGroup(func(group api.ServerGroup, spec api.ServerGroupSpec, status *api.MemberStatusList) error {
for _, m := range *status {
if m.PersistentVolumeClaimName != "" {
storageClassName := spec.GetStorageClassName()
@ -47,7 +50,7 @@ func (d *Deployment) ensurePVCs(apiObject *api.ArangoDeployment) error {
}
}
return nil
}, &d.status); err != nil {
}, &status); err != nil {
return maskAny(err)
}
return nil

View file

@ -20,18 +20,19 @@
// Author Ewout Prangsma
//
package deployment
package resources
import (
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
)
// createServices creates all services needed to service the given deployment
func (d *Deployment) createServices(apiObject *api.ArangoDeployment) error {
log := d.deps.Log
kubecli := d.deps.KubeCli
// EnsureServices creates all services needed to service the deployment
func (r *Resources) EnsureServices() error {
log := r.log
kubecli := r.context.GetKubeCli()
apiObject := r.context.GetAPIObject()
owner := apiObject.AsOwner()
spec := r.context.GetSpec()
log.Debug().Msg("creating services...")
@ -39,23 +40,30 @@ func (d *Deployment) createServices(apiObject *api.ArangoDeployment) error {
log.Debug().Err(err).Msg("Failed to create headless service")
return maskAny(err)
}
single := apiObject.Spec.GetMode().HasSingleServers()
if svcName, err := k8sutil.CreateDatabaseClientService(kubecli, apiObject, single, owner); err != nil {
single := spec.GetMode().HasSingleServers()
svcName, err := k8sutil.CreateDatabaseClientService(kubecli, apiObject, single, owner)
if err != nil {
log.Debug().Err(err).Msg("Failed to create database client service")
return maskAny(err)
} else {
d.status.ServiceName = svcName
if err := d.updateCRStatus(); err != nil {
}
status := r.context.GetStatus()
if status.ServiceName != svcName {
status.ServiceName = svcName
if err := r.context.UpdateStatus(status); err != nil {
return maskAny(err)
}
}
if apiObject.Spec.Sync.IsEnabled() {
if svcName, err := k8sutil.CreateSyncMasterClientService(kubecli, apiObject, owner); err != nil {
if spec.Sync.IsEnabled() {
svcName, err := k8sutil.CreateSyncMasterClientService(kubecli, apiObject, owner)
if err != nil {
log.Debug().Err(err).Msg("Failed to create syncmaster client service")
return maskAny(err)
} else {
d.status.ServiceName = svcName
if err := d.updateCRStatus(); err != nil {
}
status := r.context.GetStatus()
if status.SyncServiceName != svcName {
status.SyncServiceName = svcName
if err := r.context.UpdateStatus(status); err != nil {
return maskAny(err)
}
}