diff --git a/CHANGELOG/CHANGELOG-1.16.md b/CHANGELOG/CHANGELOG-1.16.md index 2db975a04..d8042b843 100644 --- a/CHANGELOG/CHANGELOG-1.16.md +++ b/CHANGELOG/CHANGELOG-1.16.md @@ -15,4 +15,5 @@ When cutting a new release, update the `unreleased` heading to the tag being gen ## unreleased -* [BUGFIX] [#1272](https://github.com/k8ssandra/k8ssandra-operator/issues/1272) Prevent cass-operator from creating users when an external DC is referenced to allow migration through expansion \ No newline at end of file +* [BUGFIX] [#1299](https://github.com/k8ssandra/k8ssandra-operator/issues/1299) CronJob for medusa purge not in the correct namespace +* [BUGFIX] [#1272](https://github.com/k8ssandra/k8ssandra-operator/issues/1272) Prevent cass-operator from creating users when an external DC is referenced to allow migration through expansion diff --git a/controllers/k8ssandra/medusa_reconciler.go b/controllers/k8ssandra/medusa_reconciler.go index b23bb0cc0..06391e459 100644 --- a/controllers/k8ssandra/medusa_reconciler.go +++ b/controllers/k8ssandra/medusa_reconciler.go @@ -137,9 +137,10 @@ func (r *K8ssandraClusterReconciler) reconcileMedusa( logger.Info("Medusa standalone deployment is not ready yet") return result.RequeueSoon(r.DefaultDelay) } + // Create a cron job to purge Medusa backups operatorNamespace := r.getOperatorNamespace() - purgeCronJob, err := medusa.PurgeCronJob(dcConfig, kc.SanitizedName(), operatorNamespace, logger) + purgeCronJob, err := medusa.PurgeCronJob(dcConfig, kc.SanitizedName(), operatorNamespace, dcNamespace, logger) if err != nil { logger.Info("Failed to create Medusa purge backups cronjob", "error", err) return result.Error(err) diff --git a/pkg/medusa/reconcile.go b/pkg/medusa/reconcile.go index 48c28b9aa..4139d514d 100644 --- a/pkg/medusa/reconcile.go +++ b/pkg/medusa/reconcile.go @@ -576,7 +576,7 @@ func StandaloneMedusaService(dcConfig *cassandra.DatacenterConfig, medusaSpec *a return medusaService } -func PurgeCronJob(dcConfig *cassandra.DatacenterConfig, clusterName, namespace string, logger logr.Logger) (*batchv1.CronJob, error) { +func PurgeCronJob(dcConfig *cassandra.DatacenterConfig, clusterName, operatorNamespace string, namespace string, logger logr.Logger) (*batchv1.CronJob, error) { cronJobName := MedusaPurgeCronJobName(cassdcapi.CleanupForKubernetes(clusterName), dcConfig.SanitizedName()) logger.Info(fmt.Sprintf("Creating Medusa purge backups cronjob: %s", cronJobName)) if len(cronJobName) > 253 { @@ -585,7 +585,7 @@ func PurgeCronJob(dcConfig *cassandra.DatacenterConfig, clusterName, namespace s purgeCronJob := &batchv1.CronJob{ ObjectMeta: metav1.ObjectMeta{ Name: cronJobName, - Namespace: namespace, + Namespace: operatorNamespace, }, Spec: batchv1.CronJobSpec{ Schedule: "0 0 * * *", diff --git a/pkg/medusa/reconcile_test.go b/pkg/medusa/reconcile_test.go index f9b49bd7a..e71432c28 100644 --- a/pkg/medusa/reconcile_test.go +++ b/pkg/medusa/reconcile_test.go @@ -721,7 +721,7 @@ func TestPurgeCronJob(t *testing.T) { logger := logr.New(logr.Discard().GetSink()) // Call the function with the test inputs - actualCronJob, err := PurgeCronJob(dcConfig, clusterName, namespace, logger) + actualCronJob, err := PurgeCronJob(dcConfig, clusterName, namespace, namespace, logger) assert.Nil(t, err) assert.Equal(t, fmt.Sprintf("%s-%s-medusa-purge", "testcluster", "testdc"), actualCronJob.ObjectMeta.Name) assert.Equal(t, 3, len(actualCronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Command)) @@ -739,6 +739,6 @@ func TestPurgeCronJobNameTooLong(t *testing.T) { logger := logr.New(logr.Discard().GetSink()) // Call the function with the test inputs - _, err := PurgeCronJob(dcConfig, clusterName, namespace, logger) + _, err := PurgeCronJob(dcConfig, clusterName, namespace, namespace, logger) assert.NotNil(t, err) }