Skip to content

Commit

Permalink
[Refactor] rename some name in pkg/k8sutils/templates/pod/spec.go (#272)
Browse files Browse the repository at this point in the history
Signed-off-by: yandongxiao <[email protected]>
  • Loading branch information
yandongxiao authored Sep 25, 2023
1 parent 5378b53 commit 5b13cf2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
11 changes: 5 additions & 6 deletions pkg/k8sutils/templates/pod/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,15 @@ func Envs(spec v1.SpecInterface, config map[string]interface{}, feExternalServic
keys[env.Name] = true
}

unsupport_envs := make(map[string]bool)
if unsupport_envs_str := os.Getenv("KUBE_STARROCKS_UNSUPPORTED_ENVS"); unsupport_envs_str != "" {
unsupport_envs_slice := strings.Split(unsupport_envs_str, ",")
for _, name := range unsupport_envs_slice {
unsupport_envs[name] = true
unsupportedEnvironments := make(map[string]bool)
if unsupportedEnvs := os.Getenv("KUBE_STARROCKS_UNSUPPORTED_ENVS"); unsupportedEnvs != "" {
for _, name := range strings.Split(unsupportedEnvs, ",") {
unsupportedEnvironments[name] = true
}
}

addEnv := func(envVar corev1.EnvVar) {
if !keys[envVar.Name] && !unsupport_envs[envVar.Name] {
if !keys[envVar.Name] && !unsupportedEnvironments[envVar.Name] {
keys[envVar.Name] = true
envs = append(envs, envVar)
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/k8sutils/templates/pod/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func TestLabels(t *testing.T) {
}

func TestEnvs(t *testing.T) {
envs_without_ip := []corev1.EnvVar{
envsWithoutIP := []corev1.EnvVar{
{
Name: "POD_NAME",
ValueFrom: &corev1.EnvVarSource{
Expand Down Expand Up @@ -550,10 +550,10 @@ func TestEnvs(t *testing.T) {
config map[string]interface{}
}
tests := []struct {
name string
args args
want []corev1.EnvVar
unsupport_envs string
name string
args args
want []corev1.EnvVar
unsupportedEnvs string
}{
{
name: "test envs for fe",
Expand All @@ -572,7 +572,7 @@ func TestEnvs(t *testing.T) {
Value: service.ExternalServiceName("test", &v1.StarRocksFeSpec{}) + "." + "ns",
},
}...),
unsupport_envs: "",
unsupportedEnvs: "",
},
{
name: "test envs for be",
Expand All @@ -595,7 +595,7 @@ func TestEnvs(t *testing.T) {
Value: fmt.Sprintf("%v", rutils.DefMap[rutils.QUERY_PORT]),
},
}...),
unsupport_envs: "",
unsupportedEnvs: "",
},
{
name: "test envs for cn",
Expand All @@ -618,7 +618,7 @@ func TestEnvs(t *testing.T) {
Value: fmt.Sprintf("%v", rutils.DefMap[rutils.QUERY_PORT]),
},
}...),
unsupport_envs: "",
unsupportedEnvs: "",
},
{
name: "test envs for be with unsupport envs",
Expand All @@ -627,7 +627,7 @@ func TestEnvs(t *testing.T) {
namespace: "ns",
spec: &v1.StarRocksBeSpec{},
},
want: append(append([]corev1.EnvVar(nil), envs_without_ip...), []corev1.EnvVar{
want: append(append([]corev1.EnvVar(nil), envsWithoutIP...), []corev1.EnvVar{
{
Name: v1.COMPONENT_NAME,
Value: v1.DEFAULT_BE,
Expand All @@ -641,13 +641,13 @@ func TestEnvs(t *testing.T) {
Value: fmt.Sprintf("%v", rutils.DefMap[rutils.QUERY_PORT]),
},
}...),
unsupport_envs: "HOST_IP,POD_IP",
unsupportedEnvs: "HOST_IP,POD_IP",
},
}
for _, tt := range tests {
feExternalServiceName := service.ExternalServiceName("test", &v1.StarRocksFeSpec{})
t.Run(tt.name, func(t *testing.T) {
os.Setenv("KUBE_STARROCKS_UNSUPPORTED_ENVS", tt.unsupport_envs)
os.Setenv("KUBE_STARROCKS_UNSUPPORTED_ENVS", tt.unsupportedEnvs)
defer func() {
os.Setenv("KUBE_STARROCKS_UNSUPPORTED_ENVS", "")
}()
Expand Down

0 comments on commit 5b13cf2

Please sign in to comment.