diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index fec795ad0..9d14acfb8 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -20,7 +20,9 @@ import ( "github.com/zalando-incubator/postgres-operator/pkg/util" "github.com/zalando-incubator/postgres-operator/pkg/util/config" "github.com/zalando-incubator/postgres-operator/pkg/util/constants" + batchv1beta1 "k8s.io/api/batch/v1beta1" "k8s.io/apimachinery/pkg/labels" + batchv1 "k8s.io/api/batch/v1" ) const ( @@ -1195,3 +1197,26 @@ func (c *Cluster) getClusterServiceConnectionParameters(clusterName string) (hos port = "5432" return } + +func (c *Cluster) generateCronJob() *batchv1beta1.CronJob { + + jobSpec := batchv1.JobSpec{} + + jobTemplateSpec := batchv1beta1.JobTemplateSpec{ + Spec: jobSpec, + } + + cronJob := &batchv1beta1.CronJob{ + ObjectMeta: metav1.ObjectMeta{ + Name: c.podDisruptionBudgetName(), + Namespace: c.Namespace, + Labels: c.labelsSet(true), + }, + Spec: batchv1beta1.CronJobSpec{ + Schedule: "*/1 * * * *", + JobTemplate: jobTemplateSpec, + }, + } + + return cronJob +} diff --git a/pkg/cluster/resources.go b/pkg/cluster/resources.go index 5bf72abda..7021ed1c2 100644 --- a/pkg/cluster/resources.go +++ b/pkg/cluster/resources.go @@ -606,8 +606,15 @@ func (c *Cluster) createRoles() (err error) { } func (c *Cluster) createBackupCronJob() (err error) { + c.setProcessName("creating a k8s cron job for backups") + cronJobSpec := c.generateCronJob() + cronJob, err := c.KubeClient.CronJobsGetter.CronJobs(c.Namespace).Create(cronJobSpec) + if err != nil { + return fmt.Errorf("could not create k8s cron job: %v", err) + } + return nil }