Improvements
-handle rollingUpdate flag -modularize code -rename config parameter name
This commit is contained in:
parent
8d718c4fc1
commit
eec21453f8
|
|
@ -65,14 +65,14 @@ type KubernetesMetaConfiguration struct {
|
||||||
NodeReadinessLabel map[string]string `json:"node_readiness_label,omitempty"`
|
NodeReadinessLabel map[string]string `json:"node_readiness_label,omitempty"`
|
||||||
CustomPodAnnotations map[string]string `json:"custom_pod_annotations,omitempty"`
|
CustomPodAnnotations map[string]string `json:"custom_pod_annotations,omitempty"`
|
||||||
// TODO: use a proper toleration structure?
|
// TODO: use a proper toleration structure?
|
||||||
PodToleration map[string]string `json:"toleration,omitempty"`
|
PodToleration map[string]string `json:"toleration,omitempty"`
|
||||||
PodEnvironmentConfigMap spec.NamespacedName `json:"pod_environment_configmap,omitempty"`
|
PodEnvironmentConfigMap spec.NamespacedName `json:"pod_environment_configmap,omitempty"`
|
||||||
PodPriorityClassName string `json:"pod_priority_class_name,omitempty"`
|
PodPriorityClassName string `json:"pod_priority_class_name,omitempty"`
|
||||||
MasterPodMoveTimeout Duration `json:"master_pod_move_timeout,omitempty"`
|
MasterPodMoveTimeout Duration `json:"master_pod_move_timeout,omitempty"`
|
||||||
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"`
|
||||||
StatefulsetPropAnnotations []string `json:"statefulset_propagate_annotations,omitempty"`
|
StatefulsetPropagateAnnotations []string `json:"statefulset_propagate_annotations,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostgresPodResourcesDefaults defines the spec of default resources
|
// PostgresPodResourcesDefaults defines the spec of default resources
|
||||||
|
|
@ -182,31 +182,31 @@ type OperatorLogicalBackupConfiguration struct {
|
||||||
|
|
||||||
// OperatorConfigurationData defines the operation config
|
// OperatorConfigurationData defines the operation config
|
||||||
type OperatorConfigurationData struct {
|
type OperatorConfigurationData struct {
|
||||||
EnableCRDValidation *bool `json:"enable_crd_validation,omitempty"`
|
EnableCRDValidation *bool `json:"enable_crd_validation,omitempty"`
|
||||||
EtcdHost string `json:"etcd_host,omitempty"`
|
EtcdHost string `json:"etcd_host,omitempty"`
|
||||||
KubernetesUseConfigMaps bool `json:"kubernetes_use_configmaps,omitempty"`
|
KubernetesUseConfigMaps bool `json:"kubernetes_use_configmaps,omitempty"`
|
||||||
DockerImage string `json:"docker_image,omitempty"`
|
DockerImage string `json:"docker_image,omitempty"`
|
||||||
Workers uint32 `json:"workers,omitempty"`
|
Workers uint32 `json:"workers,omitempty"`
|
||||||
MinInstances int32 `json:"min_instances,omitempty"`
|
MinInstances int32 `json:"min_instances,omitempty"`
|
||||||
MaxInstances int32 `json:"max_instances,omitempty"`
|
MaxInstances int32 `json:"max_instances,omitempty"`
|
||||||
ResyncPeriod Duration `json:"resync_period,omitempty"`
|
ResyncPeriod Duration `json:"resync_period,omitempty"`
|
||||||
RepairPeriod Duration `json:"repair_period,omitempty"`
|
RepairPeriod Duration `json:"repair_period,omitempty"`
|
||||||
SetMemoryRequestToLimit bool `json:"set_memory_request_to_limit,omitempty"`
|
SetMemoryRequestToLimit bool `json:"set_memory_request_to_limit,omitempty"`
|
||||||
ShmVolume *bool `json:"enable_shm_volume,omitempty"`
|
ShmVolume *bool `json:"enable_shm_volume,omitempty"`
|
||||||
Sidecars map[string]string `json:"sidecar_docker_images,omitempty"`
|
Sidecars map[string]string `json:"sidecar_docker_images,omitempty"`
|
||||||
PostgresUsersConfiguration PostgresUsersConfiguration `json:"users"`
|
PostgresUsersConfiguration PostgresUsersConfiguration `json:"users"`
|
||||||
Kubernetes KubernetesMetaConfiguration `json:"kubernetes"`
|
Kubernetes KubernetesMetaConfiguration `json:"kubernetes"`
|
||||||
PostgresPodResources PostgresPodResourcesDefaults `json:"postgres_pod_resources"`
|
PostgresPodResources PostgresPodResourcesDefaults `json:"postgres_pod_resources"`
|
||||||
Timeouts OperatorTimeouts `json:"timeouts"`
|
Timeouts OperatorTimeouts `json:"timeouts"`
|
||||||
LoadBalancer LoadBalancerConfiguration `json:"load_balancer"`
|
LoadBalancer LoadBalancerConfiguration `json:"load_balancer"`
|
||||||
AWSGCP AWSGCPConfiguration `json:"aws_or_gcp"`
|
AWSGCP AWSGCPConfiguration `json:"aws_or_gcp"`
|
||||||
OperatorDebug OperatorDebugConfiguration `json:"debug"`
|
OperatorDebug OperatorDebugConfiguration `json:"debug"`
|
||||||
TeamsAPI TeamsAPIConfiguration `json:"teams_api"`
|
TeamsAPI TeamsAPIConfiguration `json:"teams_api"`
|
||||||
LoggingRESTAPI LoggingRESTAPIConfiguration `json:"logging_rest_api"`
|
LoggingRESTAPI LoggingRESTAPIConfiguration `json:"logging_rest_api"`
|
||||||
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"`
|
||||||
StatefulsetPropAnnotations []string `json:"statefulset_propagate_annotations,omitempty"`
|
StatefulsetPropagateAnnotations []string `json:"statefulset_propagate_annotations,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//Duration shortens this frequently used name
|
//Duration shortens this frequently used name
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,11 @@ func (in *KubernetesMetaConfiguration) DeepCopyInto(out *KubernetesMetaConfigura
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.PodEnvironmentConfigMap = in.PodEnvironmentConfigMap
|
out.PodEnvironmentConfigMap = in.PodEnvironmentConfigMap
|
||||||
|
if in.StatefulsetPropagateAnnotations != nil {
|
||||||
|
in, out := &in.StatefulsetPropagateAnnotations, &out.StatefulsetPropagateAnnotations
|
||||||
|
*out = make([]string, len(*in))
|
||||||
|
copy(*out, *in)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
|
@ -1149,13 +1150,14 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
|
||||||
}
|
}
|
||||||
|
|
||||||
annotations = make(map[string]string)
|
annotations = make(map[string]string)
|
||||||
|
annotations[rollingUpdateStatefulsetAnnotationKey] = strconv.FormatBool(false)
|
||||||
|
|
||||||
statefulSet := &appsv1.StatefulSet{
|
statefulSet := &appsv1.StatefulSet{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: c.statefulSetName(),
|
Name: c.statefulSetName(),
|
||||||
Namespace: c.Namespace,
|
Namespace: c.Namespace,
|
||||||
Labels: c.labelsSet(true),
|
Labels: c.labelsSet(true),
|
||||||
Annotations: annotations,
|
Annotations: c.PropagateAnnotationsToStatefulsets(annotations),
|
||||||
},
|
},
|
||||||
Spec: appsv1.StatefulSetSpec{
|
Spec: appsv1.StatefulSetSpec{
|
||||||
Replicas: &numberOfInstances,
|
Replicas: &numberOfInstances,
|
||||||
|
|
|
||||||
|
|
@ -331,21 +331,8 @@ func (c *Cluster) syncStatefulSet() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ToPropagateAnnotations := c.OpConfig.StatefulsetPropAnnotations
|
annotations := c.PropagateAnnotationsToStatefulsets(c.Statefulset.Annotations)
|
||||||
PgCRDAnnotations := c.Postgresql.ObjectMeta.GetAnnotations()
|
c.updateStatefulSetAnnotations(annotations)
|
||||||
annotations := make(map[string]string)
|
|
||||||
|
|
||||||
if ToPropagateAnnotations != nil && PgCRDAnnotations != nil {
|
|
||||||
for _, anno := range ToPropagateAnnotations {
|
|
||||||
for k, v := range PgCRDAnnotations {
|
|
||||||
matched, err := regexp.MatchString(anno, k)
|
|
||||||
if err == nil && matched {
|
|
||||||
annotations[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.updateStatefulSetAnnotations(annotations)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply special PostgreSQL parameters that can only be set via the Patroni API.
|
// Apply special PostgreSQL parameters that can only be set via the Patroni API.
|
||||||
|
|
@ -370,6 +357,26 @@ func (c *Cluster) syncStatefulSet() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PropagateAnnotationsToStatefulsets updates annotations to statefulsets if required
|
||||||
|
// based on the annotations in postgres CRD
|
||||||
|
func (c *Cluster) PropagateAnnotationsToStatefulsets(annotations map[string]string) map[string]string {
|
||||||
|
ToPropagateAnnotations := c.OpConfig.StatefulsetPropagateAnnotations
|
||||||
|
PgCRDAnnotations := c.Postgresql.ObjectMeta.GetAnnotations()
|
||||||
|
|
||||||
|
if ToPropagateAnnotations != nil && PgCRDAnnotations != nil {
|
||||||
|
for _, anno := range ToPropagateAnnotations {
|
||||||
|
for k, v := range PgCRDAnnotations {
|
||||||
|
matched, err := regexp.MatchString(anno, k)
|
||||||
|
if err == nil && matched {
|
||||||
|
annotations[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return annotations
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// checkAndSetGlobalPostgreSQLConfiguration checks whether cluster-wide API parameters
|
// checkAndSetGlobalPostgreSQLConfiguration checks whether cluster-wide API parameters
|
||||||
// (like max_connections) has changed and if necessary sets it via the Patroni API
|
// (like max_connections) has changed and if necessary sets it via the Patroni API
|
||||||
func (c *Cluster) checkAndSetGlobalPostgreSQLConfiguration() error {
|
func (c *Cluster) checkAndSetGlobalPostgreSQLConfiguration() error {
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
|
||||||
result.ShmVolume = fromCRD.ShmVolume
|
result.ShmVolume = fromCRD.ShmVolume
|
||||||
result.Sidecars = fromCRD.Sidecars
|
result.Sidecars = fromCRD.Sidecars
|
||||||
|
|
||||||
result.StatefulsetPropAnnotations = fromCRD.StatefulsetPropAnnotations
|
result.StatefulsetPropagateAnnotations = fromCRD.StatefulsetPropagateAnnotations
|
||||||
|
|
||||||
// user config
|
// user config
|
||||||
result.SuperUsername = fromCRD.PostgresUsersConfiguration.SuperUsername
|
result.SuperUsername = fromCRD.PostgresUsersConfiguration.SuperUsername
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,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"`
|
||||||
StatefulsetPropAnnotations []string `name:"statefulset_propagate_annotations"`
|
StatefulsetPropagateAnnotations []string `name:"statefulset_propagate_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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue