diff --git a/runtime/main.go b/runtime/main.go index 8d5fedd2c47fdb28dc85c7fb885bdacf3867c36b..6594c6e4b761ceb4ba41d6ecbdc8bddae04e1d50 100644 --- a/runtime/main.go +++ b/runtime/main.go @@ -54,7 +54,7 @@ const ( // ENV for device-plugin to identify ascend-docker-runtime useAscendDocker = "ASCEND_DOCKER_RUNTIME=True" - devicePlugin = "ascend-device-plugin" + devicePlugin = "device-plugin" ascendVisibleDevices = "ASCEND_VISIBLE_DEVICES" ascendRuntimeOptions = "ASCEND_RUNTIME_OPTIONS" ) @@ -195,10 +195,8 @@ func addEnvToDevicePlugin(spec *specs.Spec) { return } - for _, line := range spec.Process.Env { - words := strings.Split(line, "=") - if len(words) == envLength && strings.TrimSpace(words[0]) == "HOSTNAME" && - strings.Contains(words[1], devicePlugin) { + for _, arg := range spec.Process.Args { + if strings.Contains(arg, devicePlugin) { spec.Process.Env = append(spec.Process.Env, useAscendDocker) break } diff --git a/runtime/main_test.go b/runtime/main_test.go index c540f8b45f61ea1e6ce987fc633783460984b159..fe48448375df52378e1ef01b1be10daa29becb7d 100644 --- a/runtime/main_test.go +++ b/runtime/main_test.go @@ -30,6 +30,13 @@ import ( "main/dcmi" ) +const ( + // strKubeDNSPort53UDPPort represents the string of the environment variable KUBE_DNS_PORT_53_UDP_PORT + strKubeDNSPort53UDPPort = "KUBE_DNS_PORT_53_UDP_PORT=53" + // strKubeDNSPort53UDPProto represents the string of the environment variable KUBE_DNS_PORT_53_UDP_PROTO + strKubeDNSPort53UDPProto = "KUBE_DNS_PORT_53_UDP_PROTO=udp" +) + func TestArgsIsCreate(t *testing.T) { t.Log("进入测试用例") @@ -266,12 +273,10 @@ func TestRemoveDuplication(t *testing.T) { } func TestAddEnvToDevicePlugin0(t *testing.T) { - devicePluginHostName := devicePlugin + "pf2i6r" + devicePluginArg := devicePlugin + "pf2i6r" spec := specs.Spec{ Process: &specs.Process{ - Env: []string{"KUBE_DNS_PORT_53_UDP_PORT=53", - fmt.Sprintf("HOSTNAME=%s", devicePluginHostName), - "KUBE_DNS_PORT_53_UDP_PROTO=udp"}, + Args: []string{"-c", "--", devicePluginArg}, }, } @@ -280,12 +285,10 @@ func TestAddEnvToDevicePlugin0(t *testing.T) { } func TestAddEnvToDevicePlugin1(t *testing.T) { - devicePluginHostName := "pf2i6r" + devicePluginArg := "pf2i6r" spec := specs.Spec{ Process: &specs.Process{ - Env: []string{"KUBE_DNS_PORT_53_UDP_PORT=53", - fmt.Sprintf("HOSTNAME=%s", devicePluginHostName), - "KUBE_DNS_PORT_53_UDP_PROTO=udp"}, + Args: []string{"-c", "--", devicePluginArg}, }, } @@ -366,9 +369,9 @@ func TestUpdateEnvAndPostHook(t *testing.T) { spec := specs.Spec{ Process: &specs.Process{ - Env: []string{"KUBE_DNS_PORT_53_UDP_PORT=53", + Env: []string{strKubeDNSPort53UDPPort, fmt.Sprintf("%s=0", ascendVisibleDevices), - "KUBE_DNS_PORT_53_UDP_PROTO=udp"}, + strKubeDNSPort53UDPProto}, }, Hooks: &specs.Hooks{}, } @@ -501,10 +504,10 @@ func TestAddDevice(t *testing.T) { }, }, Process: &specs.Process{ - Env: []string{"KUBE_DNS_PORT_53_UDP_PORT=53", + Env: []string{strKubeDNSPort53UDPPort, "ASCEND_VISIBLE_DEVICES=1", "ASCEND_RUNTIME_OPTIONS=", - "KUBE_DNS_PORT_53_UDP_PROTO=udp"}, + strKubeDNSPort53UDPProto}, }, }