Skip to content

Commit 28cd2f1

Browse files
authored
better backwards compatibility with old DNS name format for LBs (#2171)
* better backwards compatibility with legacy DNS name format for LBs * improve docs on DNS string
1 parent ce1fee8 commit 28cd2f1

File tree

12 files changed

+111
-43
lines changed

12 files changed

+111
-43
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,15 @@ spec:
434434
master_dns_name_format:
435435
type: string
436436
default: "{cluster}.{namespace}.{hostedzone}"
437+
master_legacy_dns_name_format:
438+
type: string
439+
default: "{cluster}.{team}.{hostedzone}"
437440
replica_dns_name_format:
438441
type: string
439442
default: "{cluster}-repl.{namespace}.{hostedzone}"
443+
replica_legacy_dns_name_format:
444+
type: string
445+
default: "{cluster}-repl.{team}.{hostedzone}"
440446
aws_or_gcp:
441447
type: object
442448
properties:

charts/postgres-operator/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,12 @@ configLoadBalancer:
277277
external_traffic_policy: "Cluster"
278278
# defines the DNS name string template for the master load balancer cluster
279279
master_dns_name_format: "{cluster}.{namespace}.{hostedzone}"
280+
# deprecated DNS template for master load balancer using team name
281+
master_legacy_dns_name_format: "{cluster}.{team}.{hostedzone}"
280282
# defines the DNS name string template for the replica load balancer cluster
281283
replica_dns_name_format: "{cluster}-repl.{namespace}.{hostedzone}"
284+
# deprecated DNS template for replica load balancer using team name
285+
replica_legacy_dns_name_format: "{cluster}-repl.{team}.{hostedzone}"
282286

283287
# options to aid debugging of the operator itself
284288
configDebug:

docs/reference/operator_parameters.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -627,22 +627,47 @@ In the CRD-based configuration they are grouped under the `load_balancer` key.
627627
the cluster. Can be overridden by individual cluster settings. The default
628628
is `false`.
629629

630-
* **external_traffic_policy** defines external traffic policy for load
630+
* **external_traffic_policy**
631+
defines external traffic policy for load
631632
balancers. Allowed values are `Cluster` (default) and `Local`.
632633

633-
* **master_dns_name_format** defines the DNS name string template for the
634-
master load balancer cluster. The default is
635-
`{cluster}.{namespace}.{hostedzone}`, where `{cluster}` is replaced by the cluster
636-
name, `{namespace}` is replaced with the namespace and `{hostedzone}` is replaced
637-
with the hosted zone (the value of the `db_hosted_zone` parameter). No other
638-
placeholders are allowed.
639-
640-
* **replica_dns_name_format** defines the DNS name string template for the
641-
replica load balancer cluster. The default is
642-
`{cluster}-repl.{namespace}.{hostedzone}`, where `{cluster}` is replaced by the
643-
cluster name, `{namespace}` is replaced with the namespace and `{hostedzone}` is
644-
replaced with the hosted zone (the value of the `db_hosted_zone` parameter).
645-
No other placeholders are allowed.
634+
* **master_dns_name_format**
635+
defines the DNS name string template for the master load balancer cluster.
636+
The default is `{cluster}.{namespace}.{hostedzone}`, where `{cluster}` is
637+
replaced by the cluster name, `{namespace}` is replaced with the namespace
638+
and `{hostedzone}` is replaced with the hosted zone (the value of the
639+
`db_hosted_zone` parameter). The `{team}` placeholder can still be used,
640+
although it is not recommened because the team of a cluster can change.
641+
If the cluster name starts with the `teamId` it will also be part of the
642+
DNS, aynway. No other placeholders are allowed!
643+
644+
* **master_legacy_dns_name_format**
645+
*deprecated* default master DNS template `{cluster}.{team}.{hostedzone}` as
646+
of pre `v1.9.0`. If cluster name starts with `teamId` then a second DNS
647+
entry will be created using the template defined here to provide backwards
648+
compatibility. The `teamId` prefix will be extracted from the clustername
649+
because it follows later in the DNS string. When using a customized
650+
`master_dns_name_format` make sure to define the legacy DNS format when
651+
switching to v1.9.0.
652+
653+
* **replica_dns_name_format**
654+
defines the DNS name string template for the replica load balancer cluster.
655+
The default is `{cluster}-repl.{namespace}.{hostedzone}`, where `{cluster}`
656+
is replaced by the cluster name, `{namespace}` is replaced with the
657+
namespace and `{hostedzone}` is replaced with the hosted zone (the value of
658+
the `db_hosted_zone` parameter). The `{team}` placeholder can still be used,
659+
although it is not recommened because the team of a cluster can change.
660+
If the cluster name starts with the `teamId` it will also be part of the
661+
DNS, aynway. No other placeholders are allowed!
662+
663+
* **replica_legacy_dns_name_format**
664+
*deprecated* default master DNS template `{cluster}-repl.{team}.{hostedzone}`
665+
as of pre `v1.9.0`. If cluster name starts with `teamId` then a second DNS
666+
entry will be created using the template defined here to provide backwards
667+
compatibility. The `teamId` prefix will be extracted from the clustername
668+
because it follows later in the DNS string. When using a customized
669+
`master_dns_name_format` make sure to define the legacy DNS format when
670+
switching to v1.9.0.
646671

647672
## AWS or GCP interaction
648673

manifests/configmap.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ data:
9797
major_version_upgrade_mode: "manual"
9898
# major_version_upgrade_team_allow_list: ""
9999
master_dns_name_format: "{cluster}.{namespace}.{hostedzone}"
100+
# master_legacy_dns_name_format: "{cluster}.{team}.{hostedzone}"
100101
# master_pod_move_timeout: 20m
101102
# max_instances: "-1"
102103
# min_instances: "-1"
@@ -135,6 +136,7 @@ data:
135136
ready_wait_timeout: 30s
136137
repair_period: 5m
137138
replica_dns_name_format: "{cluster}-repl.{namespace}.{hostedzone}"
139+
# replica_legacy_dns_name_format: "{cluster}-repl.{team}.{hostedzone}"
138140
replication_username: standby
139141
resource_check_interval: 3s
140142
resource_check_timeout: 10m

manifests/operatorconfiguration.crd.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,15 @@ spec:
432432
master_dns_name_format:
433433
type: string
434434
default: "{cluster}.{namespace}.{hostedzone}"
435+
master_legacy_dns_name_format:
436+
type: string
437+
default: "{cluster}.{team}.{hostedzone}"
435438
replica_dns_name_format:
436439
type: string
437440
default: "{cluster}-repl.{namespace}.{hostedzone}"
441+
replica_legacy_dns_name_format:
442+
type: string
443+
default: "{cluster}-repl.{team}.{hostedzone}"
438444
aws_or_gcp:
439445
type: object
440446
properties:

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ configuration:
137137
enable_replica_pooler_load_balancer: false
138138
external_traffic_policy: "Cluster"
139139
master_dns_name_format: "{cluster}.{namespace}.{hostedzone}"
140+
# master_legacy_dns_name_format: "{cluster}.{team}.{hostedzone}"
140141
replica_dns_name_format: "{cluster}-repl.{namespace}.{hostedzone}"
142+
# replica_dns_old_name_format: "{cluster}-repl.{team}.{hostedzone}"
141143
aws_or_gcp:
142144
# additional_secret_mount: "some-secret-name"
143145
# additional_secret_mount_path: "/some/dir"

pkg/apis/acid.zalan.do/v1/crds.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,9 +1594,15 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
15941594
"master_dns_name_format": {
15951595
Type: "string",
15961596
},
1597+
"master_legacy_dns_name_format": {
1598+
Type: "string",
1599+
},
15971600
"replica_dns_name_format": {
15981601
Type: "string",
15991602
},
1603+
"replica_legacy_dns_name_format": {
1604+
Type: "string",
1605+
},
16001606
},
16011607
},
16021608
"aws_or_gcp": {

pkg/apis/acid.zalan.do/v1/operator_configuration_type.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ type LoadBalancerConfiguration struct {
137137
EnableReplicaPoolerLoadBalancer bool `json:"enable_replica_pooler_load_balancer,omitempty"`
138138
CustomServiceAnnotations map[string]string `json:"custom_service_annotations,omitempty"`
139139
MasterDNSNameFormat config.StringTemplate `json:"master_dns_name_format,omitempty"`
140+
MasterLegacyDNSNameFormat config.StringTemplate `json:"master_legacy_dns_name_format,omitempty"`
140141
ReplicaDNSNameFormat config.StringTemplate `json:"replica_dns_name_format,omitempty"`
142+
ReplicaLegacyDNSNameFormat config.StringTemplate `json:"replica_legacy_dns_name_format,omitempty"`
141143
ExternalTrafficPolicy string `json:"external_traffic_policy" default:"Cluster"`
142144
}
143145

pkg/cluster/cluster_test.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ func TestServiceAnnotations(t *testing.T) {
549549
operatorAnnotations: make(map[string]string),
550550
serviceAnnotations: make(map[string]string),
551551
expect: map[string]string{
552-
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
552+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg.test.db.example.com,test-stg.acid.db.example.com",
553553
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
554554
},
555555
},
@@ -571,7 +571,7 @@ func TestServiceAnnotations(t *testing.T) {
571571
operatorAnnotations: make(map[string]string),
572572
serviceAnnotations: make(map[string]string),
573573
expect: map[string]string{
574-
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
574+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg.test.db.example.com,test-stg.acid.db.example.com",
575575
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
576576
},
577577
},
@@ -583,7 +583,7 @@ func TestServiceAnnotations(t *testing.T) {
583583
operatorAnnotations: make(map[string]string),
584584
serviceAnnotations: map[string]string{"foo": "bar"},
585585
expect: map[string]string{
586-
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
586+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg.test.db.example.com,test-stg.acid.db.example.com",
587587
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
588588
"foo": "bar",
589589
},
@@ -606,7 +606,7 @@ func TestServiceAnnotations(t *testing.T) {
606606
operatorAnnotations: map[string]string{"foo": "bar"},
607607
serviceAnnotations: make(map[string]string),
608608
expect: map[string]string{
609-
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
609+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg.test.db.example.com,test-stg.acid.db.example.com",
610610
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
611611
"foo": "bar",
612612
},
@@ -621,7 +621,7 @@ func TestServiceAnnotations(t *testing.T) {
621621
},
622622
serviceAnnotations: make(map[string]string),
623623
expect: map[string]string{
624-
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
624+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg.test.db.example.com,test-stg.acid.db.example.com",
625625
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
626626
},
627627
},
@@ -635,7 +635,7 @@ func TestServiceAnnotations(t *testing.T) {
635635
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
636636
},
637637
expect: map[string]string{
638-
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
638+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg.test.db.example.com,test-stg.acid.db.example.com",
639639
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
640640
},
641641
},
@@ -649,7 +649,7 @@ func TestServiceAnnotations(t *testing.T) {
649649
"external-dns.alpha.kubernetes.io/hostname": "wrong.external-dns-name.example.com",
650650
},
651651
expect: map[string]string{
652-
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
652+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg.test.db.example.com,test-stg.acid.db.example.com",
653653
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
654654
},
655655
},
@@ -661,7 +661,7 @@ func TestServiceAnnotations(t *testing.T) {
661661
serviceAnnotations: make(map[string]string),
662662
operatorAnnotations: make(map[string]string),
663663
expect: map[string]string{
664-
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
664+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg.test.db.example.com,test-stg.acid.db.example.com",
665665
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
666666
},
667667
},
@@ -679,7 +679,7 @@ func TestServiceAnnotations(t *testing.T) {
679679
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "2000",
680680
},
681681
expect: map[string]string{
682-
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
682+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg.test.db.example.com,test-stg.acid.db.example.com",
683683
"service.beta.kubernetes.io/aws-load-balancer-nlb-target-type": "ip",
684684
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "2000",
685685
},
@@ -704,7 +704,7 @@ func TestServiceAnnotations(t *testing.T) {
704704
operatorAnnotations: make(map[string]string),
705705
serviceAnnotations: make(map[string]string),
706706
expect: map[string]string{
707-
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
707+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg-repl.test.db.example.com,test-stg-repl.acid.db.example.com",
708708
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
709709
},
710710
},
@@ -726,7 +726,7 @@ func TestServiceAnnotations(t *testing.T) {
726726
operatorAnnotations: make(map[string]string),
727727
serviceAnnotations: make(map[string]string),
728728
expect: map[string]string{
729-
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
729+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg-repl.test.db.example.com,test-stg-repl.acid.db.example.com",
730730
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
731731
},
732732
},
@@ -738,7 +738,7 @@ func TestServiceAnnotations(t *testing.T) {
738738
operatorAnnotations: make(map[string]string),
739739
serviceAnnotations: map[string]string{"foo": "bar"},
740740
expect: map[string]string{
741-
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
741+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg-repl.test.db.example.com,test-stg-repl.acid.db.example.com",
742742
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
743743
"foo": "bar",
744744
},
@@ -761,7 +761,7 @@ func TestServiceAnnotations(t *testing.T) {
761761
operatorAnnotations: map[string]string{"foo": "bar"},
762762
serviceAnnotations: make(map[string]string),
763763
expect: map[string]string{
764-
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
764+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg-repl.test.db.example.com,test-stg-repl.acid.db.example.com",
765765
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
766766
"foo": "bar",
767767
},
@@ -776,7 +776,7 @@ func TestServiceAnnotations(t *testing.T) {
776776
},
777777
serviceAnnotations: make(map[string]string),
778778
expect: map[string]string{
779-
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
779+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg-repl.test.db.example.com,test-stg-repl.acid.db.example.com",
780780
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
781781
},
782782
},
@@ -790,7 +790,7 @@ func TestServiceAnnotations(t *testing.T) {
790790
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
791791
},
792792
expect: map[string]string{
793-
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
793+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg-repl.test.db.example.com,test-stg-repl.acid.db.example.com",
794794
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
795795
},
796796
},
@@ -804,7 +804,7 @@ func TestServiceAnnotations(t *testing.T) {
804804
"external-dns.alpha.kubernetes.io/hostname": "wrong.external-dns-name.example.com",
805805
},
806806
expect: map[string]string{
807-
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
807+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg-repl.test.db.example.com,test-stg-repl.acid.db.example.com",
808808
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
809809
},
810810
},
@@ -816,7 +816,7 @@ func TestServiceAnnotations(t *testing.T) {
816816
serviceAnnotations: make(map[string]string),
817817
operatorAnnotations: make(map[string]string),
818818
expect: map[string]string{
819-
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
819+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg-repl.test.db.example.com,test-stg-repl.acid.db.example.com",
820820
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
821821
},
822822
},
@@ -834,7 +834,7 @@ func TestServiceAnnotations(t *testing.T) {
834834
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "2000",
835835
},
836836
expect: map[string]string{
837-
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
837+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-stg-repl.test.db.example.com,test-stg-repl.acid.db.example.com",
838838
"service.beta.kubernetes.io/aws-load-balancer-nlb-target-type": "ip",
839839
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "2000",
840840
},
@@ -867,8 +867,10 @@ func TestServiceAnnotations(t *testing.T) {
867867
cl.OpConfig.CustomServiceAnnotations = tt.operatorAnnotations
868868
cl.OpConfig.EnableMasterLoadBalancer = tt.enableMasterLoadBalancerOC
869869
cl.OpConfig.EnableReplicaLoadBalancer = tt.enableReplicaLoadBalancerOC
870-
cl.OpConfig.MasterDNSNameFormat = "{cluster}.{namespace}.{hostedzone}"
871-
cl.OpConfig.ReplicaDNSNameFormat = "{cluster}-repl.{namespace}.{hostedzone}"
870+
cl.OpConfig.MasterDNSNameFormat = "{cluster}-stg.{namespace}.{hostedzone}"
871+
cl.OpConfig.MasterLegacyDNSNameFormat = "{cluster}-stg.{team}.{hostedzone}"
872+
cl.OpConfig.ReplicaDNSNameFormat = "{cluster}-stg-repl.{namespace}.{hostedzone}"
873+
cl.OpConfig.ReplicaLegacyDNSNameFormat = "{cluster}-stg-repl.{team}.{hostedzone}"
872874
cl.OpConfig.DbHostedZone = "db.example.com"
873875

874876
cl.Postgresql.Spec.ClusterName = ""

0 commit comments

Comments
 (0)