Skip to content

Commit

Permalink
fix: Use backup namespace for clean job
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Mutel committed Apr 26, 2024
1 parent 11e4985 commit c70dfb9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG/CHANGELOG-1.16.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* [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
3 changes: 2 additions & 1 deletion controllers/k8ssandra/medusa_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/medusa/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 * * *",
Expand Down
4 changes: 2 additions & 2 deletions pkg/medusa/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
}

0 comments on commit c70dfb9

Please sign in to comment.