From d421bb6c5a56f95634f8fe3e5a7eb9e0f0c15727 Mon Sep 17 00:00:00 2001 From: "mani.a@basiscloudsolutions.com" Date: Mon, 19 Feb 2024 18:07:29 +0100 Subject: [PATCH] changing cronjob api to v1 --- controllers/backup/cronjob.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/controllers/backup/cronjob.go b/controllers/backup/cronjob.go index 74a7e324..059358dd 100644 --- a/controllers/backup/cronjob.go +++ b/controllers/backup/cronjob.go @@ -25,7 +25,6 @@ import ( "github.com/kloeckner-i/db-operator/pkg/utils/kci" "github.com/sirupsen/logrus" batchv1 "k8s.io/api/batch/v1" - batchv1beta1 "k8s.io/api/batch/v1beta1" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -34,13 +33,13 @@ import ( // GCSBackupCron builds kubernetes cronjob object // to create database backup regularly with defined schedule from dbcr // this job will database dump and upload to google bucket storage for backup -func GCSBackupCron(conf *config.Config, dbcr *kciv1alpha1.Database, ownership []metav1.OwnerReference) (*batchv1beta1.CronJob, error) { +func GCSBackupCron(conf *config.Config, dbcr *kciv1alpha1.Database, ownership []metav1.OwnerReference) (*batchv1.CronJob, error) { cronJobSpec, err := buildCronJobSpec(conf, dbcr) if err != nil { return nil, err } - return &batchv1beta1.CronJob{ + return &batchv1.CronJob{ TypeMeta: metav1.TypeMeta{ Kind: "CronJob", APIVersion: "batch", @@ -55,25 +54,25 @@ func GCSBackupCron(conf *config.Config, dbcr *kciv1alpha1.Database, ownership [] }, nil } -func buildCronJobSpec(conf *config.Config, dbcr *kciv1alpha1.Database) (batchv1beta1.CronJobSpec, error) { +func buildCronJobSpec(conf *config.Config, dbcr *kciv1alpha1.Database) (batchv1.CronJobSpec, error) { jobTemplate, err := buildJobTemplate(conf, dbcr) if err != nil { - return batchv1beta1.CronJobSpec{}, err + return batchv1.CronJobSpec{}, err } - return batchv1beta1.CronJobSpec{ + return batchv1.CronJobSpec{ JobTemplate: jobTemplate, Schedule: dbcr.Spec.Backup.Cron, }, nil } -func buildJobTemplate(conf *config.Config, dbcr *kciv1alpha1.Database) (batchv1beta1.JobTemplateSpec, error) { +func buildJobTemplate(conf *config.Config, dbcr *kciv1alpha1.Database) (batchv1.JobTemplateSpec, error) { ActiveDeadlineSeconds := int64(conf.Backup.ActiveDeadlineSeconds) BackoffLimit := int32(3) instance, err := dbcr.GetInstanceRef() if err != nil { logrus.Errorf("can not build job template - %s", err) - return batchv1beta1.JobTemplateSpec{}, err + return batchv1.JobTemplateSpec{}, err } var backupContainer v1.Container @@ -83,18 +82,18 @@ func buildJobTemplate(conf *config.Config, dbcr *kciv1alpha1.Database) (batchv1b case "postgres": backupContainer, err = postgresBackupContainer(conf, dbcr) if err != nil { - return batchv1beta1.JobTemplateSpec{}, err + return batchv1.JobTemplateSpec{}, err } case "mysql": backupContainer, err = mysqlBackupContainer(conf, dbcr) if err != nil { - return batchv1beta1.JobTemplateSpec{}, err + return batchv1.JobTemplateSpec{}, err } default: - return batchv1beta1.JobTemplateSpec{}, errors.New("unknown engine type") + return batchv1.JobTemplateSpec{}, errors.New("unknown engine type") } - return batchv1beta1.JobTemplateSpec{ + return batchv1.JobTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: kci.BaseLabelBuilder(), },