From 34ab0092af08c17fd8f0f5700ee315d524516725 Mon Sep 17 00:00:00 2001 From: BianTanggui Date: Mon, 9 Jan 2023 21:05:30 +0800 Subject: [PATCH 1/2] Match-id-85d28edeface7978c7aa5ca4cedd283b38de5246 --- build/scripts/help.info | 3 ++- build/scripts/run_main.sh | 18 +++++++++++++++++- build/scripts/uninstall.sh | 9 ++++++++- runtime/main.go | 7 +++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/build/scripts/help.info b/build/scripts/help.info index 31fe6e0..97e5e23 100644 --- a/build/scripts/help.info +++ b/build/scripts/help.info @@ -2,4 +2,5 @@ --install-path Specify the installation path (default: /usr/local/Ascend/Ascend-Docker-Runtime) --uninstall Uninstall the installed ascend-docker-runtime tool --upgrade Upgrade the installed ascend-docker-runtime tool - --install-type= Only A500, A200ISoC and A200 need to specify the installation type of Ascend-docker-runtime (eg: --install-type=A500) \ No newline at end of file + --install-type= Only A500, A200ISoC and A200 need to specify the installation type of Ascend-docker-runtime (eg: --install-type=A500) + --ce= Only iSula need to specify the container engine(eg: --ce=isula) \ No newline at end of file diff --git a/build/scripts/run_main.sh b/build/scripts/run_main.sh index 1e6ea5f..062272b 100644 --- a/build/scripts/run_main.sh +++ b/build/scripts/run_main.sh @@ -123,7 +123,7 @@ function uninstall() exit 0 fi - ${INSTALL_PATH}/script/uninstall.sh + ${INSTALL_PATH}/script/uninstall.sh ${ISULA} echo 'remove daemon.json setting success' [ -n "${INSTALL_PATH}" ] && rm -rf ${INSTALL_PATH} @@ -191,6 +191,7 @@ a500=n a200=n a200isoc=n quiet_flag=n +ISULA=n while true do @@ -236,6 +237,21 @@ do UPGRADE_FLAG=y shift ;; + --ce=*) + if [ "${ISULA}" == "y" ]; then + echo "warning: Repeat parameter!" + exit 1 + fi + + if [ "$3" == "--ce=isula" ]; then + DOCKER_CONFIG_DIR="/etc/isulad" + ISULA=y + else + echo "ERROR :Please check the parameter of --ce=" + exit 1 + fi + shift + ;; --install-type=*) if [ "${a500}" == "y" ] || [ "${a200}" == "y" ] || [ "${a200isoc}" == "y" ]; then echo "warning :Repeat parameter!" diff --git a/build/scripts/uninstall.sh b/build/scripts/uninstall.sh index 4c320d5..c32723f 100644 --- a/build/scripts/uninstall.sh +++ b/build/scripts/uninstall.sh @@ -20,7 +20,14 @@ LOG_FILE="/var/log/ascend_seclog/ascend_toolbox_install.log" echo "Ascend-Docker-Runtime" $(date +%Y%m%d-%H:%M:%S) "start uninstall" echo "Ascend-Docker-Runtime" $(date +%Y%m%d-%H:%M:%S) "start uninstall" >>${LOG_FILE} ROOT=$(cd $(dirname $0); pwd)/.. -DST='/etc/docker/daemon.json' +if [ "$*" == "y" ] ; then + DST='/etc/isulad/daemon.json' + echo "[INFO]: You will recover iSula's daemon" +else + DST='/etc/docker/daemon.json' + echo "[INFO]: You will recover Docker's daemon" +fi + SRC="${DST}.${PPID}" ASCEND_RUNTIME_CONFIG_DIR=/etc/ascend-docker-runtime.d diff --git a/runtime/main.go b/runtime/main.go index d173a67..e78bc19 100644 --- a/runtime/main.go +++ b/runtime/main.go @@ -249,6 +249,13 @@ func modifySpecFile(path string) error { return fmt.Errorf("failed to read oci spec file %s: %v", path, err) } + if err = jsonFile.Truncate(0); err != nil { + return fmt.Errorf("failed to truncate: %v", err) + } + if _, err = jsonFile.Seek(0, 0); err != nil { + return fmt.Errorf("failed to seek: %v", err) + } + var spec specs.Spec if err = json.Unmarshal(jsonContent, &spec); err != nil { return fmt.Errorf("failed to unmarshal oci spec file %s: %v", path, err) -- Gitee From abc486665348cef8af044026a949e60ba3f62e7f Mon Sep 17 00:00:00 2001 From: BianTanggui Date: Sat, 11 Feb 2023 15:37:31 +0800 Subject: [PATCH 2/2] Match-id-d63746a2593d23d7ab3b338e979ef38cb1963697 --- runtime/main.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/runtime/main.go b/runtime/main.go index df1f5f9..76671fe 100644 --- a/runtime/main.go +++ b/runtime/main.go @@ -46,6 +46,10 @@ const ( dockerRuncFile = "docker-runc" runcFile = "runc" envLength = 2 + + // ENV for device-plugin to identify ascend-docker-runtime + useAscendDocker = "ASCEND_DOCKER_RUNTIME=True" + devicePlugin = "ascend-device-plugin" ) var ( @@ -134,6 +138,21 @@ var execRunc = func() error { return nil } +func addEnvToDevicePlugin(spec *specs.Spec) { + if 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 + } + } +} + func addHook(spec *specs.Spec) error { currentExecPath, err := os.Executable() if err != nil { @@ -258,6 +277,8 @@ func modifySpecFile(path string) error { return fmt.Errorf("failed to inject hook: %v", err) } + addEnvToDevicePlugin(&spec) + jsonOutput, err := json.Marshal(spec) if err != nil { return fmt.Errorf("failed to marshal OCI spec file: %v", err) -- Gitee