diff --git a/charts/postgres-operator/crds/operatorconfigurations.yaml b/charts/postgres-operator/crds/operatorconfigurations.yaml index 1fca35e22..ca47ab3b8 100644 --- a/charts/postgres-operator/crds/operatorconfigurations.yaml +++ b/charts/postgres-operator/crds/operatorconfigurations.yaml @@ -424,10 +424,10 @@ spec: default: "Cluster" master_dns_name_format: type: string - default: "{cluster}.{team}.{hostedzone}" + default: "{cluster}.{namespace}.{hostedzone}" replica_dns_name_format: type: string - default: "{cluster}-repl.{team}.{hostedzone}" + default: "{cluster}-repl.{namespace}.{hostedzone}" aws_or_gcp: type: object properties: diff --git a/charts/postgres-operator/values.yaml b/charts/postgres-operator/values.yaml index 9e04f8d2e..9870c707f 100644 --- a/charts/postgres-operator/values.yaml +++ b/charts/postgres-operator/values.yaml @@ -269,9 +269,9 @@ configLoadBalancer: # define external traffic policy for the load balancer external_traffic_policy: "Cluster" # defines the DNS name string template for the master load balancer cluster - master_dns_name_format: "{cluster}.{team}.{hostedzone}" + master_dns_name_format: "{cluster}.{namespace}.{hostedzone}" # defines the DNS name string template for the replica load balancer cluster - replica_dns_name_format: "{cluster}-repl.{team}.{hostedzone}" + replica_dns_name_format: "{cluster}-repl.{namespace}.{hostedzone}" # options to aid debugging of the operator itself configDebug: diff --git a/docs/reference/operator_parameters.md b/docs/reference/operator_parameters.md index ba91146e7..a923ad71c 100644 --- a/docs/reference/operator_parameters.md +++ b/docs/reference/operator_parameters.md @@ -617,15 +617,15 @@ In the CRD-based configuration they are grouped under the `load_balancer` key. * **master_dns_name_format** defines the DNS name string template for the master load balancer cluster. The default is - `{cluster}.{team}.{hostedzone}`, where `{cluster}` is replaced by the cluster - name, `{team}` is replaced with the team name and `{hostedzone}` is replaced + `{cluster}.{namespace}.{hostedzone}`, where `{cluster}` is replaced by the cluster + name, `{namespace}` is replaced with the namespace and `{hostedzone}` is replaced with the hosted zone (the value of the `db_hosted_zone` parameter). No other placeholders are allowed. * **replica_dns_name_format** defines the DNS name string template for the replica load balancer cluster. The default is - `{cluster}-repl.{team}.{hostedzone}`, where `{cluster}` is replaced by the - cluster name, `{team}` is replaced with the team name and `{hostedzone}` is + `{cluster}-repl.{namespace}.{hostedzone}`, where `{cluster}` is replaced by the + cluster name, `{namespace}` is replaced with the namespace and `{hostedzone}` is replaced with the hosted zone (the value of the `db_hosted_zone` parameter). No other placeholders are allowed. diff --git a/docs/user.md b/docs/user.md index 43e729909..fc9099234 100644 --- a/docs/user.md +++ b/docs/user.md @@ -152,7 +152,7 @@ specified explicitly. The operator automatically generates a password for each manifest role and places it in the secret named -`{username}.{team}-{clustername}.credentials.postgresql.acid.zalan.do` in the +`{username}.{clustername}.credentials.postgresql.acid.zalan.do` in the same namespace as the cluster. This way, the application running in the K8s cluster and connecting to Postgres can obtain the password right from the secret, without ever sharing it outside of the cluster. @@ -182,7 +182,7 @@ be in the form of `namespace.username`. For such usernames, the secret is created in the given namespace and its name is of the following form, -`{namespace}.{username}.{team}-{clustername}.credentials.postgresql.acid.zalan.do` +`{namespace}.{username}.{clustername}.credentials.postgresql.acid.zalan.do` ### Infrastructure roles diff --git a/manifests/configmap.yaml b/manifests/configmap.yaml index 371cd5bd1..e8823ee0e 100644 --- a/manifests/configmap.yaml +++ b/manifests/configmap.yaml @@ -87,7 +87,7 @@ data: logical_backup_schedule: "30 00 * * *" major_version_upgrade_mode: "manual" # major_version_upgrade_team_allow_list: "" - master_dns_name_format: "{cluster}.{team}.{hostedzone}" + master_dns_name_format: "{cluster}.{namespace}.{hostedzone}" # master_pod_move_timeout: 20m # max_instances: "-1" # min_instances: "-1" @@ -124,7 +124,7 @@ data: ready_wait_interval: 3s ready_wait_timeout: 30s repair_period: 5m - replica_dns_name_format: "{cluster}-repl.{team}.{hostedzone}" + replica_dns_name_format: "{cluster}-repl.{namespace}.{hostedzone}" replication_username: standby resource_check_interval: 3s resource_check_timeout: 10m diff --git a/manifests/operatorconfiguration.crd.yaml b/manifests/operatorconfiguration.crd.yaml index 3d4892bab..1f6d48a4d 100644 --- a/manifests/operatorconfiguration.crd.yaml +++ b/manifests/operatorconfiguration.crd.yaml @@ -422,10 +422,10 @@ spec: default: "Cluster" master_dns_name_format: type: string - default: "{cluster}.{team}.{hostedzone}" + default: "{cluster}.{namespace}.{hostedzone}" replica_dns_name_format: type: string - default: "{cluster}-repl.{team}.{hostedzone}" + default: "{cluster}-repl.{namespace}.{hostedzone}" aws_or_gcp: type: object properties: diff --git a/manifests/postgresql-operator-default-configuration.yaml b/manifests/postgresql-operator-default-configuration.yaml index 645e5138b..7c8ac61ae 100644 --- a/manifests/postgresql-operator-default-configuration.yaml +++ b/manifests/postgresql-operator-default-configuration.yaml @@ -133,8 +133,8 @@ configuration: enable_replica_load_balancer: false enable_replica_pooler_load_balancer: false external_traffic_policy: "Cluster" - master_dns_name_format: "{cluster}.{team}.{hostedzone}" - replica_dns_name_format: "{cluster}-repl.{team}.{hostedzone}" + master_dns_name_format: "{cluster}.{namespace}.{hostedzone}" + replica_dns_name_format: "{cluster}-repl.{namespace}.{hostedzone}" aws_or_gcp: # additional_secret_mount: "some-secret-name" # additional_secret_mount_path: "/some/dir" diff --git a/pkg/cluster/cluster_test.go b/pkg/cluster/cluster_test.go index f36db09b0..e06df9176 100644 --- a/pkg/cluster/cluster_test.go +++ b/pkg/cluster/cluster_test.go @@ -450,6 +450,7 @@ func TestServiceAnnotations(t *testing.T) { enableMasterLoadBalancerOC bool enableReplicaLoadBalancerSpec *bool enableReplicaLoadBalancerOC bool + enableTeamIdClusterPrefix bool operatorAnnotations map[string]string clusterAnnotations map[string]string expect map[string]string @@ -460,6 +461,7 @@ func TestServiceAnnotations(t *testing.T) { role: "master", enableMasterLoadBalancerSpec: &disabled, enableMasterLoadBalancerOC: false, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: make(map[string]string), expect: make(map[string]string), @@ -469,10 +471,11 @@ func TestServiceAnnotations(t *testing.T) { role: "master", enableMasterLoadBalancerSpec: &enabled, enableMasterLoadBalancerOC: false, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", }, }, @@ -481,6 +484,7 @@ func TestServiceAnnotations(t *testing.T) { role: "master", enableMasterLoadBalancerSpec: &disabled, enableMasterLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: make(map[string]string), expect: make(map[string]string), @@ -489,10 +493,11 @@ func TestServiceAnnotations(t *testing.T) { about: "Master with no annotations and EnableMasterLoadBalancer defined only on operator config", role: "master", enableMasterLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", }, }, @@ -500,10 +505,11 @@ func TestServiceAnnotations(t *testing.T) { about: "Master with cluster annotations and load balancer enabled", role: "master", enableMasterLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: map[string]string{"foo": "bar"}, expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", "foo": "bar", }, @@ -513,6 +519,7 @@ func TestServiceAnnotations(t *testing.T) { role: "master", enableMasterLoadBalancerSpec: &disabled, enableMasterLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: map[string]string{"foo": "bar"}, expect: map[string]string{"foo": "bar"}, @@ -521,10 +528,11 @@ func TestServiceAnnotations(t *testing.T) { about: "Master with operator annotations and load balancer enabled", role: "master", enableMasterLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: map[string]string{"foo": "bar"}, clusterAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", "foo": "bar", }, @@ -533,12 +541,13 @@ func TestServiceAnnotations(t *testing.T) { about: "Master with operator annotations override default annotations", role: "master", enableMasterLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: map[string]string{ "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800", }, clusterAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800", }, }, @@ -546,12 +555,13 @@ func TestServiceAnnotations(t *testing.T) { about: "Master with cluster annotations override default annotations", role: "master", enableMasterLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: map[string]string{ "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800", }, expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800", }, }, @@ -559,25 +569,25 @@ func TestServiceAnnotations(t *testing.T) { about: "Master with cluster annotations do not override external-dns annotations", role: "master", enableMasterLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: map[string]string{ "external-dns.alpha.kubernetes.io/hostname": "wrong.external-dns-name.example.com", }, expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", }, }, { - about: "Master with operator annotations do not override external-dns annotations", + about: "Master with cluster name teamId prefix enabled", role: "master", enableMasterLoadBalancerOC: true, + enableTeamIdClusterPrefix: true, clusterAnnotations: make(map[string]string), - operatorAnnotations: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "wrong.external-dns-name.example.com", - }, + operatorAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "test.test.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", }, }, @@ -587,6 +597,7 @@ func TestServiceAnnotations(t *testing.T) { role: "replica", enableReplicaLoadBalancerSpec: &disabled, enableReplicaLoadBalancerOC: false, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: make(map[string]string), expect: make(map[string]string), @@ -596,10 +607,11 @@ func TestServiceAnnotations(t *testing.T) { role: "replica", enableReplicaLoadBalancerSpec: &enabled, enableReplicaLoadBalancerOC: false, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", }, }, @@ -608,6 +620,7 @@ func TestServiceAnnotations(t *testing.T) { role: "replica", enableReplicaLoadBalancerSpec: &disabled, enableReplicaLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: make(map[string]string), expect: make(map[string]string), @@ -616,10 +629,11 @@ func TestServiceAnnotations(t *testing.T) { about: "Replica with no annotations and EnableReplicaLoadBalancer defined only on operator config", role: "replica", enableReplicaLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", }, }, @@ -627,10 +641,11 @@ func TestServiceAnnotations(t *testing.T) { about: "Replica with cluster annotations and load balancer enabled", role: "replica", enableReplicaLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: map[string]string{"foo": "bar"}, expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", "foo": "bar", }, @@ -640,6 +655,7 @@ func TestServiceAnnotations(t *testing.T) { role: "replica", enableReplicaLoadBalancerSpec: &disabled, enableReplicaLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: map[string]string{"foo": "bar"}, expect: map[string]string{"foo": "bar"}, @@ -648,10 +664,11 @@ func TestServiceAnnotations(t *testing.T) { about: "Replica with operator annotations and load balancer enabled", role: "replica", enableReplicaLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: map[string]string{"foo": "bar"}, clusterAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", "foo": "bar", }, @@ -660,12 +677,13 @@ func TestServiceAnnotations(t *testing.T) { about: "Replica with operator annotations override default annotations", role: "replica", enableReplicaLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: map[string]string{ "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800", }, clusterAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800", }, }, @@ -673,12 +691,13 @@ func TestServiceAnnotations(t *testing.T) { about: "Replica with cluster annotations override default annotations", role: "replica", enableReplicaLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: map[string]string{ "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800", }, expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800", }, }, @@ -686,25 +705,25 @@ func TestServiceAnnotations(t *testing.T) { about: "Replica with cluster annotations do not override external-dns annotations", role: "replica", enableReplicaLoadBalancerOC: true, + enableTeamIdClusterPrefix: false, operatorAnnotations: make(map[string]string), clusterAnnotations: map[string]string{ "external-dns.alpha.kubernetes.io/hostname": "wrong.external-dns-name.example.com", }, expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", }, }, { - about: "Replica with operator annotations do not override external-dns annotations", + about: "Replica with cluster name teamId prefix enabled", role: "replica", enableReplicaLoadBalancerOC: true, + enableTeamIdClusterPrefix: true, clusterAnnotations: make(map[string]string), - operatorAnnotations: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "wrong.external-dns-name.example.com", - }, + operatorAnnotations: make(map[string]string), expect: map[string]string{ - "external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com", + "external-dns.alpha.kubernetes.io/hostname": "test-repl.test.db.example.com", "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600", }, }, @@ -713,6 +732,7 @@ func TestServiceAnnotations(t *testing.T) { about: "cluster annotations append to operator annotations", role: "replica", enableReplicaLoadBalancerOC: false, + enableTeamIdClusterPrefix: false, operatorAnnotations: map[string]string{"foo": "bar"}, clusterAnnotations: map[string]string{"post": "gres"}, expect: map[string]string{"foo": "bar", "post": "gres"}, @@ -721,6 +741,7 @@ func TestServiceAnnotations(t *testing.T) { about: "cluster annotations override operator annotations", role: "replica", enableReplicaLoadBalancerOC: false, + enableTeamIdClusterPrefix: false, operatorAnnotations: map[string]string{"foo": "bar", "post": "gres"}, clusterAnnotations: map[string]string{"post": "greSQL"}, expect: map[string]string{"foo": "bar", "post": "greSQL"}, @@ -729,14 +750,20 @@ func TestServiceAnnotations(t *testing.T) { for _, tt := range tests { t.Run(tt.about, func(t *testing.T) { + cl.OpConfig.EnableTeamIdClusternamePrefix = tt.enableTeamIdClusterPrefix + if tt.enableTeamIdClusterPrefix { + cl.Postgresql.Spec.ClusterName = "test" + } else { + cl.Postgresql.Spec.ClusterName = "acid-test" + } + cl.OpConfig.CustomServiceAnnotations = tt.operatorAnnotations cl.OpConfig.EnableMasterLoadBalancer = tt.enableMasterLoadBalancerOC cl.OpConfig.EnableReplicaLoadBalancer = tt.enableReplicaLoadBalancerOC - cl.OpConfig.MasterDNSNameFormat = "{cluster}.{team}.{hostedzone}" - cl.OpConfig.ReplicaDNSNameFormat = "{cluster}-repl.{team}.{hostedzone}" + cl.OpConfig.MasterDNSNameFormat = "{cluster}.{namespace}.{hostedzone}" + cl.OpConfig.ReplicaDNSNameFormat = "{cluster}-repl.{namespace}.{hostedzone}" cl.OpConfig.DbHostedZone = "db.example.com" - cl.Postgresql.Spec.ClusterName = "test" cl.Postgresql.Spec.TeamID = "acid" cl.Postgresql.Spec.ServiceAnnotations = tt.clusterAnnotations cl.Postgresql.Spec.EnableMasterLoadBalancer = tt.enableMasterLoadBalancerSpec diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index d14bc1572..337cd3a63 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -1814,12 +1814,7 @@ func (c *Cluster) generateServiceAnnotations(role PostgresRole, spec *acidv1.Pos } if c.shouldCreateLoadBalancerForService(role, spec) { - var dnsName string - if role == Master { - dnsName = c.masterDNSName() - } else { - dnsName = c.replicaDNSName() - } + dnsName := c.dnsName(role) // Just set ELB Timeout annotation with default value, if it does not // have a cutom value diff --git a/pkg/cluster/util.go b/pkg/cluster/util.go index 37dead012..f520e14ac 100644 --- a/pkg/cluster/util.go +++ b/pkg/cluster/util.go @@ -505,20 +505,50 @@ func (c *Cluster) roleLabelsSet(shouldAddExtraLabels bool, role PostgresRole) la return lbls } +func (c *Cluster) dnsName(role PostgresRole) string { + var dnsString string + if role == Master { + dnsString = c.masterDNSName() + } else { + dnsString = c.replicaDNSName() + } + + // when cluster name starts with teamId prefix create an extra DNS entry + // to support the old format when prefix contraint was enabled (but is disabled now) + if !c.OpConfig.EnableTeamIdClusternamePrefix { + clusterNameWithoutTeamPrefix, _ := acidv1.ExtractClusterName(c.Name, c.Spec.TeamID) + if clusterNameWithoutTeamPrefix != "" { + if role == Replica { + clusterNameWithoutTeamPrefix = fmt.Sprintf("%s-repl", clusterNameWithoutTeamPrefix) + } + dnsString = fmt.Sprintf("%s,%s", dnsString, c.oldDNSFormat(clusterNameWithoutTeamPrefix)) + } + } + + return dnsString +} + func (c *Cluster) masterDNSName() string { return strings.ToLower(c.OpConfig.MasterDNSNameFormat.Format( "cluster", c.Spec.ClusterName, - "team", c.teamName(), + "namespace", c.Namespace, "hostedzone", c.OpConfig.DbHostedZone)) } func (c *Cluster) replicaDNSName() string { return strings.ToLower(c.OpConfig.ReplicaDNSNameFormat.Format( "cluster", c.Spec.ClusterName, - "team", c.teamName(), + "namespace", c.Namespace, "hostedzone", c.OpConfig.DbHostedZone)) } +func (c *Cluster) oldDNSFormat(clusterName string) string { + return fmt.Sprintf("%s.%s.%s", + clusterName, + c.teamName(), + c.OpConfig.DbHostedZone) +} + func (c *Cluster) credentialSecretName(username string) string { return c.credentialSecretNameForCluster(username, c.Name) } diff --git a/pkg/controller/postgresql.go b/pkg/controller/postgresql.go index 861d95032..1333068e5 100644 --- a/pkg/controller/postgresql.go +++ b/pkg/controller/postgresql.go @@ -159,17 +159,24 @@ func (c *Controller) acquireInitialListOfClusters() error { } func (c *Controller) addCluster(lg *logrus.Entry, clusterName spec.NamespacedName, pgSpec *acidv1.Postgresql) (*cluster.Cluster, error) { + var ( + extractedClusterName string + err error + ) if c.opConfig.EnableTeamIdClusternamePrefix { - if _, err := acidv1.ExtractClusterName(clusterName.Name, pgSpec.Spec.TeamID); err != nil { + if extractedClusterName, err = acidv1.ExtractClusterName(clusterName.Name, pgSpec.Spec.TeamID); err != nil { c.KubeClient.SetPostgresCRDStatus(clusterName, acidv1.ClusterStatusInvalid) return nil, err } + } else { + extractedClusterName = clusterName.Name } cl := cluster.New(c.makeClusterConfig(), c.KubeClient, *pgSpec, lg, c.eventRecorder) cl.Run(c.stopCh) teamName := strings.ToLower(cl.Spec.TeamID) + cl.ClusterName = extractedClusterName defer c.clustersMu.Unlock() c.clustersMu.Lock() diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 231929bb8..e1fde13f4 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -206,8 +206,8 @@ type Config struct { StorageResizeMode string `name:"storage_resize_mode" default:"pvc"` EnableLoadBalancer *bool `name:"enable_load_balancer"` // deprecated and kept for backward compatibility ExternalTrafficPolicy string `name:"external_traffic_policy" default:"Cluster"` - MasterDNSNameFormat StringTemplate `name:"master_dns_name_format" default:"{cluster}.{team}.{hostedzone}"` - ReplicaDNSNameFormat StringTemplate `name:"replica_dns_name_format" default:"{cluster}-repl.{team}.{hostedzone}"` + MasterDNSNameFormat StringTemplate `name:"master_dns_name_format" default:"{cluster}.{namespace}.{hostedzone}"` + ReplicaDNSNameFormat StringTemplate `name:"replica_dns_name_format" default:"{cluster}-repl.{namespace}.{hostedzone}"` PDBNameFormat StringTemplate `name:"pdb_name_format" default:"postgres-{cluster}-pdb"` EnablePodDisruptionBudget *bool `name:"enable_pod_disruption_budget" default:"true"` EnableInitContainers *bool `name:"enable_init_containers" default:"true"`