Use cluster UID as a suffix to the WAL bucket. (#211)
Avoid reusing WAL S3 buckets of the older cluster with the same name as the existing one. For the new cluster, the S3 bucket name will include a suffix that is equal to the UID of the PostgreSQL object describing the cluster. That way, the bucket name will stay the same for all members iff they correspond to the same PostgreSQL cluster object. When "clone: uid:" key 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.
This commit is contained in:
		
							parent
							
								
									0e3f941d2f
								
							
						
					
					
						commit
						c597377617
					
				|  | @ -7,6 +7,7 @@ import ( | ||||||
| 
 | 
 | ||||||
| 	"k8s.io/apimachinery/pkg/api/resource" | 	"k8s.io/apimachinery/pkg/api/resource" | ||||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
|  | 	"k8s.io/apimachinery/pkg/types" | ||||||
| 	"k8s.io/apimachinery/pkg/util/intstr" | 	"k8s.io/apimachinery/pkg/util/intstr" | ||||||
| 	"k8s.io/client-go/pkg/api/v1" | 	"k8s.io/client-go/pkg/api/v1" | ||||||
| 	"k8s.io/client-go/pkg/apis/apps/v1beta1" | 	"k8s.io/client-go/pkg/apis/apps/v1beta1" | ||||||
|  | @ -280,6 +281,7 @@ func (c *Cluster) tolerations(tolerationsSpec *[]v1.Toleration) []v1.Toleration | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c *Cluster) generatePodTemplate( | func (c *Cluster) generatePodTemplate( | ||||||
|  | 	uid types.UID, | ||||||
| 	resourceRequirements *v1.ResourceRequirements, | 	resourceRequirements *v1.ResourceRequirements, | ||||||
| 	resourceRequirementsScalyrSidecar *v1.ResourceRequirements, | 	resourceRequirementsScalyrSidecar *v1.ResourceRequirements, | ||||||
| 	tolerationsSpec *[]v1.Toleration, | 	tolerationsSpec *[]v1.Toleration, | ||||||
|  | @ -358,6 +360,7 @@ func (c *Cluster) generatePodTemplate( | ||||||
| 	} | 	} | ||||||
| 	if c.OpConfig.WALES3Bucket != "" { | 	if c.OpConfig.WALES3Bucket != "" { | ||||||
| 		envVars = append(envVars, v1.EnvVar{Name: "WAL_S3_BUCKET", Value: 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: getWALBucketScopeSuffix(string(uid))}) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if c.OpConfig.EtcdHost == "" { | 	if c.OpConfig.EtcdHost == "" { | ||||||
|  | @ -500,6 +503,13 @@ func (c *Cluster) generatePodTemplate( | ||||||
| 	return &template | 	return &template | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func getWALBucketScopeSuffix(uid string) string { | ||||||
|  | 	if uid != "" { | ||||||
|  | 		return fmt.Sprintf("-%s", uid) | ||||||
|  | 	} | ||||||
|  | 	return "" | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func makeResources(cpuRequest, memoryRequest, cpuLimit, memoryLimit string) spec.Resources { | func makeResources(cpuRequest, memoryRequest, cpuLimit, memoryLimit string) spec.Resources { | ||||||
| 	return spec.Resources{ | 	return spec.Resources{ | ||||||
| 		ResourceRequest: spec.ResourceDescription{ | 		ResourceRequest: spec.ResourceDescription{ | ||||||
|  | @ -537,7 +547,7 @@ func (c *Cluster) generateStatefulSet(spec *spec.PostgresSpec) (*v1beta1.Statefu | ||||||
| 			customPodEnvVars = cm.Data | 			customPodEnvVars = cm.Data | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	podTemplate := c.generatePodTemplate(resourceRequirements, resourceRequirementsScalyrSidecar, &spec.Tolerations, &spec.PostgresqlParam, &spec.Patroni, &spec.Clone, &spec.DockerImage, customPodEnvVars) | 	podTemplate := c.generatePodTemplate(c.Postgresql.GetUID(), resourceRequirements, resourceRequirementsScalyrSidecar, &spec.Tolerations, &spec.PostgresqlParam, &spec.Patroni, &spec.Clone, &spec.DockerImage, customPodEnvVars) | ||||||
| 	volumeClaimTemplate, err := generatePersistentVolumeClaimTemplate(spec.Volume.Size, spec.Volume.StorageClass) | 	volumeClaimTemplate, err := generatePersistentVolumeClaimTemplate(spec.Volume.Size, spec.Volume.StorageClass) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("could not generate volume claim template: %v", err) | 		return nil, fmt.Errorf("could not generate volume claim template: %v", err) | ||||||
|  | @ -757,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_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_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_TARGET_TIME", Value: description.EndTimestamp}) | ||||||
|  | 		result = append(result, v1.EnvVar{Name: "CLONE_WAL_BUCKET_SCOPE_SUFFIX", Value: getWALBucketScopeSuffix(description.Uid)}) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return result | 	return result | ||||||
|  |  | ||||||
|  | @ -55,6 +55,7 @@ type Patroni struct { | ||||||
| // CloneDescription describes which cluster the new should clone and up to which point in time
 | // CloneDescription describes which cluster the new should clone and up to which point in time
 | ||||||
| type CloneDescription struct { | type CloneDescription struct { | ||||||
| 	ClusterName  string `json:"cluster,omitempty"` | 	ClusterName  string `json:"cluster,omitempty"` | ||||||
|  | 	Uid          string `json:"uid,omitempty"` | ||||||
| 	EndTimestamp string `json:"timestamp,omitempty"` | 	EndTimestamp string `json:"timestamp,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue