forked from fluid-cloudnative/fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the full svc cluster domain in alluxio config (fluid-cloudnative#…
…2191) * use the full svc cluster domain in alluxio config Signed-off-by: Ruofeng Lei <ruofenglei@outlook.com> * fix ut Signed-off-by: Ruofeng Lei <ruofenglei@outlook.com> * add newline end of file Signed-off-by: Ruofeng Lei <ruofenglei@outlook.com> Signed-off-by: Ruofeng Lei <ruofenglei@outlook.com>
- Loading branch information
1 parent
b951c31
commit 338d66f
Showing
7 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -443,3 +443,4 @@ runtimeIdentity: | |
namespace: default | ||
name: xxx | ||
|
||
clusterDomain: cluster.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package common | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// GetClusterDomain get cluster domain: cluster.local from /etc/resolv.conf | ||
func GetClusterDomain() (string, error) { | ||
resolveConf, err := os.ReadFile("/etc/resolv.conf") | ||
if err != nil { | ||
return "", err | ||
} | ||
return parseResolvConf(string(resolveConf)) | ||
} | ||
|
||
// parseResolvConf parse cluster domain from /etc/resolv.conf | ||
// search default.svc.cluster.local svc.cluster.local cluster.local | ||
// for how k8s generate `resolv.conf`, ref: | ||
// https://github.com/kubernetes/kubernetes/blob/542ec977054c16c7981606cb1590cc39154ddf01/pkg/kubelet/network/dns/dns.go#L167 | ||
func parseResolvConf(conf string) (string, error) { | ||
for _, line := range strings.Split(conf, "\n") { | ||
line := strings.TrimSpace(line) | ||
if strings.HasPrefix(line, "search") { | ||
search := strings.Split(line, " ") | ||
if len(search) >= 4 { | ||
return search[3], nil | ||
} | ||
} | ||
} | ||
return "", errors.New("failed to parse cluster domain from resolv.conf") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package common | ||
|
||
import "testing" | ||
|
||
func Test_parseResolvConf(t *testing.T) { | ||
type args struct { | ||
conf string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
args: args{ | ||
conf: `nameserver 10.255.0.10 | ||
search default.svc.cluster.local svc.cluster.local cluster.local | ||
options ndots:5`, | ||
}, | ||
want: "cluster.local", | ||
wantErr: false, | ||
}, | ||
{ | ||
args: args{ | ||
conf: `nameserver 10.255.0.10 | ||
search default.svc.cluster.local svc.cluster.local cluster.local foo.bar | ||
options ndots:5`, | ||
}, | ||
want: "cluster.local", | ||
wantErr: false, | ||
}, | ||
{ | ||
args: args{ | ||
conf: `nameserver 10.255.0.10 | ||
search default.svc.clusterxx.local svc.clusterxx.local clusterxx.local | ||
options ndots:5`, | ||
}, | ||
want: "clusterxx.local", | ||
wantErr: false, | ||
}, | ||
{ | ||
args: args{ | ||
conf: `nameserver 10.255.0.10 | ||
options ndots:5`, | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
{ | ||
args: args{ | ||
conf: `nameserver 10.255.0.10 | ||
search a | ||
options ndots:5`, | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := parseResolvConf(tt.args.conf) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("parseResolvConf() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("parseResolvConf() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters