This commit is contained in:
Chris Lu 2020-10-14 21:45:53 -07:00
parent fe54fbbaa4
commit c7e0392c1c
6 changed files with 59 additions and 46 deletions

View File

@ -12,7 +12,7 @@ endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= seaweedfs/operator:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
@ -26,8 +26,11 @@ endif
all: manager
# Run tests
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
go test ./... -coverprofile cover.out
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
# Build manager binary
manager: generate fmt vet

View File

@ -17,14 +17,14 @@ func (r *SeaweedReconciler) ensureFilerServers(seaweedCR *seaweedv1.Seaweed) (do
_ = r.Log.WithValues("seaweed", seaweedCR.Name)
if done, result, err = r.ensureFilerStatefulSet(seaweedCR); done {
return done, result, err
return
}
if done, result, err = r.ensureFilerService(seaweedCR); done {
return done, result, err
return
}
return false, ctrl.Result{}, nil
return
}
func (r *SeaweedReconciler) ensureFilerStatefulSet(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
@ -40,16 +40,16 @@ func (r *SeaweedReconciler) ensureFilerStatefulSet(seaweedCR *seaweedv1.Seaweed)
err = r.Create(ctx, dep)
if err != nil {
log.Error(err, "Failed to create new filer statefulset", "Namespace", dep.Namespace, "Name", dep.Name)
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
// Deployment created successfully - return and requeue
return false, ctrl.Result{}, nil
return ReconcileResult(err)
} else if err != nil {
log.Error(err, "Failed to get filer statefulset")
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
log.Info("Get filer stateful set " + filerStatefulSet.Name)
return false, ctrl.Result{}, nil
return ReconcileResult(err)
}
func (r *SeaweedReconciler) ensureFilerService(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
@ -65,16 +65,16 @@ func (r *SeaweedReconciler) ensureFilerService(seaweedCR *seaweedv1.Seaweed) (bo
err = r.Create(ctx, dep)
if err != nil {
log.Error(err, "Failed to create new filer service", "Namespace", dep.Namespace, "Name", dep.Name)
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
// Deployment created successfully - return and requeue
return false, ctrl.Result{}, nil
return ReconcileResult(err)
} else if err != nil {
log.Error(err, "Failed to get filer server service")
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
log.Info("Get filer service " + volumeServerService.Name)
return false, ctrl.Result{}, nil
return ReconcileResult(err)
}
func labelsForFiler(name string) map[string]string {

View File

@ -22,14 +22,14 @@ func (r *SeaweedReconciler) ensureMaster(seaweedCR *seaweedv1.Seaweed) (done boo
_ = r.Log.WithValues("seaweed", seaweedCR.Name)
if done, result, err = r.ensureMasterService(seaweedCR); done {
return done, result, err
return
}
if done, result, err = r.ensureMasterStatefulSet(seaweedCR); done {
return done, result, err
return
}
return false, ctrl.Result{}, nil
return
}
func (r *SeaweedReconciler) ensureMasterStatefulSet(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
@ -45,18 +45,18 @@ func (r *SeaweedReconciler) ensureMasterStatefulSet(seaweedCR *seaweedv1.Seaweed
err = r.Create(ctx, dep)
if err != nil {
log.Error(err, "Failed to create new statefulset", "Namespace", dep.Namespace, "Name", dep.Name)
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
// sleep 60 seconds for DNS to have pod IP addresses ready
time.Sleep(time.Minute)
// Deployment created successfully - return and requeue
return false, ctrl.Result{}, nil
return ReconcileResult(err)
} else if err != nil {
log.Error(err, "Failed to get Deployment")
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
log.Info("Get master stateful set " + masterStatefulSet.Name)
return false, ctrl.Result{}, nil
return ReconcileResult(err)
}
func (r *SeaweedReconciler) ensureMasterService(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
@ -72,16 +72,16 @@ func (r *SeaweedReconciler) ensureMasterService(seaweedCR *seaweedv1.Seaweed) (b
err = r.Create(ctx, dep)
if err != nil {
log.Error(err, "Failed to create master service", "Namespace", dep.Namespace, "Name", dep.Name)
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
// Deployment created successfully - return and requeue
return false, ctrl.Result{}, nil
return ReconcileResult(err)
} else if err != nil {
log.Error(err, "Failed to get master service", "Namespace", seaweedCR.Namespace, "Name", seaweedCR.Name+"-master")
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
log.Info("Get master service " + masterService.Name)
return false, ctrl.Result{}, nil
return ReconcileResult(err)
}

View File

@ -17,14 +17,14 @@ func (r *SeaweedReconciler) ensureS3Servers(seaweedCR *seaweedv1.Seaweed) (done
_ = r.Log.WithValues("seaweed", seaweedCR.Name)
if done, result, err = r.ensureS3Deployment(seaweedCR); done {
return done, result, err
return
}
if done, result, err = r.ensureS3Service(seaweedCR); done {
return done, result, err
return
}
return false, ctrl.Result{}, nil
return
}
func (r *SeaweedReconciler) ensureS3Deployment(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
@ -40,16 +40,16 @@ func (r *SeaweedReconciler) ensureS3Deployment(seaweedCR *seaweedv1.Seaweed) (bo
err = r.Create(ctx, dep)
if err != nil {
log.Error(err, "Failed to create new s3 statefulset", "Namespace", dep.Namespace, "Name", dep.Name)
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
// Deployment created successfully - return and requeue
return false, ctrl.Result{}, nil
return ReconcileResult(err)
} else if err != nil {
log.Error(err, "Failed to get s3 statefulset")
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
log.Info("Get s3 stateful set " + s3Deployment.Name)
return false, ctrl.Result{}, nil
return ReconcileResult(err)
}
func (r *SeaweedReconciler) ensureS3Service(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
@ -65,16 +65,16 @@ func (r *SeaweedReconciler) ensureS3Service(seaweedCR *seaweedv1.Seaweed) (bool,
err = r.Create(ctx, dep)
if err != nil {
log.Error(err, "Failed to create new s3 service", "Namespace", dep.Namespace, "Name", dep.Name)
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
// Deployment created successfully - return and requeue
return false, ctrl.Result{}, nil
return ReconcileResult(err)
} else if err != nil {
log.Error(err, "Failed to get s3 server service")
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
log.Info("Get s3 service " + s3Service.Name)
return false, ctrl.Result{}, nil
return ReconcileResult(err)
}
func labelsForS3(name string) map[string]string {

View File

@ -17,14 +17,14 @@ func (r *SeaweedReconciler) ensureVolumeServers(seaweedCR *seaweedv1.Seaweed) (d
_ = r.Log.WithValues("seaweed", seaweedCR.Name)
if done, result, err = r.ensureVolumeServerStatefulSet(seaweedCR); done {
return done, result, err
return
}
if done, result, err = r.ensureVolumeServerService(seaweedCR); done {
return done, result, err
return
}
return false, ctrl.Result{}, nil
return
}
func (r *SeaweedReconciler) ensureVolumeServerStatefulSet(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
@ -40,16 +40,16 @@ func (r *SeaweedReconciler) ensureVolumeServerStatefulSet(seaweedCR *seaweedv1.S
err = r.Create(ctx, dep)
if err != nil {
log.Error(err, "Failed to create new volume statefulset", "Namespace", dep.Namespace, "Name", dep.Name)
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
// Deployment created successfully - return and requeue
return false, ctrl.Result{}, nil
return ReconcileResult(err)
} else if err != nil {
log.Error(err, "Failed to get volume server statefulset")
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
log.Info("Get volume stateful set " + volumeServerStatefulSet.Name)
return false, ctrl.Result{}, nil
return ReconcileResult(err)
}
func (r *SeaweedReconciler) ensureVolumeServerService(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
@ -65,16 +65,16 @@ func (r *SeaweedReconciler) ensureVolumeServerService(seaweedCR *seaweedv1.Seawe
err = r.Create(ctx, dep)
if err != nil {
log.Error(err, "Failed to create new volume service", "Namespace", dep.Namespace, "Name", dep.Name)
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
// Deployment created successfully - return and requeue
return false, ctrl.Result{}, nil
return ReconcileResult(err)
} else if err != nil {
log.Error(err, "Failed to get volume server service")
return true, ctrl.Result{}, err
return ReconcileResult(err)
}
log.Info("Get volume service " + volumeServerService.Name)
return false, ctrl.Result{}, nil
return ReconcileResult(err)
}
func labelsForVolumeServer(name string) map[string]string {

10
controllers/helper.go Normal file
View File

@ -0,0 +1,10 @@
package controllers
import ctrl "sigs.k8s.io/controller-runtime"
func ReconcileResult(err error) (bool, ctrl.Result, error) {
if err != nil {
return true, ctrl.Result{}, err
}
return false, ctrl.Result{}, nil
}