camelCasing all manifest parameters (#602)
* deprecate snake_case manifest parameters * move backward compatible check and update test
This commit is contained in:
		
							parent
							
								
									36003b8264
								
							
						
					
					
						commit
						3a914f9a3c
					
				| 
						 | 
					@ -351,7 +351,7 @@ metadata:
 | 
				
			||||||
  name: acid-minimal-cluster
 | 
					  name: acid-minimal-cluster
 | 
				
			||||||
spec:
 | 
					spec:
 | 
				
			||||||
  ...
 | 
					  ...
 | 
				
			||||||
  init_containers:
 | 
					  initContainers:
 | 
				
			||||||
    - name: "container-name"
 | 
					    - name: "container-name"
 | 
				
			||||||
      image: "company/image:tag"
 | 
					      image: "company/image:tag"
 | 
				
			||||||
      env:
 | 
					      env:
 | 
				
			||||||
| 
						 | 
					@ -359,7 +359,7 @@ spec:
 | 
				
			||||||
          value: "any-k8s-env-things"
 | 
					          value: "any-k8s-env-things"
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
`init_containers` accepts full `v1.Container` definition.
 | 
					`initContainers` accepts full `v1.Container` definition.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Increase volume size
 | 
					## Increase volume size
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,7 @@ kind: postgresql
 | 
				
			||||||
metadata:
 | 
					metadata:
 | 
				
			||||||
  name: acid-test-cluster
 | 
					  name: acid-test-cluster
 | 
				
			||||||
spec:
 | 
					spec:
 | 
				
			||||||
  init_containers:
 | 
					  initContainers:
 | 
				
			||||||
  - name: date
 | 
					  - name: date
 | 
				
			||||||
    image: busybox
 | 
					    image: busybox
 | 
				
			||||||
    command: [ "/bin/date" ]
 | 
					    command: [ "/bin/date" ]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,12 +53,16 @@ type PostgresSpec struct {
 | 
				
			||||||
	Databases             map[string]string    `json:"databases,omitempty"`
 | 
						Databases             map[string]string    `json:"databases,omitempty"`
 | 
				
			||||||
	Tolerations           []v1.Toleration      `json:"tolerations,omitempty"`
 | 
						Tolerations           []v1.Toleration      `json:"tolerations,omitempty"`
 | 
				
			||||||
	Sidecars              []Sidecar            `json:"sidecars,omitempty"`
 | 
						Sidecars              []Sidecar            `json:"sidecars,omitempty"`
 | 
				
			||||||
	InitContainers        []v1.Container       `json:"init_containers,omitempty"`
 | 
						InitContainers        []v1.Container       `json:"initContainers,omitempty"`
 | 
				
			||||||
	PodPriorityClassName  string               `json:"pod_priority_class_name,omitempty"`
 | 
						PodPriorityClassName  string               `json:"podPriorityClassName,omitempty"`
 | 
				
			||||||
	ShmVolume             *bool                `json:"enableShmVolume,omitempty"`
 | 
						ShmVolume             *bool                `json:"enableShmVolume,omitempty"`
 | 
				
			||||||
	EnableLogicalBackup   bool                 `json:"enableLogicalBackup,omitempty"`
 | 
						EnableLogicalBackup   bool                 `json:"enableLogicalBackup,omitempty"`
 | 
				
			||||||
	LogicalBackupSchedule string               `json:"logicalBackupSchedule,omitempty"`
 | 
						LogicalBackupSchedule string               `json:"logicalBackupSchedule,omitempty"`
 | 
				
			||||||
	StandbyCluster        *StandbyDescription  `json:"standby"`
 | 
						StandbyCluster        *StandbyDescription  `json:"standby"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// deprectaed json tags
 | 
				
			||||||
 | 
						InitContainersOld       []v1.Container `json:"init_containers,omitempty"`
 | 
				
			||||||
 | 
						PodPriorityClassNameOld string         `json:"pod_priority_class_name,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
 | 
					// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -171,6 +171,7 @@ var unmarshalCluster = []struct {
 | 
				
			||||||
		marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{}},"status":{"PostgresClusterStatus":"Invalid"}}`),
 | 
							marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{}},"status":{"PostgresClusterStatus":"Invalid"}}`),
 | 
				
			||||||
		err:     nil},
 | 
							err:     nil},
 | 
				
			||||||
	// example with detailed input manifest
 | 
						// example with detailed input manifest
 | 
				
			||||||
 | 
						// and deprecated pod_priority_class_name -> podPriorityClassName
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		in: []byte(`{
 | 
							in: []byte(`{
 | 
				
			||||||
	  "kind": "Postgresql",
 | 
						  "kind": "Postgresql",
 | 
				
			||||||
| 
						 | 
					@ -180,6 +181,7 @@ var unmarshalCluster = []struct {
 | 
				
			||||||
	  },
 | 
						  },
 | 
				
			||||||
	  "spec": {
 | 
						  "spec": {
 | 
				
			||||||
	    "teamId": "ACID",
 | 
						    "teamId": "ACID",
 | 
				
			||||||
 | 
							"pod_priority_class_name": "spilo-pod-priority",
 | 
				
			||||||
	    "volume": {
 | 
						    "volume": {
 | 
				
			||||||
	      "size": "5Gi",
 | 
						      "size": "5Gi",
 | 
				
			||||||
	      "storageClass": "SSD",
 | 
						      "storageClass": "SSD",
 | 
				
			||||||
| 
						 | 
					@ -263,6 +265,7 @@ var unmarshalCluster = []struct {
 | 
				
			||||||
						"log_statement":   "all",
 | 
											"log_statement":   "all",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
 | 
									PodPriorityClassNameOld: "spilo-pod-priority",
 | 
				
			||||||
				Volume: Volume{
 | 
									Volume: Volume{
 | 
				
			||||||
					Size:         "5Gi",
 | 
										Size:         "5Gi",
 | 
				
			||||||
					StorageClass: "SSD",
 | 
										StorageClass: "SSD",
 | 
				
			||||||
| 
						 | 
					@ -316,7 +319,7 @@ var unmarshalCluster = []struct {
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			Error: "",
 | 
								Error: "",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"9.6","parameters":{"log_statement":"all","max_connections":"10","shared_buffers":"32MB"}},"volume":{"size":"5Gi","storageClass":"SSD", "subPath": "subdir"},"enableShmVolume":false,"patroni":{"initdb":{"data-checksums":"true","encoding":"UTF8","locale":"en_US.UTF-8"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host    all all 0.0.0.0/0 md5"],"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}}},"resources":{"requests":{"cpu":"10m","memory":"50Mi"},"limits":{"cpu":"300m","memory":"3000Mi"}},"teamId":"ACID","allowedSourceRanges":["127.0.0.1/32"],"numberOfInstances":2,"users":{"zalando":["superuser","createdb"]},"maintenanceWindows":["Mon:01:00-06:00","Sat:00:00-04:00","05:00-05:15"],"clone":{"cluster":"acid-batman"}},"status":{"PostgresClusterStatus":""}}`),
 | 
							marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"9.6","parameters":{"log_statement":"all","max_connections":"10","shared_buffers":"32MB"}},"pod_priority_class_name":"spilo-pod-priority","volume":{"size":"5Gi","storageClass":"SSD", "subPath": "subdir"},"enableShmVolume":false,"patroni":{"initdb":{"data-checksums":"true","encoding":"UTF8","locale":"en_US.UTF-8"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host    all all 0.0.0.0/0 md5"],"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}}},"resources":{"requests":{"cpu":"10m","memory":"50Mi"},"limits":{"cpu":"300m","memory":"3000Mi"}},"teamId":"ACID","allowedSourceRanges":["127.0.0.1/32"],"numberOfInstances":2,"users":{"zalando":["superuser","createdb"]},"maintenanceWindows":["Mon:01:00-06:00","Sat:00:00-04:00","05:00-05:15"],"clone":{"cluster":"acid-batman"}},"status":{"PostgresClusterStatus":""}}`),
 | 
				
			||||||
		err:     nil},
 | 
							err:     nil},
 | 
				
			||||||
	// example with teamId set in input
 | 
						// example with teamId set in input
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -513,6 +513,13 @@ func (in *PostgresSpec) DeepCopyInto(out *PostgresSpec) {
 | 
				
			||||||
		*out = new(StandbyDescription)
 | 
							*out = new(StandbyDescription)
 | 
				
			||||||
		**out = **in
 | 
							**out = **in
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if in.InitContainersOld != nil {
 | 
				
			||||||
 | 
							in, out := &in.InitContainersOld, &out.InitContainersOld
 | 
				
			||||||
 | 
							*out = make([]corev1.Container, len(*in))
 | 
				
			||||||
 | 
							for i := range *in {
 | 
				
			||||||
 | 
								(*in)[i].DeepCopyInto(&(*out)[i])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -799,6 +799,28 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*v1beta1.State
 | 
				
			||||||
		return nil, fmt.Errorf("s3_wal_path is empty for standby cluster")
 | 
							return nil, fmt.Errorf("s3_wal_path is empty for standby cluster")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// backward compatible check for InitContainers
 | 
				
			||||||
 | 
						if spec.InitContainersOld != nil {
 | 
				
			||||||
 | 
							msg := "Manifest parameter init_containers is deprecated."
 | 
				
			||||||
 | 
							if spec.InitContainers == nil {
 | 
				
			||||||
 | 
								c.logger.Warningf("%s Consider using initContainers instead.", msg)
 | 
				
			||||||
 | 
								spec.InitContainers = spec.InitContainersOld
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								c.logger.Warningf("%s Only value from initContainers is used", msg)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// backward compatible check for PodPriorityClassName
 | 
				
			||||||
 | 
						if spec.PodPriorityClassNameOld != "" {
 | 
				
			||||||
 | 
							msg := "Manifest parameter pod_priority_class_name is deprecated."
 | 
				
			||||||
 | 
							if spec.PodPriorityClassName == "" {
 | 
				
			||||||
 | 
								c.logger.Warningf("%s Consider using podPriorityClassName instead.", msg)
 | 
				
			||||||
 | 
								spec.PodPriorityClassName = spec.PodPriorityClassNameOld
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								c.logger.Warningf("%s Only value from podPriorityClassName is used", msg)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spiloConfiguration, err := generateSpiloJSONConfiguration(&spec.PostgresqlParam, &spec.Patroni, c.OpConfig.PamRoleName, c.logger)
 | 
						spiloConfiguration, err := generateSpiloJSONConfiguration(&spec.PostgresqlParam, &spec.Patroni, c.OpConfig.PamRoleName, c.logger)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("could not generate Spilo JSON configuration: %v", err)
 | 
							return nil, fmt.Errorf("could not generate Spilo JSON configuration: %v", err)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue