From 4bb6f99cd83ecaeb8d1a273373033e6fddca5701 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 17 Oct 2020 02:25:23 -0700 Subject: [PATCH] support upgrade --- api/v1/seaweed_types.go | 3 +++ .../crd/bases/seaweed.seaweedfs.com_seaweeds.yaml | 3 +++ config/samples/seaweed_v1_seaweed.yaml | 1 + controllers/controller_filer.go | 4 +++- controllers/controller_filer_statefulset.go | 2 +- controllers/controller_master.go | 14 +++++++++++++- controllers/controller_master_statefulset.go | 2 +- controllers/controller_volume.go | 4 +++- controllers/controller_volume_statefulset.go | 2 +- 9 files changed, 29 insertions(+), 6 deletions(-) diff --git a/api/v1/seaweed_types.go b/api/v1/seaweed_types.go index 2e08556..33f1559 100644 --- a/api/v1/seaweed_types.go +++ b/api/v1/seaweed_types.go @@ -31,6 +31,9 @@ type SeaweedSpec struct { // MetricsAddress is Prometheus gateway address MetricsAddress string `json:"metricsAddress,omitempty"` + // Image + Image string `json:"image,omitempty"` + // VolumeServerCount is the number of volume servers, default to 1 VolumeServerCount int32 `json:"volumeServerCount,omitempty"` diff --git a/config/crd/bases/seaweed.seaweedfs.com_seaweeds.yaml b/config/crd/bases/seaweed.seaweedfs.com_seaweeds.yaml index 566a871..d14cc5e 100644 --- a/config/crd/bases/seaweed.seaweedfs.com_seaweeds.yaml +++ b/config/crd/bases/seaweed.seaweedfs.com_seaweeds.yaml @@ -40,6 +40,9 @@ spec: description: FilerCount is the number of filers, default to 1 format: int32 type: integer + image: + description: Image + type: string metricsAddress: description: MetricsAddress is Prometheus gateway address type: string diff --git a/config/samples/seaweed_v1_seaweed.yaml b/config/samples/seaweed_v1_seaweed.yaml index 99ee9ac..ef5987f 100644 --- a/config/samples/seaweed_v1_seaweed.yaml +++ b/config/samples/seaweed_v1_seaweed.yaml @@ -4,5 +4,6 @@ metadata: name: seaweed1 spec: # Add fields here + image: chrislusf/seaweedfs:2.03 volumeServerCount: 4 filerCount: 2 diff --git a/controllers/controller_filer.go b/controllers/controller_filer.go index 3c0d73e..7e050d1 100644 --- a/controllers/controller_filer.go +++ b/controllers/controller_filer.go @@ -49,8 +49,10 @@ func (r *SeaweedReconciler) ensureFilerStatefulSet(seaweedCR *seaweedv1.Seaweed) return ReconcileResult(err) } - if *filerStatefulSet.Spec.Replicas != seaweedCR.Spec.FilerCount { + if *filerStatefulSet.Spec.Replicas != seaweedCR.Spec.FilerCount || + filerStatefulSet.Spec.Template.Spec.Containers[0].Image != seaweedCR.Spec.Image { filerStatefulSet.Spec.Replicas = &seaweedCR.Spec.FilerCount + filerStatefulSet.Spec.Template.Spec.Containers[0].Image = seaweedCR.Spec.Image if err = r.Update(ctx, filerStatefulSet); err != nil { log.Error(err, "Failed to update filer statefulset", "Namespace", filerStatefulSet.Namespace, "Name", filerStatefulSet.Name) return ReconcileResult(err) diff --git a/controllers/controller_filer_statefulset.go b/controllers/controller_filer_statefulset.go index 80e3bce..69c0295 100644 --- a/controllers/controller_filer_statefulset.go +++ b/controllers/controller_filer_statefulset.go @@ -42,7 +42,7 @@ func (r *SeaweedReconciler) createFilerStatefulSet(m *seaweedv1.Seaweed) *appsv1 EnableServiceLinks: &enableServiceLinks, Containers: []corev1.Container{{ Name: "seaweedfs", - Image: "chrislusf/seaweedfs:latest", + Image: m.Spec.Image, ImagePullPolicy: corev1.PullIfNotPresent, Env: []corev1.EnvVar{ { diff --git a/controllers/controller_master.go b/controllers/controller_master.go index fbcb19d..08fcef2 100644 --- a/controllers/controller_master.go +++ b/controllers/controller_master.go @@ -44,7 +44,7 @@ func (r *SeaweedReconciler) ensureMasterStatefulSet(seaweedCR *seaweedv1.Seaweed log.Info("Creating a new master statefulset", "Namespace", dep.Namespace, "Name", dep.Name) err = r.Create(ctx, dep) if err != nil { - log.Error(err, "Failed to create new statefulset", "Namespace", dep.Namespace, "Name", dep.Name) + log.Error(err, "Failed to create master statefulset", "Namespace", dep.Namespace, "Name", dep.Name) return ReconcileResult(err) } // sleep 60 seconds for DNS to have pod IP addresses ready @@ -55,6 +55,18 @@ func (r *SeaweedReconciler) ensureMasterStatefulSet(seaweedCR *seaweedv1.Seaweed log.Error(err, "Failed to get Deployment") return ReconcileResult(err) } + + log.Info("master version " + masterStatefulSet.Spec.Template.Spec.Containers[0].Image + " expected " + seaweedCR.Spec.Image) + if masterStatefulSet.Spec.Template.Spec.Containers[0].Image != seaweedCR.Spec.Image { + masterStatefulSet.Spec.Template.Spec.Containers[0].Image = seaweedCR.Spec.Image + if err = r.Update(ctx, masterStatefulSet); err != nil { + log.Error(err, "Failed to update master statefulset", "Namespace", masterStatefulSet.Namespace, "Name", masterStatefulSet.Name) + return ReconcileResult(err) + } + // Deployment created successfully - return and requeue + return ReconcileResult(err) + } + log.Info("Get master stateful set " + masterStatefulSet.Name) return ReconcileResult(err) } diff --git a/controllers/controller_master_statefulset.go b/controllers/controller_master_statefulset.go index 4cb4c3d..1ce217e 100644 --- a/controllers/controller_master_statefulset.go +++ b/controllers/controller_master_statefulset.go @@ -56,7 +56,7 @@ func (r *SeaweedReconciler) createMasterStatefulSet(m *seaweedv1.Seaweed) *appsv EnableServiceLinks: &enableServiceLinks, Containers: []corev1.Container{{ Name: "seaweedfs", - Image: "chrislusf/seaweedfs:latest", + Image: m.Spec.Image, ImagePullPolicy: corev1.PullIfNotPresent, Env: []corev1.EnvVar{ { diff --git a/controllers/controller_volume.go b/controllers/controller_volume.go index d86328d..dbd7709 100644 --- a/controllers/controller_volume.go +++ b/controllers/controller_volume.go @@ -49,8 +49,10 @@ func (r *SeaweedReconciler) ensureVolumeServerStatefulSet(seaweedCR *seaweedv1.S return ReconcileResult(err) } - if *volumeServerStatefulSet.Spec.Replicas != seaweedCR.Spec.VolumeServerCount { + if *volumeServerStatefulSet.Spec.Replicas != seaweedCR.Spec.VolumeServerCount || + volumeServerStatefulSet.Spec.Template.Spec.Containers[0].Image != seaweedCR.Spec.Image { volumeServerStatefulSet.Spec.Replicas = &seaweedCR.Spec.VolumeServerCount + volumeServerStatefulSet.Spec.Template.Spec.Containers[0].Image = seaweedCR.Spec.Image if err = r.Update(ctx, volumeServerStatefulSet); err != nil { log.Error(err, "Failed to update volume statefulset", "Namespace", volumeServerStatefulSet.Namespace, "Name", volumeServerStatefulSet.Name) return ReconcileResult(err) diff --git a/controllers/controller_volume_statefulset.go b/controllers/controller_volume_statefulset.go index 94dc3e9..c69dc7f 100644 --- a/controllers/controller_volume_statefulset.go +++ b/controllers/controller_volume_statefulset.go @@ -42,7 +42,7 @@ func (r *SeaweedReconciler) createVolumeServerStatefulSet(m *seaweedv1.Seaweed) EnableServiceLinks: &enableServiceLinks, Containers: []corev1.Container{{ Name: "seaweedfs", - Image: "chrislusf/seaweedfs:latest", + Image: m.Spec.Image, ImagePullPolicy: corev1.PullIfNotPresent, Env: []corev1.EnvVar{ {