Create combined image and add helm chart 97/72997/2
authorYury Kylulin <yury.kylulin@intel.com>
Tue, 2 Nov 2021 14:47:12 +0000 (17:47 +0300)
committerYury Kylulin <yury.kylulin@intel.com>
Tue, 2 Nov 2021 15:01:48 +0000 (18:01 +0300)
Changes in this commit:
1) Create self contained image, rapid scripts can be executed
from the management pod and create other testing pods in the cluster.

2) Helm chart to automate rapid deployment and proper service account
configuration to be able to start management pod.

3) Fix for migration to paramiko.

Signed-off-by: Yury Kylulin <yury.kylulin@intel.com>
Change-Id: I0281871cce392b3003e0274602a5c90c29af9b23

VNFs/DPPD-PROX/helper-scripts/rapid/Dockerfile
VNFs/DPPD-PROX/helper-scripts/rapid/deploycentostools.sh
VNFs/DPPD-PROX/helper-scripts/rapid/dockerimage.sh
VNFs/DPPD-PROX/helper-scripts/rapid/prox_ctrl.py
VNFs/DPPD-PROX/helper-scripts/rapid/rapid.pods
VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/.helmignore [new file with mode: 0644]
VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/Chart.yaml [new file with mode: 0644]
VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/templates/deployment.yaml [new file with mode: 0644]
VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/templates/serviceaccount.yaml [new file with mode: 0644]
VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/values.yaml [new file with mode: 0644]
VNFs/DPPD-PROX/helper-scripts/rapid/rapid_k8s_deployment.py

index a62c5dc..2c25f09 100644 (file)
@@ -48,6 +48,11 @@ EXPOSE 22 8474
 COPY ./rapid_rsa_key.pub /home/centos/.ssh/authorized_keys
 COPY ./rapid_rsa_key.pub /root/.ssh/authorized_keys
 
+RUN chown centos:centos /home/centos/.ssh/authorized_keys \
+ && chmod 600 /home/centos/.ssh/authorized_keys \
+ && chown root:root /root/.ssh/authorized_keys \
+ && chmod 600 /root/.ssh/authorized_keys
+
 # Copy startup script
 COPY ./start.sh /start.sh
 RUN chmod +x /start.sh
index c50d796..a0fe7cb 100644 (file)
@@ -44,7 +44,8 @@ function os_pkgs_install()
                         numactl-devel vim tuna openssl-devel wireshark \
                         make driverctl
 
-       ${SUDO} wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/linux/nasm-2.14.02-0.fc27.x86_64.rpm
+       ${SUDO} wget --no-check-certificate \
+               https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/linux/nasm-2.14.02-0.fc27.x86_64.rpm
        ${SUDO} rpm -ivh nasm-2.14.02-0.fc27.x86_64.rpm
 }
 
@@ -55,6 +56,12 @@ function k8s_os_pkgs_runtime_install()
        # Install required dynamically linked libraries + required packages
        ${SUDO} yum install -y numactl-libs libpcap openssh openssh-server \
                  openssh-clients sudo
+
+       # Install additional packets for universal image
+       ${SUDO} yum install -y epel-release python3 kubernetes-client
+       ${SUDO} yum install -y python3-paramiko python3-future
+       ${SUDO} python3 -m pip install --upgrade pip
+       ${SUDO} pip3 install scp kubernetes
 }
 
 function os_cfg()
index e0f38ad..e2266e5 100755 (executable)
@@ -16,7 +16,7 @@
 ##
 
 PROX_DEPLOY_DIR="."
-PROX_IMAGE_NAME="prox_slim"
+PROX_IMAGE_NAME="rapid"
 RSA_KEY_FILE_NAME="rapid_rsa_key"
 
 DOCKERFILE="Dockerfile"
index fc6749d..c1aade6 100644 (file)
@@ -86,6 +86,7 @@ class prox_ctrl(object):
 
     def run_cmd(self, command):
         self._sshclient.run_cmd(command)
+        return self._sshclient.get_output()
 
     def prox_sock(self, port=8474):
         """Connect to the PROX instance on remote system.
index f568139..cd54d50 100644 (file)
@@ -16,6 +16,7 @@
 
 [DEFAULT]
 total_number_of_pods=2
+namespace=rapid-testing
 
 [POD1]
 nodeSelector_hostname=k8s-node1
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/.helmignore b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/.helmignore
new file mode 100644 (file)
index 0000000..0e8a0eb
--- /dev/null
@@ -0,0 +1,23 @@
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*.orig
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/Chart.yaml b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/Chart.yaml
new file mode 100644 (file)
index 0000000..4d21040
--- /dev/null
@@ -0,0 +1,6 @@
+apiVersion: v2
+name: rapid
+description: A Helm chart for deploying RAPID test scripts and environment
+type: application
+version: 0.0.1
+appVersion: "1.0.0"
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/templates/deployment.yaml b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/templates/deployment.yaml
new file mode 100644 (file)
index 0000000..74fc629
--- /dev/null
@@ -0,0 +1,26 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: rapid-testing
+  namespace: {{ .Values.namespace }}
+  labels:
+    app: rapid-testing
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: rapid-testing
+  template:
+    metadata:
+      labels:
+        app: rapid-testing
+    spec:
+      serviceAccountName: rapid-testing-sa
+      containers:
+      - name: rapid-mgmt
+        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
+        imagePullPolicy: {{ .Values.image.pullPolicy }}
+      {{- with .Values.nodeSelector }}
+      nodeSelector:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/templates/serviceaccount.yaml b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/templates/serviceaccount.yaml
new file mode 100644 (file)
index 0000000..7886ade
--- /dev/null
@@ -0,0 +1,36 @@
+---
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: {{ .Values.namespace }}
+
+---
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: rapid-testing-sa
+  namespace: {{ .Values.namespace }}
+
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRole
+metadata:
+  name: rapid-testing-cr
+rules:
+- apiGroups: [""]
+  resources: ["pods", "pods/exec", "pods/status"]
+  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
+
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  name: rapid-testing-crb
+subjects:
+- kind: ServiceAccount
+  name: rapid-testing-sa
+  namespace: {{ .Values.namespace }}
+roleRef:
+  kind: ClusterRole
+  name: rapid-testing-cr
+  apiGroup: rbac.authorization.k8s.io
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/values.yaml b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_helm_chart/values.yaml
new file mode 100644 (file)
index 0000000..76b8037
--- /dev/null
@@ -0,0 +1,8 @@
+namespace: rapid-testing
+
+image:
+  repository: opnfv/rapid
+  tag: "latest"
+  pullPolicy: IfNotPresent
+
+nodeSelector: {}
index 2d88cd9..bfb8161 100644 (file)
@@ -40,6 +40,7 @@ class K8sDeployment:
     _create_config = None
     _runtime_config = None
     _total_number_of_pods = 0
+    _namespace = "rapid-testing"
     _pods = []
 
     def __init__(self):
@@ -64,7 +65,11 @@ class K8sDeployment:
         self._log.addHandler(console_handler)
 
         # Initialize k8s plugin
-        config.load_kube_config()
+        try:
+            config.load_kube_config()
+        except:
+            config.load_incluster_config()
+
         Pod.k8s_CoreV1Api = client.CoreV1Api()
 
     def load_create_config(self, config_file_name):
@@ -89,6 +94,15 @@ class K8sDeployment:
 
         self._log.debug("Total number of pods %d" % self._total_number_of_pods)
 
+        if self._create_config.has_option("DEFAULT", "namespace"):
+            self._namespace = self._create_config.get(
+                "DEFAULT", "namespace")
+        else:
+            self._log.error("No option namespace in DEFAULT section")
+            return -1
+
+        self._log.debug("Using namespace %s" % self._total_number_of_pods)
+
         # Parse [PODx] sections
         for i in range(1, int(self._total_number_of_pods) + 1):
             # Search for POD name
@@ -123,7 +137,7 @@ class K8sDeployment:
             else:
                 pod_dp_subnet = "24"
 
-            pod = Pod(pod_name)
+            pod = Pod(pod_name, self._namespace)
             pod.set_nodeselector(pod_nodeselector_hostname)
             pod.set_dp_ip(pod_dp_ip)
             pod.set_dp_subnet(pod_dp_subnet)