diff --git a/docs/reference/cluster_manifest.md b/docs/reference/cluster_manifest.md index 1e97f0771..576031543 100644 --- a/docs/reference/cluster_manifest.md +++ b/docs/reference/cluster_manifest.md @@ -165,11 +165,6 @@ These parameters are grouped directly under the `spec` key in the manifest. If `targetContainers` is empty, additional volumes will be mounted only in the `postgres` container. 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) - - * **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 diff --git a/docs/reference/operator_parameters.md b/docs/reference/operator_parameters.md index b7d69ab80..cd4a487f5 100644 --- a/docs/reference/operator_parameters.md +++ b/docs/reference/operator_parameters.md @@ -151,7 +151,7 @@ Those are top-level keys, containing both leaf keys and groups. [operator deployment manually](../../manifests/postgres-operator.yaml#L20). The default is `false`. -* **statefulset_propagate_annotations** +* **downscaler_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. diff --git a/e2e/tests/test_e2e.py b/e2e/tests/test_e2e.py index f5a4b7ebe..aaf9cecec 100644 --- a/e2e/tests/test_e2e.py +++ b/e2e/tests/test_e2e.py @@ -502,7 +502,7 @@ class EndToEndTestCase(unittest.TestCase): patch_sset_propagate_annotations = { "data": { - "statefulset_propagate_annotations": "deployment-time,downscaler/*", + "downscaler_annotations": "deployment-time,downscaler/*", } } k8s.update_config(patch_sset_propagate_annotations) diff --git a/manifests/configmap.yaml b/manifests/configmap.yaml index 74d3eaa77..87f1634f7 100644 --- a/manifests/configmap.yaml +++ b/manifests/configmap.yaml @@ -94,7 +94,7 @@ data: # sidecar_docker_images: "" # set_memory_request_to_limit: "false" spilo_privileged: "false" - # statefulset_propagate_annotations: "deployment-time,downscaler/*" + # downscaler_annotations: "deployment-time,downscaler/*" super_username: postgres # team_admin_role: "admin" # team_api_role_configuration: "log_statement:all" diff --git a/manifests/operatorconfiguration.crd.yaml b/manifests/operatorconfiguration.crd.yaml index 5fd67aee9..57c44aee8 100644 --- a/manifests/operatorconfiguration.crd.yaml +++ b/manifests/operatorconfiguration.crd.yaml @@ -34,7 +34,7 @@ spec: configuration: type: object properties: - # statefulset_propagate_annotations: + # downscaler_annotations: # type: array # items: # type: string diff --git a/manifests/postgresql-operator-default-configuration.yaml b/manifests/postgresql-operator-default-configuration.yaml index ae256f799..93c305232 100644 --- a/manifests/postgresql-operator-default-configuration.yaml +++ b/manifests/postgresql-operator-default-configuration.yaml @@ -4,7 +4,7 @@ metadata: name: postgresql-operator-default-configuration configuration: docker_image: registry.opensource.zalan.do/acid/spilo-cdp-12:1.6-p115 - # statefulset_propagate_annotations: + # downscaler_annotations: # - deployment-time # - downscaler/* # enable_crd_validation: true diff --git a/pkg/apis/acid.zalan.do/v1/crds.go b/pkg/apis/acid.zalan.do/v1/crds.go index 007de1e81..ad1b79a45 100644 --- a/pkg/apis/acid.zalan.do/v1/crds.go +++ b/pkg/apis/acid.zalan.do/v1/crds.go @@ -888,7 +888,7 @@ var OperatorConfigCRDResourceValidation = apiextv1beta1.CustomResourceValidation }, }, }, - "statefulset_propagate_annotations": { + "downscaler_annotations": { Type: "array", Items: &apiextv1beta1.JSONSchemaPropsOrArray{ Schema: &apiextv1beta1.JSONSchemaProps{ diff --git a/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go b/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go index c240cb579..fe14a7702 100644 --- a/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go +++ b/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go @@ -66,14 +66,14 @@ type KubernetesMetaConfiguration struct { NodeReadinessLabel map[string]string `json:"node_readiness_label,omitempty"` CustomPodAnnotations map[string]string `json:"custom_pod_annotations,omitempty"` // TODO: use a proper toleration structure? - PodToleration map[string]string `json:"toleration,omitempty"` - PodEnvironmentConfigMap spec.NamespacedName `json:"pod_environment_configmap,omitempty"` - PodPriorityClassName string `json:"pod_priority_class_name,omitempty"` - MasterPodMoveTimeout Duration `json:"master_pod_move_timeout,omitempty"` - EnablePodAntiAffinity bool `json:"enable_pod_antiaffinity,omitempty"` - PodAntiAffinityTopologyKey string `json:"pod_antiaffinity_topology_key,omitempty"` - PodManagementPolicy string `json:"pod_management_policy,omitempty"` - StatefulsetPropagateAnnotations []string `json:"statefulset_propagate_annotations,omitempty"` + PodToleration map[string]string `json:"toleration,omitempty"` + PodEnvironmentConfigMap spec.NamespacedName `json:"pod_environment_configmap,omitempty"` + PodPriorityClassName string `json:"pod_priority_class_name,omitempty"` + MasterPodMoveTimeout Duration `json:"master_pod_move_timeout,omitempty"` + EnablePodAntiAffinity bool `json:"enable_pod_antiaffinity,omitempty"` + PodAntiAffinityTopologyKey string `json:"pod_antiaffinity_topology_key,omitempty"` + PodManagementPolicy string `json:"pod_management_policy,omitempty"` + DownscalerAnnotations []string `json:"downscaler_annotations,omitempty"` } // PostgresPodResourcesDefaults defines the spec of default resources @@ -196,21 +196,21 @@ type OperatorConfigurationData struct { SetMemoryRequestToLimit bool `json:"set_memory_request_to_limit,omitempty"` ShmVolume *bool `json:"enable_shm_volume,omitempty"` // deprecated in favour of SidecarContainers - SidecarImages map[string]string `json:"sidecar_docker_images,omitempty"` - SidecarContainers []v1.Container `json:"sidecars,omitempty"` - PostgresUsersConfiguration PostgresUsersConfiguration `json:"users"` - Kubernetes KubernetesMetaConfiguration `json:"kubernetes"` - PostgresPodResources PostgresPodResourcesDefaults `json:"postgres_pod_resources"` - Timeouts OperatorTimeouts `json:"timeouts"` - LoadBalancer LoadBalancerConfiguration `json:"load_balancer"` - AWSGCP AWSGCPConfiguration `json:"aws_or_gcp"` - OperatorDebug OperatorDebugConfiguration `json:"debug"` - TeamsAPI TeamsAPIConfiguration `json:"teams_api"` - LoggingRESTAPI LoggingRESTAPIConfiguration `json:"logging_rest_api"` - Scalyr ScalyrConfiguration `json:"scalyr"` - LogicalBackup OperatorLogicalBackupConfiguration `json:"logical_backup"` - ConnectionPooler ConnectionPoolerConfiguration `json:"connection_pooler"` - StatefulsetPropagateAnnotations []string `json:"statefulset_propagate_annotations,omitempty"` + SidecarImages map[string]string `json:"sidecar_docker_images,omitempty"` + SidecarContainers []v1.Container `json:"sidecars,omitempty"` + PostgresUsersConfiguration PostgresUsersConfiguration `json:"users"` + Kubernetes KubernetesMetaConfiguration `json:"kubernetes"` + PostgresPodResources PostgresPodResourcesDefaults `json:"postgres_pod_resources"` + Timeouts OperatorTimeouts `json:"timeouts"` + LoadBalancer LoadBalancerConfiguration `json:"load_balancer"` + AWSGCP AWSGCPConfiguration `json:"aws_or_gcp"` + OperatorDebug OperatorDebugConfiguration `json:"debug"` + TeamsAPI TeamsAPIConfiguration `json:"teams_api"` + LoggingRESTAPI LoggingRESTAPIConfiguration `json:"logging_rest_api"` + Scalyr ScalyrConfiguration `json:"scalyr"` + LogicalBackup OperatorLogicalBackupConfiguration `json:"logical_backup"` + ConnectionPooler ConnectionPoolerConfiguration `json:"connection_pooler"` + DownscalerAnnotations []string `json:"downscaler_annotations,omitempty"` } //Duration shortens this frequently used name diff --git a/pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go b/pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go index 31ad514fd..0f1962f07 100644 --- a/pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go +++ b/pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go @@ -202,8 +202,8 @@ func (in *KubernetesMetaConfiguration) DeepCopyInto(out *KubernetesMetaConfigura } } out.PodEnvironmentConfigMap = in.PodEnvironmentConfigMap - if in.StatefulsetPropagateAnnotations != nil { - in, out := &in.StatefulsetPropagateAnnotations, &out.StatefulsetPropagateAnnotations + if in.DownscalerAnnotations != nil { + in, out := &in.DownscalerAnnotations, &out.DownscalerAnnotations *out = make([]string, len(*in)) copy(*out, *in) } @@ -343,8 +343,8 @@ func (in *OperatorConfigurationData) DeepCopyInto(out *OperatorConfigurationData out.Scalyr = in.Scalyr out.LogicalBackup = in.LogicalBackup in.ConnectionPooler.DeepCopyInto(&out.ConnectionPooler) - if in.StatefulsetPropagateAnnotations != nil { - in, out := &in.StatefulsetPropagateAnnotations, &out.StatefulsetPropagateAnnotations + if in.DownscalerAnnotations != nil { + in, out := &in.DownscalerAnnotations, &out.DownscalerAnnotations *out = make([]string, len(*in)) copy(*out, *in) } diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 387107540..31b8fa155 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -711,8 +711,7 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error { updateFailed = true return } - - if !reflect.DeepEqual(oldSs, newSs) { + if !reflect.DeepEqual(oldSs, newSs) || !reflect.DeepEqual(oldSpec.Annotations, newSpec.Annotations) { c.logger.Debugf("syncing statefulsets") // TODO: avoid generating the StatefulSet object twice by passing it to syncStatefulSet if err := c.syncStatefulSet(); err != nil { diff --git a/pkg/cluster/cluster_test.go b/pkg/cluster/cluster_test.go index 43f03a0e1..9d1bb4444 100644 --- a/pkg/cluster/cluster_test.go +++ b/pkg/cluster/cluster_test.go @@ -34,7 +34,7 @@ var cl = New( SuperUsername: superUserName, ReplicationUsername: replicationUserName, }, - StatefulsetPropagateAnnotations: []string{"downscaler/*"}, + DownscalerAnnotations: []string{"downscaler/*"}, }, }, k8sutil.NewMockKubernetesClient(), diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index 2f146f699..697fc2d05 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -403,7 +403,7 @@ func (c *Cluster) syncStatefulSet() error { // AnnotationsToPropagate get the annotations to update if required // based on the annotations in postgres CRD func (c *Cluster) AnnotationsToPropagate(annotations map[string]string) map[string]string { - toPropagateAnnotations := c.OpConfig.StatefulsetPropagateAnnotations + toPropagateAnnotations := c.OpConfig.DownscalerAnnotations pgCRDAnnotations := c.Postgresql.ObjectMeta.GetAnnotations() if toPropagateAnnotations != nil && pgCRDAnnotations != nil { diff --git a/pkg/controller/operator_config.go b/pkg/controller/operator_config.go index 0cafff81e..3ad967f9c 100644 --- a/pkg/controller/operator_config.go +++ b/pkg/controller/operator_config.go @@ -48,7 +48,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur result.SidecarImages = fromCRD.SidecarImages result.SidecarContainers = fromCRD.SidecarContainers - result.StatefulsetPropagateAnnotations = fromCRD.StatefulsetPropagateAnnotations + result.DownscalerAnnotations = fromCRD.Kubernetes.DownscalerAnnotations // user config result.SuperUsername = fromCRD.PostgresUsersConfiguration.SuperUsername diff --git a/pkg/controller/postgresql.go b/pkg/controller/postgresql.go index 2a9e1b650..e4ebaa4ec 100644 --- a/pkg/controller/postgresql.go +++ b/pkg/controller/postgresql.go @@ -487,7 +487,9 @@ func (c *Controller) postgresqlUpdate(prev, cur interface{}) { if pgOld != nil && pgNew != nil { // Avoid the inifinite recursion for status updates if reflect.DeepEqual(pgOld.Spec, pgNew.Spec) { - return + if pgNew.Annotations != nil && pgOld.Annotations != nil && !reflect.DeepEqual(pgNew.Annotations, pgOld.Annotations) { + return + } } c.queueClusterEvent(pgOld, pgNew, EventUpdate) } diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 25a598052..3165cab78 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -137,7 +137,7 @@ type Config struct { EnableReplicaLoadBalancer bool `name:"enable_replica_load_balancer" default:"false"` CustomServiceAnnotations map[string]string `name:"custom_service_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"` PodAntiAffinityTopologyKey string `name:"pod_antiaffinity_topology_key" default:"kubernetes.io/hostname"` // deprecated and kept for backward compatibility