From 54b14de2903cea70e451a2c8637218d1c096a6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B8=A3=E6=B2=BC?= Date: Wed, 17 Apr 2024 16:34:16 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4=E6=98=8E?= =?UTF-8?q?=20Modification=E3=80=91=E4=BF=AE=E5=A4=8DDevice-plugin?= =?UTF-8?q?=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 | 16 ++++------------ runtime/main_test.go | 6 +++--- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/runtime/main.go b/runtime/main.go index 8d5fedd..96567e9 100644 --- a/runtime/main.go +++ b/runtime/main.go @@ -190,19 +190,11 @@ var execRunc = func() error { return nil } -func addEnvToDevicePlugin(spec *specs.Spec) { - if spec.Process.Env == nil { +func addAscendDockerEnv(spec *specs.Spec) { + if spec == nil || spec.Process == nil || spec.Process.Env == nil { 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) { - spec.Process.Env = append(spec.Process.Env, useAscendDocker) - break - } - } + spec.Process.Env = append(spec.Process.Env, useAscendDocker) } func addHook(spec *specs.Spec) error { @@ -640,7 +632,7 @@ func modifySpecFile(path string) error { } } - addEnvToDevicePlugin(&spec) + addAscendDockerEnv(&spec) jsonOutput, err := json.Marshal(spec) if err != nil { diff --git a/runtime/main_test.go b/runtime/main_test.go index c540f8b..35e0221 100644 --- a/runtime/main_test.go +++ b/runtime/main_test.go @@ -275,7 +275,7 @@ func TestAddEnvToDevicePlugin0(t *testing.T) { }, } - addEnvToDevicePlugin(&spec) + addAscendDockerEnv(&spec) assert.Contains(t, spec.Process.Env, useAscendDocker) } @@ -289,8 +289,8 @@ func TestAddEnvToDevicePlugin1(t *testing.T) { }, } - addEnvToDevicePlugin(&spec) - assert.NotContains(t, spec.Process.Env, useAscendDocker) + addAscendDockerEnv(&spec) + assert.Contains(t, spec.Process.Env, useAscendDocker) } func TestGetDeviceTypeByChipName0(t *testing.T) { -- Gitee