From aea55760c25f0bfda51b647feb8d6813257e8e76 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Fri, 19 Jan 2018 14:31:25 +0100 Subject: [PATCH] Allow setting uid in the clone description. When clone: uid: value is present in the cluster manifest and the cluster is cloned from an S3 bucket (currently that happens if the endTimestamp is present in the clone description) the S3 bucket to clone from is suffixed with the -uid value, matching the suffix the operator gives to the S3 buckets of the new clusters. --- pkg/cluster/k8sres.go | 14 +++++++++++--- pkg/spec/postgresql.go | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 4ec30be51..3fb8d050a 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -7,8 +7,8 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/pkg/api/v1" "k8s.io/client-go/pkg/apis/apps/v1beta1" policybeta1 "k8s.io/client-go/pkg/apis/policy/v1beta1" @@ -281,7 +281,7 @@ func (c *Cluster) tolerations(tolerationsSpec *[]v1.Toleration) []v1.Toleration } func (c *Cluster) generatePodTemplate( - uuid types.UID, + uid types.UID, resourceRequirements *v1.ResourceRequirements, resourceRequirementsScalyrSidecar *v1.ResourceRequirements, tolerationsSpec *[]v1.Toleration, @@ -360,7 +360,7 @@ func (c *Cluster) generatePodTemplate( } if c.OpConfig.WALES3Bucket != "" { envVars = append(envVars, v1.EnvVar{Name: "WAL_S3_BUCKET", Value: c.OpConfig.WALES3Bucket}) - envVars = append(envVars, v1.EnvVar{Name: "WAL_BUCKET_SCOPE_SUFFIX", Value: fmt.Sprintf("-%s", uuid) }) + envVars = append(envVars, v1.EnvVar{Name: "WAL_BUCKET_SCOPE_SUFFIX", Value: getWALBucketScopeSuffix(string(uid))}) } if c.OpConfig.EtcdHost == "" { @@ -503,6 +503,13 @@ func (c *Cluster) generatePodTemplate( return &template } +func getWALBucketScopeSuffix(uid string) string { + if uid != "" { + return fmt.Sprintf("-%s", uid) + } + return "" +} + func makeResources(cpuRequest, memoryRequest, cpuLimit, memoryLimit string) spec.Resources { return spec.Resources{ ResourceRequest: spec.ResourceDescription{ @@ -760,6 +767,7 @@ func (c *Cluster) generateCloneEnvironment(description *spec.CloneDescription) [ result = append(result, v1.EnvVar{Name: "CLONE_METHOD", Value: "CLONE_WITH_WALE"}) result = append(result, v1.EnvVar{Name: "CLONE_WAL_S3_BUCKET", Value: c.OpConfig.WALES3Bucket}) result = append(result, v1.EnvVar{Name: "CLONE_TARGET_TIME", Value: description.EndTimestamp}) + result = append(result, v1.EnvVar{Name: "CLONE_WAL_BUCKET_SCOPE_SUFFIX", Value: getWALBucketScopeSuffix(description.Uid)}) } return result diff --git a/pkg/spec/postgresql.go b/pkg/spec/postgresql.go index a08d260d6..e124c10c1 100644 --- a/pkg/spec/postgresql.go +++ b/pkg/spec/postgresql.go @@ -55,6 +55,7 @@ type Patroni struct { // CloneDescription describes which cluster the new should clone and up to which point in time type CloneDescription struct { ClusterName string `json:"cluster,omitempty"` + Uid string `json:"uid,omitempty"` EndTimestamp string `json:"timestamp,omitempty"` }