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
This commit is contained in:
Felix Kunde
2023-01-17 10:06:11 +01:00
committed by GitHub
parent ce1fee8586
commit 28cd2f188a
12 changed files with 110 additions and 42 deletions
+18 -9
View File
@@ -506,7 +506,7 @@ func (c *Cluster) roleLabelsSet(shouldAddExtraLabels bool, role PostgresRole) la
}
func (c *Cluster) dnsName(role PostgresRole) string {
var dnsString string
var dnsString, oldDnsString string
if role == Master {
dnsString = c.masterDNSName()
@@ -517,10 +517,12 @@ func (c *Cluster) dnsName(role PostgresRole) string {
// if cluster name starts with teamID we might need to provide backwards compatibility
clusterNameWithoutTeamPrefix, _ := acidv1.ExtractClusterName(c.Name, c.Spec.TeamID)
if clusterNameWithoutTeamPrefix != "" {
if role == Replica {
clusterNameWithoutTeamPrefix = fmt.Sprintf("%s-repl", clusterNameWithoutTeamPrefix)
if role == Master {
oldDnsString = c.oldMasterDNSName(clusterNameWithoutTeamPrefix)
} else {
oldDnsString = c.oldReplicaDNSName(clusterNameWithoutTeamPrefix)
}
dnsString = fmt.Sprintf("%s,%s", dnsString, c.oldDNSFormat(clusterNameWithoutTeamPrefix))
dnsString = fmt.Sprintf("%s,%s", dnsString, oldDnsString)
}
return dnsString
@@ -542,11 +544,18 @@ func (c *Cluster) replicaDNSName() string {
"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) oldMasterDNSName(clusterName string) string {
return strings.ToLower(c.OpConfig.MasterLegacyDNSNameFormat.Format(
"cluster", clusterName,
"team", c.teamName(),
"hostedzone", c.OpConfig.DbHostedZone))
}
func (c *Cluster) oldReplicaDNSName(clusterName string) string {
return strings.ToLower(c.OpConfig.ReplicaLegacyDNSNameFormat.Format(
"cluster", clusterName,
"team", c.teamName(),
"hostedzone", c.OpConfig.DbHostedZone))
}
func (c *Cluster) credentialSecretName(username string) string {