From 7385c2c35898091ef11fde8983bef2849e5d0f11 Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Tue, 12 Mar 2024 15:09:34 +0100 Subject: [PATCH 1/4] #1240 set the PullSecretRef configured for medusa as imagePullSecrets at the standalone deployment --- controllers/k8ssandra/medusa_reconciler.go | 2 +- pkg/medusa/reconcile.go | 7 +++-- pkg/medusa/reconcile_test.go | 36 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/controllers/k8ssandra/medusa_reconciler.go b/controllers/k8ssandra/medusa_reconciler.go index 6894a0526..a71629f43 100644 --- a/controllers/k8ssandra/medusa_reconciler.go +++ b/controllers/k8ssandra/medusa_reconciler.go @@ -83,7 +83,7 @@ func (r *K8ssandraClusterReconciler) reconcileMedusa( } // Create the Medusa standalone pod - desiredMedusaStandalone := medusa.StandaloneMedusaDeployment(*medusaContainer, kc.SanitizedName(), dcConfig.SanitizedName(), namespace, logger) + desiredMedusaStandalone := medusa.StandaloneMedusaDeployment(*medusaContainer, kc.SanitizedName(), dcConfig.SanitizedName(), namespace, logger, kc.Spec.Medusa.ContainerImage) // Add the volumes previously computed to the Medusa standalone pod for _, volume := range volumes { diff --git a/pkg/medusa/reconcile.go b/pkg/medusa/reconcile.go index 27c49cbfa..81d4922d9 100644 --- a/pkg/medusa/reconcile.go +++ b/pkg/medusa/reconcile.go @@ -501,7 +501,7 @@ func MedusaPurgeCronJobName(clusterName string, dcName string) string { return fmt.Sprintf("%s-%s-medusa-purge", clusterName, dcName) } -func StandaloneMedusaDeployment(medusaContainer corev1.Container, clusterName, dcName, namespace string, logger logr.Logger) *appsv1.Deployment { +func StandaloneMedusaDeployment(medusaContainer corev1.Container, clusterName, dcName, namespace string, logger logr.Logger, medusaImage *images.Image) *appsv1.Deployment { // The standalone medusa pod won't be able to resolve its own IP address using DNS entries medusaContainer.Env = append(medusaContainer.Env, corev1.EnvVar{Name: "MEDUSA_RESOLVE_IP_ADDRESSES", Value: "False"}) medusaDeployment := &appsv1.Deployment{ @@ -526,8 +526,9 @@ func StandaloneMedusaDeployment(medusaContainer corev1.Container, clusterName, d Containers: []corev1.Container{ medusaContainer, }, - Volumes: []corev1.Volume{}, - Hostname: MedusaStandaloneDeploymentName(clusterName, dcName), + ImagePullSecrets: images.CollectPullSecrets(medusaImage.ApplyDefaults(*medusaImage)), + Volumes: []corev1.Volume{}, + Hostname: MedusaStandaloneDeploymentName(clusterName, dcName), }, }, }, diff --git a/pkg/medusa/reconcile_test.go b/pkg/medusa/reconcile_test.go index e55f2abd7..bcf953127 100644 --- a/pkg/medusa/reconcile_test.go +++ b/pkg/medusa/reconcile_test.go @@ -9,6 +9,7 @@ import ( api "github.com/k8ssandra/k8ssandra-operator/apis/k8ssandra/v1alpha1" medusaapi "github.com/k8ssandra/k8ssandra-operator/apis/medusa/v1alpha1" "github.com/k8ssandra/k8ssandra-operator/pkg/cassandra" + "github.com/k8ssandra/k8ssandra-operator/pkg/images" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -527,6 +528,41 @@ func TestInitContainerCustomResources(t *testing.T) { } +func TestStandaloneMedusaDeploymentImageSettings(t *testing.T) { + medusaSpec := &medusaapi.MedusaClusterTemplate{ + StorageProperties: medusaapi.Storage{ + StorageProvider: "s3", + StorageSecretRef: corev1.LocalObjectReference{ + Name: "secret", + }, + BucketName: "bucket", + }, + ContainerImage: &images.Image{ + Registry: "reg1", + Name: "img1", + Repository: "repo1", + Tag: "tag1", + PullPolicy: "Always", + PullSecretRef: &corev1.LocalObjectReference{Name: "main-secret"}, + }, + } + + dcConfig := cassandra.DatacenterConfig{} + + logger := logr.New(logr.Discard().GetSink()) + + medusaContainer, err := CreateMedusaMainContainer(&dcConfig, medusaSpec, false, "test", logger) + assert.NoError(t, err) + UpdateMedusaInitContainer(&dcConfig, medusaSpec, false, "test", logger) + UpdateMedusaMainContainer(&dcConfig, medusaContainer) + + desiredMedusaStandalone := StandaloneMedusaDeployment(*medusaContainer, "dc1", dcConfig.SanitizedName(), "test", logger, medusaSpec.ContainerImage) + + assert.Equal(t, "main-secret", *&desiredMedusaStandalone.Spec.Template.Spec.ImagePullSecrets[0].Name, "expected standalone container image pull secret to be set") + assert.Equal(t, "reg1/repo1/img1:tag1", *&desiredMedusaStandalone.Spec.Template.Spec.Containers[0].Image, "expected standalone container image to be set to reg1/repo1/img1:tag1") + assert.Equal(t, corev1.PullAlways, *&desiredMedusaStandalone.Spec.Template.Spec.Containers[0].ImagePullPolicy, "expected standalone pull policy to be set to Always") +} + func TestExternalSecretsFlag(t *testing.T) { medusaSpec := &medusaapi.MedusaClusterTemplate{ StorageProperties: medusaapi.Storage{ From 321decdbfee86dec3b88616488915bdc3d907033 Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Tue, 12 Mar 2024 15:11:56 +0100 Subject: [PATCH 2/4] #1240 added fix to Changelog.md --- CHANGELOG/CHANGELOG-1.14.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG/CHANGELOG-1.14.md b/CHANGELOG/CHANGELOG-1.14.md index a9aa4e8dc..5e19f50e2 100644 --- a/CHANGELOG/CHANGELOG-1.14.md +++ b/CHANGELOG/CHANGELOG-1.14.md @@ -14,4 +14,5 @@ Changelog for the K8ssandra Operator, new PRs should update the `unreleased` sec When cutting a new release, update the `unreleased` heading to the tag being generated and date, like `## vX.Y.Z - YYYY-MM-DD` and create a new placeholder section for `unreleased` entries. ## unreleased -* [BUGFIX] [#1226](https://github.com/k8ssandra/k8ssandra-operator/issues/1226) Medusa purge cronjob should be created in the operator namespace \ No newline at end of file +* [BUGFIX] [#1226](https://github.com/k8ssandra/k8ssandra-operator/issues/1226) Medusa purge cronjob should be created in the operator namespace +* [BUGFIX] [#1240](https://github.com/k8ssandra/k8ssandra-operator/issues/1240) The PullSecretRef for medusa is ignored in the standalone deployment of medusa \ No newline at end of file From 5b107f360b1df599de649c1115dda9b91ebfef8d Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Tue, 12 Mar 2024 15:24:08 +0100 Subject: [PATCH 3/4] #1240 make the linter happy --- pkg/medusa/reconcile_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/medusa/reconcile_test.go b/pkg/medusa/reconcile_test.go index bcf953127..4fd2591ad 100644 --- a/pkg/medusa/reconcile_test.go +++ b/pkg/medusa/reconcile_test.go @@ -558,9 +558,9 @@ func TestStandaloneMedusaDeploymentImageSettings(t *testing.T) { desiredMedusaStandalone := StandaloneMedusaDeployment(*medusaContainer, "dc1", dcConfig.SanitizedName(), "test", logger, medusaSpec.ContainerImage) - assert.Equal(t, "main-secret", *&desiredMedusaStandalone.Spec.Template.Spec.ImagePullSecrets[0].Name, "expected standalone container image pull secret to be set") - assert.Equal(t, "reg1/repo1/img1:tag1", *&desiredMedusaStandalone.Spec.Template.Spec.Containers[0].Image, "expected standalone container image to be set to reg1/repo1/img1:tag1") - assert.Equal(t, corev1.PullAlways, *&desiredMedusaStandalone.Spec.Template.Spec.Containers[0].ImagePullPolicy, "expected standalone pull policy to be set to Always") + assert.Equal(t, "main-secret", desiredMedusaStandalone.Spec.Template.Spec.ImagePullSecrets[0].Name, "expected standalone container image pull secret to be set") + assert.Equal(t, "reg1/repo1/img1:tag1", desiredMedusaStandalone.Spec.Template.Spec.Containers[0].Image, "expected standalone container image to be set to reg1/repo1/img1:tag1") + assert.Equal(t, corev1.PullAlways, desiredMedusaStandalone.Spec.Template.Spec.Containers[0].ImagePullPolicy, "expected standalone pull policy to be set to Always") } func TestExternalSecretsFlag(t *testing.T) { From 0380f7ea7cc2a9838ab8c8a463ae633c83da7f11 Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Tue, 12 Mar 2024 17:11:15 +0100 Subject: [PATCH 4/4] #1240 Fixes applying defaults --- pkg/medusa/reconcile.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/medusa/reconcile.go b/pkg/medusa/reconcile.go index 81d4922d9..805fa0c14 100644 --- a/pkg/medusa/reconcile.go +++ b/pkg/medusa/reconcile.go @@ -526,7 +526,7 @@ func StandaloneMedusaDeployment(medusaContainer corev1.Container, clusterName, d Containers: []corev1.Container{ medusaContainer, }, - ImagePullSecrets: images.CollectPullSecrets(medusaImage.ApplyDefaults(*medusaImage)), + ImagePullSecrets: images.CollectPullSecrets(medusaImage.ApplyDefaults(defaultMedusaImage)), Volumes: []corev1.Volume{}, Hostname: MedusaStandaloneDeploymentName(clusterName, dcName), },