From ef929d2493f22367b2d514342a12b1686bda4413 Mon Sep 17 00:00:00 2001 From: "Zhang Rong(Jon)" Date: Thu, 1 Dec 2022 17:52:19 +0800 Subject: [PATCH] Fix the new base image to support helm cli ssh login Signed-off-by: Zhang Rong(Jon) Change-Id: Iafe4120bd5ef05210930f78144754a5da17ed633 --- .gitignore | 1 + charts/resources/scripts/init/o2_helmcli_start.sh | 11 ++++---- charts/templates/deployment.yaml | 14 +++++++--- docker-compose.yml | 33 ++++++++++++----------- o2common/config/config.py | 24 ++++++++++------- o2ims/views/ocloud_view.py | 10 ++++--- tests/o2app-helmcli-entry.sh | 13 +++++---- 7 files changed, 59 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 5f213db..6f039b3 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ configs/kubeconfig_*.config *.crt *.csr *.key +share diff --git a/charts/resources/scripts/init/o2_helmcli_start.sh b/charts/resources/scripts/init/o2_helmcli_start.sh index 135882d..c0bd9de 100644 --- a/charts/resources/scripts/init/o2_helmcli_start.sh +++ b/charts/resources/scripts/init/o2_helmcli_start.sh @@ -14,18 +14,17 @@ #!/bin/bash -apt-get update && apt-get install ssh -y +apk add --no-cache openssh if [ -z "${HELM_USER_PASSWD}" ]; then HELM_USER_PASSWD=St8rlingX* fi -useradd helm -passwd helm << EOF + +adduser helm << EOF ${HELM_USER_PASSWD} ${HELM_USER_PASSWD} EOF -service ssh restart - -tail -f /dev/null \ No newline at end of file +ssh-keygen -A +exec /usr/sbin/sshd -D -e "$@" \ No newline at end of file diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml index d912a06..a5deaf6 100644 --- a/charts/templates/deployment.yaml +++ b/charts/templates/deployment.yaml @@ -156,8 +156,10 @@ spec: volumeMounts: - name: scripts mountPath: /opt - # - name: configs - # mountPath: /configs + {{- if .Values.o2dms.helm_cli_enable }} + - name: share + mountPath: /share + {{- end }} - name: applicationconfig mountPath: /configs/o2app.conf subPath: config.json @@ -184,13 +186,17 @@ spec: volumeMounts: - name: scripts mountPath: /opt + - name: share + mountPath: /share {{- end }} volumes: - name: scripts configMap: name: {{ .Chart.Name }}-scripts-configmap - # - name: configs - # emptyDir: {} + {{- if .Values.o2dms.helm_cli_enable }} + - name: share + emptyDir: {} + {{- end }} - configMap: name: {{ .Chart.Name }}-application-config name: applicationconfig diff --git a/docker-compose.yml b/docker-compose.yml index eae9a94..a3bf256 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,22 +32,22 @@ services: - /bin/sh - /tests/o2app-redis-entry.sh - helm_cli: - image: o2imsdms - depends_on: - - watcher - environment: - - LOGGING_CONFIG_LEVEL=DEBUG - - HELM_USER_PASSWD=St8rlingX* - volumes: - - ./configs:/configs - - ./helm_sdk:/helm_sdk - - ./tests:/tests - entrypoint: - - /bin/sh - - /tests/o2app-helmcli-entry.sh - ports: - - "10022:22" + # helm_cli: + # image: o2imsdms + # depends_on: + # - watcher + # environment: + # - LOGGING_CONFIG_LEVEL=DEBUG + # - HELM_USER_PASSWD=St8rlingX* + # volumes: + # - ./share:/share + # - ./helm_sdk:/helm_sdk + # - ./tests:/tests + # entrypoint: + # - /bin/sh + # - /tests/o2app-helmcli-entry.sh + # ports: + # - "10022:22" api: image: o2imsdms @@ -69,6 +69,7 @@ services: - HELM_USER_PASSWD=St8rlingX* volumes: - ./configs:/configs + - ./share:/share - ./o2ims:/o2ims - ./o2dms:/o2dms - ./o2common:/o2common diff --git a/o2common/config/config.py b/o2common/config/config.py index e36c889..2e47414 100644 --- a/o2common/config/config.py +++ b/o2common/config/config.py @@ -257,6 +257,10 @@ def get_helm_cli(): return '/usr/local/bin/helm' +def get_containers_shared_folder(): + return '/share' + + def get_system_controller_as_respool(): return True @@ -374,13 +378,13 @@ def get_auth_provider(): def get_dms_support_profiles(): - profiles = config.conf.API.DMS_SUPPORT_PROFILES - if profiles is None or profiles == '': - profiles = [] - elif "[" in profiles and "]" in profiles: - profiles = profiles.replace("'", "").replace( - '"', "").replace('[', "").replace(']', "") - profiles = profiles.split(',') - if 'native_k8sapi' not in profiles: - profiles.append('native_k8sapi') - return profiles + profiles_list = [] + profiles_str = config.conf.API.DMS_SUPPORT_PROFILES + if profiles_str: + profiles_strip = profiles_str.strip(' []') + profiles_str = profiles_strip.replace("'", "").replace( + '"', "") + profiles_list = profiles_str.split(',') + if 'native_k8sapi' not in profiles_list: + profiles_list.append('native_k8sapi') + return profiles_list diff --git a/o2ims/views/ocloud_view.py b/o2ims/views/ocloud_view.py index d062ada..15a6e1d 100644 --- a/o2ims/views/ocloud_view.py +++ b/o2ims/views/ocloud_view.py @@ -186,6 +186,7 @@ def deployment_manager_one(deploymentManagerId: str, def _gen_kube_config(dmId: str, kubeconfig: dict) -> dict: + shared_folder = config.get_containers_shared_folder() data = config.gen_k8s_config_dict( kubeconfig.pop('cluster_api_endpoint', None), @@ -204,6 +205,7 @@ def _gen_kube_config(dmId: str, kubeconfig: dict) -> dict: current_time = datetime.now().strftime("%Y%m%d%H%M%S") tmp_file_name = 'kubeconfig_' + name_key + "_" + current_time kube_config_name = 'kubeconfig_' + name_key + '.config' + kube_config_path = f'{shared_folder}/{kube_config_name}' # write down the yaml file of kubectl into tmp folder with open('/tmp/' + tmp_file_name, 'w') as file: @@ -211,12 +213,12 @@ def _gen_kube_config(dmId: str, kubeconfig: dict) -> dict: # generate the kube config file if not exist or update the file if it # changes - if not os.path.exists('/configs/' + kube_config_name) or not \ - filecmp.cmp('/tmp/'+tmp_file_name, '/configs/'+kube_config_name): + if not os.path.exists(kube_config_path) or not \ + filecmp.cmp('/tmp/'+tmp_file_name, kube_config_path): shutil.move(os.path.join('/tmp', tmp_file_name), - os.path.join('/configs', kube_config_name)) + os.path.join(shared_folder, kube_config_name)) - return '/configs/'+kube_config_name + return kube_config_path def subscriptions(uow: unit_of_work.AbstractUnitOfWork, **kwargs): diff --git a/tests/o2app-helmcli-entry.sh b/tests/o2app-helmcli-entry.sh index e00a00b..fc0b3c3 100644 --- a/tests/o2app-helmcli-entry.sh +++ b/tests/o2app-helmcli-entry.sh @@ -1,15 +1,14 @@ -apt-get update && apt-get install ssh -y +apk add --no-cache openssh if [ -z "${HELM_USER_PASSWD}" ]; then - HELM_USER_PASSWD=St8rlingX + HELM_USER_PASSWD=St8rlingX* fi -useradd helm -passwd helm << EOF + +adduser helm << EOF ${HELM_USER_PASSWD} ${HELM_USER_PASSWD} EOF -service ssh restart - -tail -f /dev/null \ No newline at end of file +ssh-keygen -A +exec /usr/sbin/sshd -D -e "$@" \ No newline at end of file -- 2.16.6