From 7bd39d3bfd35ca2df95ebf702bcb4be35dde1a0c Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Fri, 29 Nov 2019 18:08:00 +0100 Subject: [PATCH] only error on Sts creation --- charts/postgres-operator/values.yaml | 2 +- ...gresql-operator-default-configuration.yaml | 2 +- pkg/cluster/k8sres.go | 22 +++++++++---------- pkg/cluster/resources.go | 11 ++++++++++ pkg/util/config/config.go | 2 +- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/charts/postgres-operator/values.yaml b/charts/postgres-operator/values.yaml index c42883f65..826862c4a 100644 --- a/charts/postgres-operator/values.yaml +++ b/charts/postgres-operator/values.yaml @@ -57,7 +57,7 @@ configKubernetes: # label assigned to Kubernetes objects created by the operator cluster_name_label: version # annotations attached to each database pod - # custom_pod_annotations: keya:valuea,keyb:valueb + # custom_pod_annotations: "keya:valuea,keyb:valueb" # enables initContainers to run actions before Spilo is started enable_init_containers: "true" diff --git a/manifests/postgresql-operator-default-configuration.yaml b/manifests/postgresql-operator-default-configuration.yaml index f22a158e0..84e12b4ee 100644 --- a/manifests/postgresql-operator-default-configuration.yaml +++ b/manifests/postgresql-operator-default-configuration.yaml @@ -35,7 +35,7 @@ configuration: # - application # - environment # node_readiness_label: - # status: ready + # status: ready oauth_token_secret_name: postgresql-operator pdb_name_format: "postgres-{cluster}-pdb" pod_antiaffinity_topology_key: "kubernetes.io/hostname" diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index ab9b8aa69..53249457b 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -788,11 +788,10 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef } if spec.InitContainers != nil && len(spec.InitContainers) > 0 { - if c.OpConfig.EnableInitContainers != nil && *c.OpConfig.EnableInitContainers { - initContainers = spec.InitContainers - } else { - return nil, fmt.Errorf("initContainers specified but globally disabled") + if c.OpConfig.EnableInitContainers != nil && !(*c.OpConfig.EnableInitContainers) { + c.logger.Warningf("initContainers in use but globally disabled - next statefulSet creation would fail") } + initContainers = spec.InitContainers } customPodEnvVarsList := make([]v1.EnvVar, 0) @@ -882,13 +881,12 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef // generate sidecar containers if sideCars != nil && len(sideCars) > 0 { - if c.OpConfig.EnableSidecars != nil && *c.OpConfig.EnableSidecars { - if sidecarContainers, err = generateSidecarContainers(sideCars, volumeMounts, defaultResources, - c.OpConfig.SuperUsername, c.credentialSecretName(c.OpConfig.SuperUsername), c.logger); err != nil { - return nil, fmt.Errorf("could not generate sidecar containers: %v", err) - } - } else { - return nil, fmt.Errorf("sidecar containers specified but globally disabled") + if c.OpConfig.EnableSidecars != nil && !(*c.OpConfig.EnableSidecars) { + c.logger.Warningf("sidecars in use but globally disabled - next stateful set creation would fail") + } + if sidecarContainers, err = generateSidecarContainers(sideCars, volumeMounts, defaultResources, + c.OpConfig.SuperUsername, c.credentialSecretName(c.OpConfig.SuperUsername), c.logger); err != nil { + return nil, fmt.Errorf("could not generate sidecar containers: %v", err) } } @@ -1427,7 +1425,7 @@ func (c *Cluster) generatePodDisruptionBudget() *policybeta1.PodDisruptionBudget pdbEnabled := c.OpConfig.EnablePodDisruptionBudget // if PodDisruptionBudget is disabled or if there are no DB pods, set the budget to 0. - if (pdbEnabled != nil && !*pdbEnabled) || c.Spec.NumberOfInstances <= 0 { + if (pdbEnabled != nil && !(*pdbEnabled)) || c.Spec.NumberOfInstances <= 0 { minAvailable = intstr.FromInt(0) } diff --git a/pkg/cluster/resources.go b/pkg/cluster/resources.go index 3e8f73916..89c63970e 100644 --- a/pkg/cluster/resources.go +++ b/pkg/cluster/resources.go @@ -65,6 +65,17 @@ func (c *Cluster) listResources() error { func (c *Cluster) createStatefulSet() (*appsv1.StatefulSet, error) { c.setProcessName("creating statefulset") + // check if it's allowed that spec contains initContainers + if c.Spec.InitContainers != nil && len(c.Spec.InitContainers) > 0 && + c.OpConfig.EnableInitContainers != nil && !*c.OpConfig.EnableInitContainers { + return nil, fmt.Errorf("initContainers specified but globally disabled") + } + // check if it's allowed that spec contains sidecars + if c.Spec.Sidecars != nil && len(c.Spec.Sidecars) > 0 && + c.OpConfig.EnableSidecars != nil && !*c.OpConfig.EnableSidecars { + return nil, fmt.Errorf("sidecar containers specified but globally disabled") + } + statefulSetSpec, err := c.generateStatefulSet(&c.Spec) if err != nil { return nil, fmt.Errorf("could not generate statefulset: %v", err) diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 9c706a28b..d46cba2b2 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -123,8 +123,8 @@ type Config struct { ReplicaDNSNameFormat StringTemplate `name:"replica_dns_name_format" default:"{cluster}-repl.{team}.{hostedzone}"` PDBNameFormat StringTemplate `name:"pdb_name_format" default:"postgres-{cluster}-pdb"` EnablePodDisruptionBudget *bool `name:"enable_pod_disruption_budget" default:"true"` - EnableSidecars *bool `name:"enable_sidecars" default:"true"` EnableInitContainers *bool `name:"enable_init_containers" default:"true"` + EnableSidecars *bool `name:"enable_sidecars" default:"true"` Workers uint32 `name:"workers" default:"4"` APIPort int `name:"api_port" default:"8080"` RingLogLines int `name:"ring_log_lines" default:"100"`