Skip to content

Commit

Permalink
Merge pull request #384 from nikore/update_sa_pullsecrets
Browse files Browse the repository at this point in the history
Update imagepullsecrets in service account on existing clusters/serviceaccounts
  • Loading branch information
derekm authored Aug 26, 2021
2 parents aafd465 + dbb8d58 commit 38a3da8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38a3da8

Please sign in to comment.