From b7758c02924ccb1eb73cba521fa61d171258fa73 Mon Sep 17 00:00:00 2001 From: "mykyta.oleksiienko" Date: Mon, 4 Mar 2024 15:33:33 +0200 Subject: [PATCH] issue-728, default user secret already exists error --- .secrets.baseline | 12 ++++++------ controllers/clusters/cassandra_controller.go | 12 ++++++++++++ pkg/models/operator.go | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index c7107856..d92e7b68 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -1075,35 +1075,35 @@ "filename": "pkg/models/operator.go", "hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", "is_verified": false, - "line_number": 154 + "line_number": 155 }, { "type": "Secret Keyword", "filename": "pkg/models/operator.go", "hashed_secret": "d65d45369e8aef106a8ca1c3bad151ad24163494", "is_verified": false, - "line_number": 184 + "line_number": 185 }, { "type": "Secret Keyword", "filename": "pkg/models/operator.go", "hashed_secret": "638724dcc0799a22cc4adce12434fcac73c8af58", "is_verified": false, - "line_number": 185 + "line_number": 186 }, { "type": "Secret Keyword", "filename": "pkg/models/operator.go", "hashed_secret": "4fe486f255f36f8787d5c5cc1185e3d5d5c91c03", "is_verified": false, - "line_number": 186 + "line_number": 187 }, { "type": "Secret Keyword", "filename": "pkg/models/operator.go", "hashed_secret": "2331919a92cbb5c2d530947171fa5e1a1415af2f", "is_verified": false, - "line_number": 187 + "line_number": 188 } ], "pkg/utils/user_creds_from_secret_test.go": [ @@ -1132,5 +1132,5 @@ } ] }, - "generated_at": "2024-02-29T10:48:32Z" + "generated_at": "2024-03-04T13:33:17Z" } diff --git a/controllers/clusters/cassandra_controller.go b/controllers/clusters/cassandra_controller.go index 6f7f0248..4eec4d2b 100644 --- a/controllers/clusters/cassandra_controller.go +++ b/controllers/clusters/cassandra_controller.go @@ -908,6 +908,18 @@ func (r *CassandraReconciler) createDefaultSecret(ctx context.Context, c *v1beta patch := c.NewPatch() secret := newDefaultUserSecret(username, password, c.Name, c.Namespace) + err = controllerutil.SetOwnerReference(c, secret, r.Scheme) + if err != nil { + l.Error(err, "Cannot set secret owner reference with default user credentials", + "cluster ID", c.Status.ID, + ) + r.EventRecorder.Eventf(c, models.Warning, models.SetOwnerRef, + "Setting secret owner ref with default user credentials is failed. Reason: %v", err, + ) + + return err + } + err = r.Create(ctx, secret) if err != nil { l.Error(err, "Cannot create secret with default user credentials", diff --git a/pkg/models/operator.go b/pkg/models/operator.go index 3b0cfb24..b0ab4911 100644 --- a/pkg/models/operator.go +++ b/pkg/models/operator.go @@ -143,6 +143,7 @@ const ( DeletionFailed = "DeletionFailed" Deleted = "Deleted" ExternalDeleted = "ExternalDeleted" + SetOwnerRef = "SettingOwnerRefFailed" ) const (