diff --git a/pkg/controller/zookeepercluster/zookeepercluster_controller.go b/pkg/controller/zookeepercluster/zookeepercluster_controller.go index e48c3509e..e59e8af19 100644 --- a/pkg/controller/zookeepercluster/zookeepercluster_controller.go +++ b/pkg/controller/zookeepercluster/zookeepercluster_controller.go @@ -235,6 +235,13 @@ func (r *ReconcileZookeeperCluster) reconcileStatefulSet(instance *zookeeperv1be } } else if err != nil { return err + } else { + foundServiceAccount.ImagePullSecrets = serviceAccount.ImagePullSecrets + r.log.Info("Updating ServiceAccount", "ServiceAccount.Namespace", serviceAccount.Namespace, "ServiceAccount.Name", serviceAccount.Name) + err = r.client.Update(context.TODO(), foundServiceAccount) + if err != nil { + return err + } } } sts := zk.MakeStatefulSet(instance) diff --git a/pkg/controller/zookeepercluster/zookeepercluster_controller_test.go b/pkg/controller/zookeepercluster/zookeepercluster_controller_test.go index 55b5347db..0a2af8523 100644 --- a/pkg/controller/zookeepercluster/zookeepercluster_controller_test.go +++ b/pkg/controller/zookeepercluster/zookeepercluster_controller_test.go @@ -250,6 +250,49 @@ var _ = Describe("ZookeeperCluster Controller", func() { }) + Context("With update to ImagePullSecrets", func() { + var ( + cl client.Client + err error + next *v1beta1.ZookeeperCluster + sa *corev1.ServiceAccount + ) + + BeforeEach(func() { + z.WithDefaults() + z.Spec.Pod.ServiceAccountName = "zookeeper" + z.Status.Init() + next = z.DeepCopy() + sa = zk.MakeServiceAccount(z) + cl = fake.NewFakeClientWithScheme(s, []runtime.Object{next, sa}...) + r = &ReconcileZookeeperCluster{client: cl, scheme: s, zkClient: mockZkClient} + res, err = r.Reconcile(req) + }) + + It("should not raise an error", func() { + Ω(err).To(BeNil()) + }) + + It("should create the service account", func() { + foundSA := &corev1.ServiceAccount{} + err = cl.Get(context.TODO(), types.NamespacedName{Name: "zookeeper", Namespace: Namespace}, foundSA) + Ω(err).To(BeNil()) + Ω(foundSA.ImagePullSecrets).To(HaveLen(0)) + }) + It("should update the service account", func() { + next.Spec.Pod.ImagePullSecrets = []corev1.LocalObjectReference{{Name: "test-pull-secret"}} + cl = fake.NewFakeClientWithScheme(s, []runtime.Object{next, sa}...) + r = &ReconcileZookeeperCluster{client: cl, scheme: s, zkClient: mockZkClient} + _, err := r.Reconcile(req) + Ω(err).To(BeNil()) + + foundSA := &corev1.ServiceAccount{} + err = cl.Get(context.TODO(), types.NamespacedName{Name: "zookeeper", Namespace: Namespace}, foundSA) + Ω(err).To(BeNil()) + Ω(foundSA.ImagePullSecrets).To(HaveLen(1)) + }) + }) + Context("upgrading the image for zookeepercluster", func() { var ( cl client.Client