From a20fe3b82d834cc94c81330a46b6a2ea74e9471f Mon Sep 17 00:00:00 2001 From: "mykyta.oleksiienko" Date: Thu, 15 Feb 2024 14:01:40 +0200 Subject: [PATCH] issue-698, Save default user ref for zookeeper --- .secrets.baseline | 6 +++--- apis/clusters/v1beta1/zookeeper_types.go | 3 ++- .../clusters/v1beta1/zz_generated.deepcopy.go | 5 +++++ .../clusters.instaclustr.com_zookeepers.yaml | 11 +++++++++++ controllers/clusters/zookeeper_controller.go | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 8f5639220..adcd3dfbc 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -374,14 +374,14 @@ "filename": "apis/clusters/v1beta1/zookeeper_types.go", "hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db", "is_verified": false, - "line_number": 234 + "line_number": 235 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/zookeeper_types.go", "hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", "is_verified": false, - "line_number": 239 + "line_number": 240 } ], "apis/clusters/v1beta1/zz_generated.deepcopy.go": [ @@ -1130,5 +1130,5 @@ } ] }, - "generated_at": "2024-02-12T11:41:39Z" + "generated_at": "2024-02-15T12:14:33Z" } diff --git a/apis/clusters/v1beta1/zookeeper_types.go b/apis/clusters/v1beta1/zookeeper_types.go index c4bda24f2..22e502bc5 100644 --- a/apis/clusters/v1beta1/zookeeper_types.go +++ b/apis/clusters/v1beta1/zookeeper_types.go @@ -45,7 +45,8 @@ type ZookeeperStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster // Important: Run "make" to regenerate code after modifying this file - ClusterStatus `json:",inline"` + ClusterStatus `json:",inline"` + DefaultUserSecretRef *Reference `json:"defaultRef,omitempty"` } //+kubebuilder:object:root=true diff --git a/apis/clusters/v1beta1/zz_generated.deepcopy.go b/apis/clusters/v1beta1/zz_generated.deepcopy.go index 9dfb532d6..a19ccb2af 100644 --- a/apis/clusters/v1beta1/zz_generated.deepcopy.go +++ b/apis/clusters/v1beta1/zz_generated.deepcopy.go @@ -3095,6 +3095,11 @@ func (in *ZookeeperSpec) DeepCopy() *ZookeeperSpec { func (in *ZookeeperStatus) DeepCopyInto(out *ZookeeperStatus) { *out = *in in.ClusterStatus.DeepCopyInto(&out.ClusterStatus) + if in.DefaultUserSecretRef != nil { + in, out := &in.DefaultUserSecretRef, &out.DefaultUserSecretRef + *out = new(apiextensions.ObjectReference) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ZookeeperStatus. diff --git a/config/crd/bases/clusters.instaclustr.com_zookeepers.yaml b/config/crd/bases/clusters.instaclustr.com_zookeepers.yaml index badcbe5d3..07c9e6285 100644 --- a/config/crd/bases/clusters.instaclustr.com_zookeepers.yaml +++ b/config/crd/bases/clusters.instaclustr.com_zookeepers.yaml @@ -141,6 +141,17 @@ spec: status: description: ZookeeperStatus defines the observed state of Zookeeper properties: + DefaultRef: + description: ObjectReference is namespaced reference to an object + properties: + name: + type: string + namespace: + type: string + required: + - name + - namespace + type: object cdcid: type: string currentClusterOperationStatus: diff --git a/controllers/clusters/zookeeper_controller.go b/controllers/clusters/zookeeper_controller.go index 113f842a4..38a892a9a 100644 --- a/controllers/clusters/zookeeper_controller.go +++ b/controllers/clusters/zookeeper_controller.go @@ -211,6 +211,7 @@ func (r *ZookeeperReconciler) createDefaultSecret(ctx context.Context, zk *v1bet return err } + patch := zk.NewPatch() secret := zk.NewDefaultUserSecret(username, password) err = r.Create(ctx, secret) if err != nil { @@ -224,6 +225,24 @@ func (r *ZookeeperReconciler) createDefaultSecret(ctx context.Context, zk *v1bet return err } + zk.Status.DefaultUserSecretRef = &v1beta1.Reference{ + Name: secret.Name, + Namespace: secret.Namespace, + } + + err = r.Status().Patch(ctx, zk, patch) + if err != nil { + l.Error(err, "Cannot patch Zookeeper resource", + "cluster name", zk.Spec.Name, + "status", zk.Status) + + r.EventRecorder.Eventf( + zk, models.Warning, models.PatchFailed, + "Cluster resource patch is failed. Reason: %v", err) + + return err + } + return nil }