Skip to content

Commit

Permalink
Allow setting uid in the clone description.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexeyklyukin committed Jan 19, 2018
1 parent 0af39c3 commit aea5576
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/cluster/k8sres.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/spec/postgresql.go
Expand Up @@ -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"`
}

Expand Down

0 comments on commit aea5576

Please sign in to comment.