Handle update path and renaming

- handle the update path to update sts and connection pooler deployment.
  This way no need to wait for sync
- rename the parameter to downscaler_annotations
- handle other review comments
This commit is contained in:
Rafia Sabih 2020-04-30 13:20:44 +02:00
parent 1745c44c5e
commit 11ef0cf722
15 changed files with 41 additions and 45 deletions

View File

@ -166,11 +166,6 @@ These parameters are grouped directly under the `spec` key in the manifest.
If you set the `all` special item, it will be mounted in all containers (postgres + sidecars). If you set the `all` special item, it will be mounted in all containers (postgres + sidecars).
Else you can set the list of target containers in which the additional volumes will be mounted (eg : postgres, telegraf) Else you can set the list of target containers in which the additional volumes will be mounted (eg : postgres, telegraf)
* **statefulset_propagate_annotations**
An array of annotations from PostgresCRD that should be passed on to the statefulsets.
This also accepts the regular expression like downscaler/*, etc.
These annotations will also be passed to the connection-pooler deployments if any.
## Postgres parameters ## Postgres parameters
Those parameters are grouped under the `postgresql` top-level key, which is Those parameters are grouped under the `postgresql` top-level key, which is

View File

@ -151,7 +151,7 @@ Those are top-level keys, containing both leaf keys and groups.
[operator deployment manually](../../manifests/postgres-operator.yaml#L20). [operator deployment manually](../../manifests/postgres-operator.yaml#L20).
The default is `false`. The default is `false`.
* **statefulset_propagate_annotations** * **downscaler_annotations**
An array of annotations from PostgresCRD that should be passed on to the statefulsets. An array of annotations from PostgresCRD that should be passed on to the statefulsets.
This also accepts the regular expression like downscaler/*, etc. This also accepts the regular expression like downscaler/*, etc.
These annotations will also be passed to the connection-pooler deployments if any. These annotations will also be passed to the connection-pooler deployments if any.

View File

@ -502,7 +502,7 @@ class EndToEndTestCase(unittest.TestCase):
patch_sset_propagate_annotations = { patch_sset_propagate_annotations = {
"data": { "data": {
"statefulset_propagate_annotations": "deployment-time,downscaler/*", "downscaler_annotations": "deployment-time,downscaler/*",
} }
} }
k8s.update_config(patch_sset_propagate_annotations) k8s.update_config(patch_sset_propagate_annotations)

View File

@ -94,7 +94,7 @@ data:
# sidecar_docker_images: "" # sidecar_docker_images: ""
# set_memory_request_to_limit: "false" # set_memory_request_to_limit: "false"
spilo_privileged: "false" spilo_privileged: "false"
# statefulset_propagate_annotations: "deployment-time,downscaler/*" # downscaler_annotations: "deployment-time,downscaler/*"
super_username: postgres super_username: postgres
# team_admin_role: "admin" # team_admin_role: "admin"
# team_api_role_configuration: "log_statement:all" # team_api_role_configuration: "log_statement:all"

View File

@ -34,7 +34,7 @@ spec:
configuration: configuration:
type: object type: object
properties: properties:
# statefulset_propagate_annotations: # downscaler_annotations:
# type: array # type: array
# items: # items:
# type: string # type: string

View File

@ -4,7 +4,7 @@ metadata:
name: postgresql-operator-default-configuration name: postgresql-operator-default-configuration
configuration: configuration:
docker_image: registry.opensource.zalan.do/acid/spilo-cdp-12:1.6-p115 docker_image: registry.opensource.zalan.do/acid/spilo-cdp-12:1.6-p115
# statefulset_propagate_annotations: # downscaler_annotations:
# - deployment-time # - deployment-time
# - downscaler/* # - downscaler/*
# enable_crd_validation: true # enable_crd_validation: true

View File

@ -888,7 +888,7 @@ var OperatorConfigCRDResourceValidation = apiextv1beta1.CustomResourceValidation
}, },
}, },
}, },
"statefulset_propagate_annotations": { "downscaler_annotations": {
Type: "array", Type: "array",
Items: &apiextv1beta1.JSONSchemaPropsOrArray{ Items: &apiextv1beta1.JSONSchemaPropsOrArray{
Schema: &apiextv1beta1.JSONSchemaProps{ Schema: &apiextv1beta1.JSONSchemaProps{

View File

@ -73,7 +73,7 @@ type KubernetesMetaConfiguration struct {
EnablePodAntiAffinity bool `json:"enable_pod_antiaffinity,omitempty"` EnablePodAntiAffinity bool `json:"enable_pod_antiaffinity,omitempty"`
PodAntiAffinityTopologyKey string `json:"pod_antiaffinity_topology_key,omitempty"` PodAntiAffinityTopologyKey string `json:"pod_antiaffinity_topology_key,omitempty"`
PodManagementPolicy string `json:"pod_management_policy,omitempty"` PodManagementPolicy string `json:"pod_management_policy,omitempty"`
StatefulsetPropagateAnnotations []string `json:"statefulset_propagate_annotations,omitempty"` DownscalerAnnotations []string `json:"downscaler_annotations,omitempty"`
} }
// PostgresPodResourcesDefaults defines the spec of default resources // PostgresPodResourcesDefaults defines the spec of default resources
@ -210,7 +210,7 @@ type OperatorConfigurationData struct {
Scalyr ScalyrConfiguration `json:"scalyr"` Scalyr ScalyrConfiguration `json:"scalyr"`
LogicalBackup OperatorLogicalBackupConfiguration `json:"logical_backup"` LogicalBackup OperatorLogicalBackupConfiguration `json:"logical_backup"`
ConnectionPooler ConnectionPoolerConfiguration `json:"connection_pooler"` ConnectionPooler ConnectionPoolerConfiguration `json:"connection_pooler"`
StatefulsetPropagateAnnotations []string `json:"statefulset_propagate_annotations,omitempty"` DownscalerAnnotations []string `json:"downscaler_annotations,omitempty"`
} }
//Duration shortens this frequently used name //Duration shortens this frequently used name

View File

@ -202,8 +202,8 @@ func (in *KubernetesMetaConfiguration) DeepCopyInto(out *KubernetesMetaConfigura
} }
} }
out.PodEnvironmentConfigMap = in.PodEnvironmentConfigMap out.PodEnvironmentConfigMap = in.PodEnvironmentConfigMap
if in.StatefulsetPropagateAnnotations != nil { if in.DownscalerAnnotations != nil {
in, out := &in.StatefulsetPropagateAnnotations, &out.StatefulsetPropagateAnnotations in, out := &in.DownscalerAnnotations, &out.DownscalerAnnotations
*out = make([]string, len(*in)) *out = make([]string, len(*in))
copy(*out, *in) copy(*out, *in)
} }
@ -343,8 +343,8 @@ func (in *OperatorConfigurationData) DeepCopyInto(out *OperatorConfigurationData
out.Scalyr = in.Scalyr out.Scalyr = in.Scalyr
out.LogicalBackup = in.LogicalBackup out.LogicalBackup = in.LogicalBackup
in.ConnectionPooler.DeepCopyInto(&out.ConnectionPooler) in.ConnectionPooler.DeepCopyInto(&out.ConnectionPooler)
if in.StatefulsetPropagateAnnotations != nil { if in.DownscalerAnnotations != nil {
in, out := &in.StatefulsetPropagateAnnotations, &out.StatefulsetPropagateAnnotations in, out := &in.DownscalerAnnotations, &out.DownscalerAnnotations
*out = make([]string, len(*in)) *out = make([]string, len(*in))
copy(*out, *in) copy(*out, *in)
} }

View File

@ -711,8 +711,7 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error {
updateFailed = true updateFailed = true
return return
} }
if !reflect.DeepEqual(oldSs, newSs) || !reflect.DeepEqual(oldSpec.Annotations, newSpec.Annotations) {
if !reflect.DeepEqual(oldSs, newSs) {
c.logger.Debugf("syncing statefulsets") c.logger.Debugf("syncing statefulsets")
// TODO: avoid generating the StatefulSet object twice by passing it to syncStatefulSet // TODO: avoid generating the StatefulSet object twice by passing it to syncStatefulSet
if err := c.syncStatefulSet(); err != nil { if err := c.syncStatefulSet(); err != nil {

View File

@ -34,7 +34,7 @@ var cl = New(
SuperUsername: superUserName, SuperUsername: superUserName,
ReplicationUsername: replicationUserName, ReplicationUsername: replicationUserName,
}, },
StatefulsetPropagateAnnotations: []string{"downscaler/*"}, DownscalerAnnotations: []string{"downscaler/*"},
}, },
}, },
k8sutil.NewMockKubernetesClient(), k8sutil.NewMockKubernetesClient(),

View File

@ -403,7 +403,7 @@ func (c *Cluster) syncStatefulSet() error {
// AnnotationsToPropagate get the annotations to update if required // AnnotationsToPropagate get the annotations to update if required
// based on the annotations in postgres CRD // based on the annotations in postgres CRD
func (c *Cluster) AnnotationsToPropagate(annotations map[string]string) map[string]string { func (c *Cluster) AnnotationsToPropagate(annotations map[string]string) map[string]string {
toPropagateAnnotations := c.OpConfig.StatefulsetPropagateAnnotations toPropagateAnnotations := c.OpConfig.DownscalerAnnotations
pgCRDAnnotations := c.Postgresql.ObjectMeta.GetAnnotations() pgCRDAnnotations := c.Postgresql.ObjectMeta.GetAnnotations()
if toPropagateAnnotations != nil && pgCRDAnnotations != nil { if toPropagateAnnotations != nil && pgCRDAnnotations != nil {

View File

@ -48,7 +48,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
result.SidecarImages = fromCRD.SidecarImages result.SidecarImages = fromCRD.SidecarImages
result.SidecarContainers = fromCRD.SidecarContainers result.SidecarContainers = fromCRD.SidecarContainers
result.StatefulsetPropagateAnnotations = fromCRD.StatefulsetPropagateAnnotations result.DownscalerAnnotations = fromCRD.Kubernetes.DownscalerAnnotations
// user config // user config
result.SuperUsername = fromCRD.PostgresUsersConfiguration.SuperUsername result.SuperUsername = fromCRD.PostgresUsersConfiguration.SuperUsername

View File

@ -487,8 +487,10 @@ func (c *Controller) postgresqlUpdate(prev, cur interface{}) {
if pgOld != nil && pgNew != nil { if pgOld != nil && pgNew != nil {
// Avoid the inifinite recursion for status updates // Avoid the inifinite recursion for status updates
if reflect.DeepEqual(pgOld.Spec, pgNew.Spec) { if reflect.DeepEqual(pgOld.Spec, pgNew.Spec) {
if pgNew.Annotations != nil && pgOld.Annotations != nil && !reflect.DeepEqual(pgNew.Annotations, pgOld.Annotations) {
return return
} }
}
c.queueClusterEvent(pgOld, pgNew, EventUpdate) c.queueClusterEvent(pgOld, pgNew, EventUpdate)
} }

View File

@ -137,7 +137,7 @@ type Config struct {
EnableReplicaLoadBalancer bool `name:"enable_replica_load_balancer" default:"false"` EnableReplicaLoadBalancer bool `name:"enable_replica_load_balancer" default:"false"`
CustomServiceAnnotations map[string]string `name:"custom_service_annotations"` CustomServiceAnnotations map[string]string `name:"custom_service_annotations"`
CustomPodAnnotations map[string]string `name:"custom_pod_annotations"` CustomPodAnnotations map[string]string `name:"custom_pod_annotations"`
StatefulsetPropagateAnnotations []string `name:"statefulset_propagate_annotations"` DownscalerAnnotations []string `name:"downscaler_annotations"`
EnablePodAntiAffinity bool `name:"enable_pod_antiaffinity" default:"false"` EnablePodAntiAffinity bool `name:"enable_pod_antiaffinity" default:"false"`
PodAntiAffinityTopologyKey string `name:"pod_antiaffinity_topology_key" default:"kubernetes.io/hostname"` PodAntiAffinityTopologyKey string `name:"pod_antiaffinity_topology_key" default:"kubernetes.io/hostname"`
// deprecated and kept for backward compatibility // deprecated and kept for backward compatibility