diff --git a/cmd/kubectl-moco/cmd/stop.go b/cmd/kubectl-moco/cmd/stop.go index 7d0c86b56..03785d602 100644 --- a/cmd/kubectl-moco/cmd/stop.go +++ b/cmd/kubectl-moco/cmd/stop.go @@ -45,6 +45,9 @@ func stopClustering(ctx context.Context, name string) error { orig := cluster.DeepCopy() + if cluster.Annotations == nil { + cluster.Annotations = make(map[string]string) + } cluster.Annotations[constants.AnnClusteringStopped] = "true" if equality.Semantic.DeepEqual(orig, cluster) { @@ -79,6 +82,9 @@ func stopReconciliation(ctx context.Context, name string) error { orig := cluster.DeepCopy() + if cluster.Annotations == nil { + cluster.Annotations = make(map[string]string) + } cluster.Annotations[constants.AnnReconciliationStopped] = "true" if equality.Semantic.DeepEqual(orig, cluster) { diff --git a/controllers/mysqlcluster_controller_test.go b/controllers/mysqlcluster_controller_test.go index f9691bc56..26ae0dbef 100644 --- a/controllers/mysqlcluster_controller_test.go +++ b/controllers/mysqlcluster_controller_test.go @@ -1929,6 +1929,9 @@ var _ = Describe("MySQLCluster reconciler", func() { Expect(err).NotTo(HaveOccurred()) By("setting reconcile stop annotation") + if cluster.Annotations == nil { + cluster.Annotations = map[string]string{} + } cluster.Annotations[constants.AnnReconciliationStopped] = "true" err = k8sClient.Update(ctx, cluster) Expect(err).NotTo(HaveOccurred()) @@ -1956,6 +1959,9 @@ var _ = Describe("MySQLCluster reconciler", func() { Expect(err).NotTo(HaveOccurred()) By("setting clustering stop annotation") + if cluster.Annotations == nil { + cluster.Annotations = map[string]string{} + } cluster.Annotations[constants.AnnClusteringStopped] = "true" err = k8sClient.Update(ctx, cluster) Expect(err).NotTo(HaveOccurred())