From 11019f557e425e21ea94a6d783a5a4f948243c88 Mon Sep 17 00:00:00 2001 From: Sergey Dudoladov Date: Tue, 15 Jan 2019 15:44:57 +0100 Subject: [PATCH] Submit hello world cron job --- manifests/minimal-postgres-manifest.yaml | 2 ++ pkg/cluster/cluster.go | 3 +++ pkg/cluster/k8sres.go | 23 +++++++++++++++++++---- pkg/cluster/resources.go | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/manifests/minimal-postgres-manifest.yaml b/manifests/minimal-postgres-manifest.yaml index 402946b09..55a5d9be6 100644 --- a/manifests/minimal-postgres-manifest.yaml +++ b/manifests/minimal-postgres-manifest.yaml @@ -23,3 +23,5 @@ spec: foo: zalando postgresql: version: "10" + + enableLogicalBackup: true diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 6ee2c80bb..bc55a16c7 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -18,6 +18,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" + batchv1beta1 "k8s.io/api/batch/v1beta1" "encoding/json" @@ -82,6 +83,8 @@ type Cluster struct { currentProcess Process processMu sync.RWMutex // protects the current operation for reporting, no need to hold the master mutex specMu sync.RWMutex // protects the spec for reporting, no need to hold the master mutex + + backupJob *batchv1beta1.CronJob // periodical logical backups independent from WAL archiving } type compareStatefulsetResult struct { diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 9d14acfb8..1f477cd6c 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -20,9 +20,10 @@ 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" + batchv1beta1 "k8s.io/api/batch/v1beta1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/labels" ) const ( @@ -1200,15 +1201,29 @@ func (c *Cluster) getClusterServiceConnectionParameters(clusterName string) (hos func (c *Cluster) generateCronJob() *batchv1beta1.CronJob { - jobSpec := batchv1.JobSpec{} + jobSpec := batchv1.JobSpec{Template : v1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + corev1.Container { + Name: "Hello world", + Image: "hello-world", + Command: []string{"date", "echo Hello from the Kubernetes cluster"}, + + }, + + }, + }, + }, + } jobTemplateSpec := batchv1beta1.JobTemplateSpec{ Spec: jobSpec, + } cronJob := &batchv1beta1.CronJob{ ObjectMeta: metav1.ObjectMeta{ - Name: c.podDisruptionBudgetName(), + Name: "Dummy cron job", Namespace: c.Namespace, Labels: c.labelsSet(true), }, diff --git a/pkg/cluster/resources.go b/pkg/cluster/resources.go index 7021ed1c2..1d226d360 100644 --- a/pkg/cluster/resources.go +++ b/pkg/cluster/resources.go @@ -614,6 +614,7 @@ func (c *Cluster) createBackupCronJob() (err error) { if err != nil { return fmt.Errorf("could not create k8s cron job: %v", err) } + c.backupJob = cronJob return nil }