From c23f5f4823d791c1585225f9dccdd5fc3805582b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Thu, 11 Apr 2024 16:03:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91=E4=BF=AE=E5=BE=A9Device-plugi?= =?UTF-8?q?n=E5=BC=80=E5=90=AFhostnetwork=E6=97=B6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E7=8E=AF=E5=A2=83=E4=B8=8A=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E4=BA=86docker-runtime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/main.go | 8 +++----- runtime/main_test.go | 6 ++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/runtime/main.go b/runtime/main.go index 8d5fedd..6594c6e 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 c540f8b..bda5d07 100644 --- a/runtime/main_test.go +++ b/runtime/main_test.go @@ -266,12 +266,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}, }, } -- Gitee From 96d6a00ed7ce9ffb366b04c42d53d16c2d49bc9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Thu, 11 Apr 2024 16:42:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=20Modification=E3=80=91=E4=BF=AE=E5=A4=8Dcodecheck?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/main_test.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/runtime/main_test.go b/runtime/main_test.go index bda5d07..fe48448 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("进入测试用例") @@ -278,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}, }, } @@ -364,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{}, } @@ -499,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}, }, } -- Gitee