Skip to content

Commit

Permalink
Revert "Add cronjob to purge backups (k8ssandra#1167)"
Browse files Browse the repository at this point in the history
This reverts commit 8c32ae3.
  • Loading branch information
ericsmalling committed Apr 23, 2024
1 parent 7bd21a7 commit e785fa9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 562 deletions.
11 changes: 0 additions & 11 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ rules:
verbs:
- list
- watch
- apiGroups:
- batch
resources:
- cronjobs
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- cassandra.datastax.com
resources:
Expand Down
35 changes: 0 additions & 35 deletions controllers/k8ssandra/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/k8ssandra/k8ssandra-operator/pkg/result"
"github.com/k8ssandra/k8ssandra-operator/pkg/utils"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -107,10 +106,6 @@ func (r *K8ssandraClusterReconciler) checkDeletion(ctx context.Context, kc *api.
if r.deleteK8ssandraConfigMaps(ctx, kc, dcTemplate, namespace, remoteClient, logger) {
hasErrors = true
}

if r.deleteCronJobs(ctx, kc, dcTemplate, namespace, remoteClient, logger) {
hasErrors = true
}
}

if hasErrors {
Expand Down Expand Up @@ -442,33 +437,3 @@ func (r *K8ssandraClusterReconciler) deleteDeployments(

return
}

func (r *K8ssandraClusterReconciler) deleteCronJobs(
ctx context.Context,
kc *k8ssandraapi.K8ssandraCluster,
dcTemplate k8ssandraapi.CassandraDatacenterTemplate,
namespace string,
remoteClient client.Client,
kcLogger logr.Logger,
) (hasErrors bool) {
selector := k8ssandralabels.CleanedUpByLabels(client.ObjectKey{Namespace: kc.Namespace, Name: kc.SanitizedName()})
options := client.ListOptions{
Namespace: namespace,
LabelSelector: labels.SelectorFromSet(selector),
}
cronJobList := &batchv1.CronJobList{}
if err := remoteClient.List(ctx, cronJobList, &options); err != nil {
kcLogger.Error(err, "Failed to list Medusa CronJobs", "Context", dcTemplate.K8sContext)
return true
}
for _, item := range cronJobList.Items {
kcLogger.Info("Deleting CronJob", "CronJob", utils.GetKey(&item))
if err := remoteClient.Delete(ctx, &item); err != nil {
key := client.ObjectKey{Namespace: namespace, Name: item.Name}
if !errors.IsNotFound(err) {
kcLogger.Error(err, "Failed to delete CronJob", "CronJob", key, "Context", dcTemplate.K8sContext)
}
}
}
return
}
1 change: 0 additions & 1 deletion controllers/k8ssandra/k8ssandracluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type K8ssandraClusterReconciler struct {
// +kubebuilder:rbac:groups=monitoring.coreos.com,namespace="k8ssandra",resources=servicemonitors,verbs=get;list;watch;create;update;patch;delete;deletecollection
// +kubebuilder:rbac:groups=core,namespace="k8ssandra",resources=configmaps,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="",namespace="k8ssandra",resources=events,verbs=create;patch
// +kubebuilder:rbac:groups=batch,namespace="k8ssandra",resources=cronjobs,verbs=get;list;watch;create;update;delete

func (r *K8ssandraClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx).WithValues("K8ssandraCluster", req.NamespacedName)
Expand Down
19 changes: 2 additions & 17 deletions controllers/k8ssandra/medusa_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r *K8ssandraClusterReconciler) reconcileMedusa(
}

// Create the Medusa standalone pod
desiredMedusaStandalone := medusa.StandaloneMedusaDeployment(*medusaContainer, kc.SanitizedName(), dcConfig.SanitizedName(), dcNamespace, logger, kc.Spec.Medusa.ContainerImage)
desiredMedusaStandalone := medusa.StandaloneMedusaDeployment(*medusaContainer, kc.SanitizedName(), dcConfig.SanitizedName(), dcNamespace, logger)

// Add the volumes previously computed to the Medusa standalone pod
for _, volume := range volumes {
Expand Down Expand Up @@ -132,21 +132,6 @@ 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
purgeCronJob, err := medusa.PurgeCronJob(dcConfig, kc.SanitizedName(), namespace, logger)
if err != nil {
logger.Info("Failed to create Medusa purge backups cronjob", "error", err)
return result.Error(err)
}
purgeCronJob.SetLabels(labels.CleanedUpByLabels(kcKey))
recRes = reconciliation.ReconcileObject(ctx, remoteClient, r.DefaultDelay, *purgeCronJob)
switch {
case recRes.IsError():
return recRes
case recRes.IsRequeue():
return recRes
}

} else {
logger.Info("Medusa is not enabled")
}
Expand Down Expand Up @@ -218,7 +203,7 @@ func (r *K8ssandraClusterReconciler) reconcileMedusaConfigMap(
) result.ReconcileResult {
logger.Info("Reconciling Medusa configMap on namespace : " + namespace)
if kc.Spec.Medusa != nil {
medusaIni := medusa.CreateMedusaIni(kc, dcConfig)
medusaIni := medusa.CreateMedusaIni(kc)
desiredConfigMap := medusa.CreateMedusaConfigMap(namespace, kc.SanitizedName(), medusaIni)
kcKey := utils.GetKey(kc)
desiredConfigMap.SetLabels(labels.CleanedUpByLabels(kcKey))
Expand Down
Loading

0 comments on commit e785fa9

Please sign in to comment.