From 18e8a9472f0214074ac1bbf413dd53ba035ee102 Mon Sep 17 00:00:00 2001 From: "mykyta.oleksiienko" Date: Fri, 16 Feb 2024 14:41:40 +0200 Subject: [PATCH] issue-698, Save default user ref for kafkaconnect --- .secrets.baseline | 28 +++++++++---------- apis/clusters/v1beta1/kafkaconnect_types.go | 3 +- .../clusters/v1beta1/zz_generated.deepcopy.go | 5 ++++ ...lusters.instaclustr.com_kafkaconnects.yaml | 11 ++++++++ .../clusters/kafkaconnect_controller.go | 19 +++++++++++++ 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index adcd3dfbc..f122a7322 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -233,84 +233,84 @@ "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "46fe9b29395041087f91b33bd8c5c6177cd42fd1", "is_verified": false, - "line_number": 246 + "line_number": 247 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "4b3af1508421e2fa591c5b260c36dd06fdd872a5", "is_verified": false, - "line_number": 284 + "line_number": 285 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "cf45830dd81b7e1a8b5ffbc2d95b112771524117", "is_verified": false, - "line_number": 294 + "line_number": 295 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "138905ac46675150bf790088ec56b2efc6a64697", "is_verified": false, - "line_number": 305 + "line_number": 306 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "3948059919ffeee8ecc42149cb386f43d2f06f74", "is_verified": false, - "line_number": 310 + "line_number": 311 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "87f1180476a944c4162d1af55efedc8f3e3b609c", "is_verified": false, - "line_number": 519 + "line_number": 520 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "f0f06c9167ce61a586749bb183ac6a3756dd6010", "is_verified": false, - "line_number": 529 + "line_number": 530 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "2042128e13ef5ede4af44271160c72f64564c632", "is_verified": false, - "line_number": 540 + "line_number": 541 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "82dc9ca8ba09262ce948227aeb5d9db8084eeb5d", "is_verified": false, - "line_number": 545 + "line_number": 546 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "5f915325aef923cdc945f639f14c2f854b4214d6", "is_verified": false, - "line_number": 569 + "line_number": 570 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db", "is_verified": false, - "line_number": 602 + "line_number": 603 }, { "type": "Secret Keyword", "filename": "apis/clusters/v1beta1/kafkaconnect_types.go", "hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", "is_verified": false, - "line_number": 607 + "line_number": 608 } ], "apis/clusters/v1beta1/postgresql_types.go": [ @@ -390,7 +390,7 @@ "filename": "apis/clusters/v1beta1/zz_generated.deepcopy.go", "hashed_secret": "44e17306b837162269a410204daaa5ecee4ec22c", "is_verified": false, - "line_number": 2290 + "line_number": 1322 } ], "apis/kafkamanagement/v1beta1/kafkauser_types.go": [ @@ -1130,5 +1130,5 @@ } ] }, - "generated_at": "2024-02-15T12:14:33Z" + "generated_at": "2024-02-16T12:41:16Z" } diff --git a/apis/clusters/v1beta1/kafkaconnect_types.go b/apis/clusters/v1beta1/kafkaconnect_types.go index d4363e15e..8cd9cda8c 100644 --- a/apis/clusters/v1beta1/kafkaconnect_types.go +++ b/apis/clusters/v1beta1/kafkaconnect_types.go @@ -119,7 +119,8 @@ type KafkaConnectSpec struct { // KafkaConnectStatus defines the observed state of KafkaConnect type KafkaConnectStatus struct { ClusterStatus `json:",inline"` - TargetKafkaClusterID string `json:"targetKafkaClusterId,omitempty"` + TargetKafkaClusterID string `json:"targetKafkaClusterId,omitempty"` + DefaultUserSecretRef *Reference `json:"defaultUserSecretRef,omitempty"` } //+kubebuilder:object:root=true diff --git a/apis/clusters/v1beta1/zz_generated.deepcopy.go b/apis/clusters/v1beta1/zz_generated.deepcopy.go index a19ccb2af..50c6ab8cf 100644 --- a/apis/clusters/v1beta1/zz_generated.deepcopy.go +++ b/apis/clusters/v1beta1/zz_generated.deepcopy.go @@ -1319,6 +1319,11 @@ func (in *KafkaConnectSpec) DeepCopy() *KafkaConnectSpec { func (in *KafkaConnectStatus) DeepCopyInto(out *KafkaConnectStatus) { *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 KafkaConnectStatus. diff --git a/config/crd/bases/clusters.instaclustr.com_kafkaconnects.yaml b/config/crd/bases/clusters.instaclustr.com_kafkaconnects.yaml index fefddd33c..4f51936db 100644 --- a/config/crd/bases/clusters.instaclustr.com_kafkaconnects.yaml +++ b/config/crd/bases/clusters.instaclustr.com_kafkaconnects.yaml @@ -381,6 +381,17 @@ spec: type: string type: object type: array + defaultUserSecretRef: + description: ObjectReference is namespaced reference to an object + properties: + name: + type: string + namespace: + type: string + required: + - name + - namespace + type: object id: type: string maintenanceEvents: diff --git a/controllers/clusters/kafkaconnect_controller.go b/controllers/clusters/kafkaconnect_controller.go index ee4b2b7f6..7d3c4356d 100644 --- a/controllers/clusters/kafkaconnect_controller.go +++ b/controllers/clusters/kafkaconnect_controller.go @@ -437,6 +437,7 @@ func (r *KafkaConnectReconciler) createDefaultSecret(ctx context.Context, kc *v1 return err } + patch := kc.NewPatch() secret := kc.NewDefaultUserSecret(username, password) err = r.Create(ctx, secret) if err != nil { @@ -455,6 +456,24 @@ func (r *KafkaConnectReconciler) createDefaultSecret(ctx context.Context, kc *v1 "secret namespace", secret.Namespace, ) + kc.Status.DefaultUserSecretRef = &v1beta1.Reference{ + Name: secret.Name, + Namespace: secret.Namespace, + } + + err = r.Status().Patch(ctx, kc, patch) + if err != nil { + l.Error(err, "Cannot patch Kafka Connect resource", + "cluster name", kc.Spec.Name, + "status", kc.Status) + + r.EventRecorder.Eventf( + kc, models.Warning, models.PatchFailed, + "Cluster resource patch is failed. Reason: %v", err) + + return err + } + return nil }