Skip to content

Commit

Permalink
tweak the policy of make up fqdn
Browse files Browse the repository at this point in the history
  • Loading branch information
whalecold committed Jan 8, 2024
1 parent b60566b commit 0a0218c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
20 changes: 16 additions & 4 deletions core/manager/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,27 @@ func (bc *BootstrapConfig) tryExpandFQDN(host string) string {
b.Grow(len(host) + len(bc.configNamespace) + len(bc.nodeDomain) + 10)
b.WriteString(host)

// the regex for Kubernetes service is [a-z]([-a-z0-9]*[a-z0-9])?, it should not contains `.` in it
// the regex for Kubernetes service is [a-z]([-a-z0-9]*[a-z0-9])?, it should not contains `.`, so we can split the host
// by `.`
// if the host not contains namespace.
if !strings.Contains(host, ".") {
parts := strings.Split(host, ".")
switch len(parts) {
case 1:
b.WriteString(".")
b.WriteString(bc.configNamespace)
fallthrough
case 2:
b.WriteString(".svc.")
b.WriteString(bc.nodeDomain)
case 3:
if parts[2] == "svc" {
b.WriteString(".")
b.WriteString(bc.nodeDomain)
}
default:
// ignore the other cases
}

b.WriteString(".svc.")
b.WriteString(bc.nodeDomain)
return b.String()
}

Expand Down
9 changes: 9 additions & 0 deletions core/manager/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ func TestTryExpandFQDN(t *testing.T) {
configNamespace: "default",
},
},
{
desc: "error",
host: "servicea.bookinfo.svc",
want: "servicea.bookinfo.svc.cluster.local",
bsc: &BootstrapConfig{
nodeDomain: "cluster.local",
configNamespace: "default",
},
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
Expand Down

0 comments on commit 0a0218c

Please sign in to comment.