Skip to content

Commit

Permalink
Use the full svc cluster domain in alluxio config (fluid-cloudnative#…
Browse files Browse the repository at this point in the history
…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
abowloflrf authored Oct 18, 2022
1 parent b951c31 commit 338d66f
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/alluxio/templates/config/alluxio-conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{{- $alluxioJavaOpts := list }}
{{- /* Specify master hostname if single master */}}
{{- if $isSingleMaster }}
{{- $alluxioJavaOpts = printf "-Dalluxio.master.hostname=%v-%v" $fullName $defaultMasterName | append $alluxioJavaOpts }}
{{- $alluxioJavaOpts = printf "-Dalluxio.master.hostname=%v-%v.%v.svc.%v" $fullName $defaultMasterName .Values.runtimeIdentity.namespace .Values.clusterDomain | append $alluxioJavaOpts }}
{{- end }}
{{ if .Values.fuse.enabled -}}
{{- $alluxioJavaOpts = print "-Dalluxio.user.hostname=${ALLUXIO_CLIENT_HOSTNAME}" | append $alluxioJavaOpts }}
Expand Down
1 change: 1 addition & 0 deletions charts/alluxio/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,4 @@ runtimeIdentity:
namespace: default
name: xxx

clusterDomain: cluster.local
33 changes: 33 additions & 0 deletions pkg/common/cluster_domain.go
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")
}
72 changes: 72 additions & 0 deletions pkg/common/cluster_domain_test.go
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)
}
})
}
}
17 changes: 16 additions & 1 deletion pkg/ddc/alluxio/master_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/brahma-adshonor/gohook"
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/common"
"github.com/fluid-cloudnative/fluid/pkg/ddc/base/portallocator"
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
"github.com/fluid-cloudnative/fluid/pkg/utils/helm"
Expand Down Expand Up @@ -54,6 +55,9 @@ func TestSetupMasterInternal(t *testing.T) {
mockExecInstallReleaseErr := func(name string, namespace string, valueFile string, chartName string) error {
return errors.New("fail to install dataload chart")
}
mockGetClusterDomain := func() (string, error) {
return "cluster.local", nil
}

wrappedUnhookCreateConfigMapFromFile := func() {
err := gohook.UnHook(kubectl.CreateConfigMapFromFile)
Expand Down Expand Up @@ -134,6 +138,10 @@ func TestSetupMasterInternal(t *testing.T) {
if err != nil {
t.Fatal(err.Error())
}
err = gohook.Hook(common.GetClusterDomain, mockGetClusterDomain, nil)
if err != nil {
t.Fatal(err.Error())
}
err = engine.setupMasterInternal()
if err != nil {
t.Errorf("fail to exec check helm release")
Expand Down Expand Up @@ -190,6 +198,9 @@ func TestGenerateAlluxioValueFile(t *testing.T) {
mockExecCreateConfigMapFromFileErr := func(name string, key, fileName string, namespace string) (err error) {
return errors.New("fail to exec command")
}
mockGetClusterDomain := func() (string, error) {
return "cluster.local", nil
}

wrappedUnhookCreateConfigMapFromFile := func() {
err := gohook.UnHook(kubectl.CreateConfigMapFromFile)
Expand Down Expand Up @@ -253,9 +264,13 @@ func TestGenerateAlluxioValueFile(t *testing.T) {
if err != nil {
t.Fatal(err.Error())
}
err = gohook.Hook(common.GetClusterDomain, mockGetClusterDomain, nil)
if err != nil {
t.Fatal(err.Error())
}
_, err = engine.generateAlluxioValueFile(allixioruntime)
if err != nil {
t.Errorf("fail to exec the function")
t.Errorf("fail to generateAlluxioValueFile %v", err)
}
wrappedUnhookCreateConfigMapFromFile()
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/ddc/alluxio/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ func (e *AlluxioEngine) transformCommonPart(runtime *datav1alpha1.AlluxioRuntime

e.transformShortCircuit(runtimeInfo, value)

clusterDomain, err := common.GetClusterDomain()
if err != nil {
return err
}
value.ClusterDomain = clusterDomain

return
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/ddc/alluxio/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type Alluxio struct {
PlacementMode string `json:"placement,omitempty"`

RuntimeIdentity common.RuntimeIdentity `json:"runtimeIdentity"`

ClusterDomain string `json:"clusterDomain,omitempty"`
}

type HadoopConfig struct {
Expand Down

0 comments on commit 338d66f

Please sign in to comment.