use old LB DNS format when teamId prefix is disabled (#2011)

* use old LB DNS format when teamId prefix is disabled
* support both old and new format in external-dns
* switch dns template from team to namespace
This commit is contained in:
Felix Kunde
2022-08-25 18:29:54 +02:00
committed by GitHub
parent 21d00e2ed7
commit 89375186b3
12 changed files with 113 additions and 54 deletions
+32 -2
View File
@@ -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)
}