Fix the new base image to support helm cli ssh login 44/9944/1
authorZhang Rong(Jon) <rong.zhang@windriver.com>
Thu, 1 Dec 2022 09:52:19 +0000 (17:52 +0800)
committerJackie Huang <jackie.huang@windriver.com>
Mon, 5 Dec 2022 04:47:24 +0000 (12:47 +0800)
Signed-off-by: Zhang Rong(Jon) <rong.zhang@windriver.com>
Change-Id: Iafe4120bd5ef05210930f78144754a5da17ed633

.gitignore
charts/resources/scripts/init/o2_helmcli_start.sh
charts/templates/deployment.yaml
docker-compose.yml
o2common/config/config.py
o2ims/views/ocloud_view.py
tests/o2app-helmcli-entry.sh

index 5f213db..6f039b3 100644 (file)
@@ -14,3 +14,4 @@ configs/kubeconfig_*.config
 *.crt
 *.csr
 *.key
+share
index 135882d..c0bd9de 100644 (file)
 
 #!/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
index d912a06..a5deaf6 100644 (file)
@@ -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
index eae9a94..a3bf256 100644 (file)
@@ -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
index e36c889..2e47414 100644 (file)
@@ -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
index d062ada..15a6e1d 100644 (file)
@@ -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):
index e00a00b..fc0b3c3 100644 (file)
@@ -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