diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2020-09-15 23:18:16 +0200 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2020-09-16 10:31:25 +0200 |
commit | 6a94f3af61529257cea8ec71fe728f28541a9dba (patch) | |
tree | c6670267e9625188fbc84f212e0b05c9852a5c9d | |
parent | aa4a7102926c5b71f9249a770b17ef917b928f71 (diff) |
Publish helm_vims also based on clearwater-docker
It leverages helm rather than kubectl as proposed by k8s_vims.
A new abstract class Vims is added to factorize code between both
testcases.
Change-Id: Ie5de8d62e25e74f73f8e32167228a08e82989abd
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit 32dfc10f56ead9abea8798e1ce16fe87652ca480)
30 files changed, 892 insertions, 48 deletions
diff --git a/ansible/site.yml b/ansible/site.yml index 5db086f8..cb269eb6 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -60,5 +60,6 @@ - xrally_kubernetes_full - container: functest-kubernetes-cnf tests: - - cnf_conformance - k8s_vims + - helm_vims + - cnf_conformance diff --git a/docker/cnf/Dockerfile b/docker/cnf/Dockerfile index 8c95faee..f7a8ef3b 100644 --- a/docker/cnf/Dockerfile +++ b/docker/cnf/Dockerfile @@ -1,17 +1,23 @@ FROM opnfv/functest-kubernetes-core:jerma ARG CNF_CONFORMANCE_TAG=v0.7.2-beta1 +ARG HELM_TAG=v3.3.1 RUN apk --no-cache add --update wget curl libc6-compat && \ K8S_TAG=$(curl -s https://storage.googleapis.com/kubernetes-release/release/latest-1.17.txt) && \ case $(uname -m) in armv7l) ARCH=arm;; aarch64) ARCH=arm64;; x86_64) ARCH=amd64;; esac && \ curl https://storage.googleapis.com/kubernetes-release/release/$K8S_TAG/bin/linux/$ARCH/kubectl \ -s --output /usr/local/bin/kubectl && \ + curl https://get.helm.sh/helm-$HELM_TAG-linux-$ARCH.tar.gz \ + -s --output /src/helm-$HELM_TAG-linux-$ARCH.tar.gz && \ + tar zxf /src/helm-$HELM_TAG-linux-$ARCH.tar.gz linux-$ARCH/helm -C /src && \ + mv /src/linux-$ARCH/helm /usr/local/bin && \ + chmod +x /usr/local/bin/kubectl /usr/local/bin/helm && \ + rm -r /src/helm-$HELM_TAG-linux-$ARCH.tar.gz /src/linux-$ARCH && \ case $(uname -m) in x86_64) \ curl https://github.com/cncf/cnf-conformance/releases/download/$CNF_CONFORMANCE_TAG/cnf-conformance-$(echo $CNF_CONFORMANCE_TAG |cut -d\- -f 1)-$ARCH-static \ -Ls --output /usr/local/bin/cnf-conformance && \ chmod +x /usr/local/bin/cnf-conformance ;; esac && \ - chmod +x /usr/local/bin/kubectl && \ mkdir -p /src/cnf-conformance && \ curl -Ls https://raw.githubusercontent.com/cncf/cnf-conformance/$CNF_CONFORMANCE_TAG/example-cnfs/coredns/cnf-conformance.yml \ -s --output /src/cnf-conformance/cnf-conformance.yml && \ diff --git a/docker/cnf/testcases.yaml b/docker/cnf/testcases.yaml index f122d066..71dce987 100644 --- a/docker/cnf/testcases.yaml +++ b/docker/cnf/testcases.yaml @@ -6,20 +6,20 @@ tiers: Collection of VNF test cases. testcases: - - case_name: cnf_conformance + case_name: k8s_vims project_name: functest - criteria: 75 + criteria: 100 blocking: false description: >- - Enable interoperability of Cloud native Network - Functions (CNFs) as proposed by - https://github.com/cncf/cnf-conformance + Deploy and test Clearwater IMS using Kubernetes as proposed + by https://github.com/Metaswitch/clearwater-docker dependencies: - DEPLOY_SCENARIO: 'k8-*' run: - name: cnf_conformance + name: k8s_vims + - - case_name: k8s_vims + case_name: helm_vims project_name: functest criteria: 100 blocking: false @@ -29,4 +29,18 @@ tiers: dependencies: - DEPLOY_SCENARIO: 'k8-*' run: - name: k8s_vims + name: helm_vims + + - + case_name: cnf_conformance + project_name: functest + criteria: 75 + blocking: false + description: >- + Enable interoperability of Cloud native Network + Functions (CNFs) as proposed by + https://github.com/cncf/cnf-conformance + dependencies: + - DEPLOY_SCENARIO: 'k8-*' + run: + name: cnf_conformance diff --git a/functest_kubernetes/ims/cassandra-depl.yaml b/functest_kubernetes/ims/cassandra-depl.yaml index 7758d9ef..50f8c87c 100644 --- a/functest_kubernetes/ims/cassandra-depl.yaml +++ b/functest_kubernetes/ims/cassandra-depl.yaml @@ -36,7 +36,7 @@ spec: exec: command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "7000 9042 9160"] # Cassandra can take a very, very long time to start up - initialDelaySeconds: 1200 + initialDelaySeconds: 600 readinessProbe: exec: command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "7000 9042 9160"] diff --git a/functest_kubernetes/ims/helm/Chart.yaml b/functest_kubernetes/ims/helm/Chart.yaml new file mode 100644 index 00000000..0f0d7e5d --- /dev/null +++ b/functest_kubernetes/ims/helm/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Clearwater +name: clearwater +version: 0.1.0 diff --git a/functest_kubernetes/ims/helm/templates/astaire-depl.yaml b/functest_kubernetes/ims/helm/templates/astaire-depl.yaml new file mode 100644 index 00000000..11fcb1d6 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/astaire-depl.yaml @@ -0,0 +1,61 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: astaire +spec: + replicas: 1 + selector: + matchLabels: + service: astaire + template: + metadata: + labels: + service: astaire + spec: + terminationGracePeriodSeconds: 120 + initContainers: + - name: wait-on-cassandra + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup cassandra; do echo waiting for cassandra to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-astaire:{{ .Values.image.tag }}" + name: astaire + ports: + - containerPort: 22 + - containerPort: 11211 + - containerPort: 11311 + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + tcpSocket: + port: 11311 + periodSeconds: 10 + failureThreshold: 9 + readinessProbe: + tcpSocket: + port: 11311 + volumeMounts: + - name: astairelogs + mountPath: /var/log/astaire + lifecycle: + preStop: + exec: + command: ["/bin/bash", "-c", "/usr/bin/pre-stop"] + - image: busybox:1.28 + name: tailer + command: [ "tail", "-F", "/var/log/astaire/astaire_current.txt" ] + volumeMounts: + - name: astairelogs + mountPath: /var/log/astaire + volumes: + - name: astairelogs + emptyDir: {} + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/astaire-svc.yaml b/functest_kubernetes/ims/helm/templates/astaire-svc.yaml new file mode 100644 index 00000000..2e2c8715 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/astaire-svc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: astaire +spec: + ports: + - name: "11311" + port: 11311 + selector: + service: astaire + clusterIP: None diff --git a/functest_kubernetes/ims/helm/templates/bono-depl.yaml b/functest_kubernetes/ims/helm/templates/bono-depl.yaml new file mode 100644 index 00000000..d3fb1b82 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/bono-depl.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: bono +spec: + replicas: 1 + selector: + matchLabels: + service: bono + template: + metadata: + labels: + service: bono + snmp: enabled + spec: + initContainers: + - name: wait-on-sprout + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup sprout; do echo waiting for sprout to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-bono:{{ .Values.image.tag }}" + name: bono + ports: + - containerPort: 22 + - containerPort: 3478 + - containerPort: 5060 + - containerPort: 5062 + - containerPort: 5060 + protocol: "UDP" + - containerPort: 5062 + protocol: "UDP" + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + exec: + command: ["nc", "-z", "-w", "5", "127.0.0.1", "5060"] + initialDelaySeconds: 30 + readinessProbe: + tcpSocket: + port: 5060 + livenessProbe: + exec: + command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "3478 5060 5062"] + initialDelaySeconds: 30 + readinessProbe: + exec: + command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "3478 5060 5062"] + volumeMounts: + - name: bonologs + mountPath: /var/log/bono + - image: busybox:1.28 + name: tailer + command: [ "tail", "-F", "/var/log/bono/bono_current.txt" ] + volumeMounts: + - name: bonologs + mountPath: /var/log/bono + volumes: + - name: bonologs + emptyDir: {} + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/bono-svc.yaml b/functest_kubernetes/ims/helm/templates/bono-svc.yaml new file mode 100644 index 00000000..8220ccd0 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/bono-svc.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: bono +spec: + clusterIP: None + ports: + - name: "3478" + port: 3478 + - name: "5060" + port: 5060 + - name: "5062" + port: 5062 + selector: + service: bono diff --git a/functest_kubernetes/ims/helm/templates/cassandra-depl.yaml b/functest_kubernetes/ims/helm/templates/cassandra-depl.yaml new file mode 100644 index 00000000..fb04a78f --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/cassandra-depl.yaml @@ -0,0 +1,45 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: cassandra +spec: + replicas: 1 + selector: + matchLabels: + service: cassandra + template: + metadata: + labels: + service: cassandra + spec: + initContainers: + - name: wait-on-etcd + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup etcd; do echo waiting for etcd to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-cassandra:{{ .Values.image.tag }}" + name: cassandra + ports: + - containerPort: 22 + - containerPort: 7001 + - containerPort: 9042 + - containerPort: 9160 + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + exec: + command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "7000 9042 9160"] + # Cassandra can take a very, very long time to start up + initialDelaySeconds: 600 + readinessProbe: + exec: + command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "7000 9042 9160"] + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/cassandra-svc.yaml b/functest_kubernetes/ims/helm/templates/cassandra-svc.yaml new file mode 100644 index 00000000..dbaa3c0c --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/cassandra-svc.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: cassandra +spec: + ports: + - name: "7001" + port: 7001 + - name: "7000" + port: 7000 + - name: "9042" + port: 9042 + - name: "9160" + port: 9160 + selector: + service: cassandra + clusterIP: None diff --git a/functest_kubernetes/ims/helm/templates/chronos-depl.yaml b/functest_kubernetes/ims/helm/templates/chronos-depl.yaml new file mode 100644 index 00000000..641ba479 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/chronos-depl.yaml @@ -0,0 +1,62 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + service: chronos + name: chronos +spec: + replicas: 1 + selector: + matchLabels: + service: chronos + template: + metadata: + labels: + service: chronos + spec: + terminationGracePeriodSeconds: 120 + initContainers: + - name: wait-on-cassandra + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup cassandra; do echo waiting for cassandra to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-chronos:{{ .Values.image.tag }}" + name: chronos + ports: + - containerPort: 22 + - containerPort: 7253 + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + tcpSocket: + port: 7253 + periodSeconds: 10 + failureThreshold: 9 + readinessProbe: + tcpSocket: + port: 7253 + volumeMounts: + - name: chronoslogs + mountPath: /var/log/chronos + lifecycle: + preStop: + exec: + command: ["/bin/bash", "-c", "/usr/bin/pre-stop"] + - image: busybox:1.28 + name: tailer + command: [ "tail", "-F", "/var/log/chronos/chronos_current.txt" ] + volumeMounts: + - name: chronoslogs + mountPath: /var/log/chronos + volumes: + - name: chronoslogs + emptyDir: {} + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/chronos-svc.yaml b/functest_kubernetes/ims/helm/templates/chronos-svc.yaml new file mode 100644 index 00000000..0c421260 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/chronos-svc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: chronos +spec: + ports: + - name: "7253" + port: 7253 + selector: + service: chronos + clusterIP: None diff --git a/functest_kubernetes/ims/helm/templates/ellis-depl.yaml b/functest_kubernetes/ims/helm/templates/ellis-depl.yaml new file mode 100644 index 00000000..0a290139 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/ellis-depl.yaml @@ -0,0 +1,45 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ellis +spec: + replicas: 1 + selector: + matchLabels: + service: ellis + template: + metadata: + labels: + service: ellis + spec: + initContainers: + - name: wait-on-homestead-prov + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup homestead-prov; do echo waiting for homestead-prov to start ...; sleep 2; done'] + - name: wait-on-sprout + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup sprout; do echo waiting for sprout to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-ellis:{{ .Values.image.tag }}" + name: ellis + ports: + - containerPort: 22 + - containerPort: 80 + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + tcpSocket: + port: 80 + initialDelaySeconds: 30 + readinessProbe: + tcpSocket: + port: 80 + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/ellis-svc.yaml b/functest_kubernetes/ims/helm/templates/ellis-svc.yaml new file mode 100644 index 00000000..53376317 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/ellis-svc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: ellis +spec: + clusterIP: None + ports: + - name: "http" + port: 80 + selector: + service: ellis diff --git a/functest_kubernetes/ims/helm/templates/etcd-depl.yaml b/functest_kubernetes/ims/helm/templates/etcd-depl.yaml new file mode 100644 index 00000000..c9e628ff --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/etcd-depl.yaml @@ -0,0 +1,63 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: etcd +spec: + replicas: 1 + selector: + matchLabels: + instance-type: etcd-pod + template: + metadata: + creationTimestamp: null + labels: + instance-type: etcd-pod + spec: + containers: + - args: + - --name + - $(MY_POD_NAME) + - --advertise-client-urls + - http://$(MY_POD_IP):2379,http://$(MY_POD_IP):4001 + - --listen-client-urls + - http://0.0.0.0:2379,http://0.0.0.0:4001 + - --initial-advertise-peer-urls + - http://$(MY_POD_IP):2380 + - --listen-peer-urls + - http://0.0.0.0:2380 + # By default use a single pod cluster + - --initial-cluster + - $(MY_POD_NAME)=http://$(MY_POD_IP):2380 + # Alternatively multi-pod clusters can be supported Using central discvovery. Run e.g. + # curl https://discovery.etcd.io/new?size=3 | sed s/https/http/ + # to get a discovery URL for a 3 pod cluster, substitute the returned value below, and + # set replicas: 3 above. + #- --discovery + #- <URL returned by command above> + - --initial-cluster-state + - new + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: MY_POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + image: quay.io/coreos/etcd:v2.2.5 + name: etcd + ports: + - containerPort: 2379 + - containerPort: 2380 + - containerPort: 4001 + livenessProbe: + tcpSocket: + port: 4001 + initialDelaySeconds: 300 + readinessProbe: + tcpSocket: + port: 4001 + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/etcd-svc.yaml b/functest_kubernetes/ims/helm/templates/etcd-svc.yaml new file mode 100644 index 00000000..2df5b164 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/etcd-svc.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: etcd + labels: + instance-type: etcd-pod +spec: + ports: + - name: "etcd-client" + port: 2379 + - name: "etcd-server" + port: 2380 + - name: "4001" + port: 4001 + selector: + instance-type: etcd-pod + clusterIP: None diff --git a/functest_kubernetes/ims/helm/templates/homer-depl.yaml b/functest_kubernetes/ims/helm/templates/homer-depl.yaml new file mode 100644 index 00000000..01bf9cdc --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/homer-depl.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: homer +spec: + replicas: 1 + selector: + matchLabels: + service: homer + template: + metadata: + labels: + service: homer + spec: + initContainers: + - name: wait-on-cassandra + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup cassandra; do echo waiting for cassandra to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-homer:{{ .Values.image.tag }}" + name: homer + ports: + - containerPort: 22 + - containerPort: 7888 + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + tcpSocket: + port: 7888 + initialDelaySeconds: 30 + readinessProbe: + tcpSocket: + port: 7888 + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/homer-svc.yaml b/functest_kubernetes/ims/helm/templates/homer-svc.yaml new file mode 100644 index 00000000..72fda055 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/homer-svc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: homer +spec: + ports: + - name: "7888" + port: 7888 + selector: + service: homer + clusterIP: None diff --git a/functest_kubernetes/ims/helm/templates/homestead-depl.yaml b/functest_kubernetes/ims/helm/templates/homestead-depl.yaml new file mode 100644 index 00000000..782ff16d --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/homestead-depl.yaml @@ -0,0 +1,58 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: homestead +spec: + replicas: 1 + selector: + matchLabels: + service: homestead + template: + metadata: + labels: + service: homestead + snmp: enabled + spec: + initContainers: + - name: wait-on-cassandra + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup cassandra; do echo waiting for cassandra to start ...; sleep 2; done'] + - name: wait-on-astaire + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup astaire; do echo waiting for astaire to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-homestead:{{ .Values.image.tag }}" + name: homestead + ports: + - containerPort: 22 + - containerPort: 8888 + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + exec: + command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "8888"] + initialDelaySeconds: 60 + readinessProbe: + exec: + command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "8888"] + volumeMounts: + - name: homesteadlogs + mountPath: /var/log/homestead + - image: busybox:1.28 + name: tailer + command: [ "tail", "-F", "/var/log/homestead/homestead_current.txt" ] + volumeMounts: + - name: homesteadlogs + mountPath: /var/log/homestead + volumes: + - name: homesteadlogs + emptyDir: {} + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/homestead-prov-depl.yaml b/functest_kubernetes/ims/helm/templates/homestead-prov-depl.yaml new file mode 100644 index 00000000..59ec4e26 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/homestead-prov-depl.yaml @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: homestead-prov +spec: + replicas: 1 + selector: + matchLabels: + service: homestead-prov + template: + metadata: + labels: + service: homestead-prov + snmp: enabled + spec: + initContainers: + - name: wait-on-homestead + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup homestead; do echo waiting for homestead to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-homestead-prov:{{ .Values.image.tag }}" + name: homestead-prov + ports: + - containerPort: 22 + - containerPort: 8889 + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + exec: + command: ["/bin/bash", "/usr/share/clearwater/bin/poll_homestead-prov.sh"] + initialDelaySeconds: 60 + readinessProbe: + exec: + command: ["/bin/bash", "/usr/share/clearwater/bin/poll_homestead-prov.sh"] + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/homestead-prov-svc.yaml b/functest_kubernetes/ims/helm/templates/homestead-prov-svc.yaml new file mode 100644 index 00000000..83103021 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/homestead-prov-svc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: homestead-prov +spec: + ports: + - name: "8889" + port: 8889 + selector: + service: homestead-prov + clusterIP: None diff --git a/functest_kubernetes/ims/helm/templates/homestead-svc.yaml b/functest_kubernetes/ims/helm/templates/homestead-svc.yaml new file mode 100644 index 00000000..4015e81b --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/homestead-svc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: homestead +spec: + ports: + - name: "8888" + port: 8888 + selector: + service: homestead + clusterIP: None diff --git a/functest_kubernetes/ims/helm/templates/ralf-depl.yaml b/functest_kubernetes/ims/helm/templates/ralf-depl.yaml new file mode 100644 index 00000000..b052eea6 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/ralf-depl.yaml @@ -0,0 +1,55 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ralf +spec: + replicas: 1 + selector: + matchLabels: + service: ralf + template: + metadata: + labels: + service: ralf + snmp: enabled + spec: + initContainers: + - name: wait-on-cassandra + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup cassandra; do echo waiting for cassandra to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-ralf:{{ .Values.image.tag }}" + name: ralf + ports: + - containerPort: 22 + - containerPort: 10888 + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + tcpSocket: + port: 10888 + initialDelaySeconds: 30 + readinessProbe: + tcpSocket: + port: 10888 + volumeMounts: + - name: ralflogs + mountPath: /var/log/ralf + - image: busybox:1.28 + name: tailer + command: [ "tail", "-F", "/var/log/ralf/ralf_current.txt" ] + volumeMounts: + - name: ralflogs + mountPath: /var/log/ralf + volumes: + - name: ralflogs + emptyDir: {} + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/ralf-svc.yaml b/functest_kubernetes/ims/helm/templates/ralf-svc.yaml new file mode 100644 index 00000000..07ad51e9 --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/ralf-svc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: ralf +spec: + ports: + - name: "10888" + port: 10888 + selector: + service: ralf + clusterIP: None diff --git a/functest_kubernetes/ims/helm/templates/sprout-depl.yaml b/functest_kubernetes/ims/helm/templates/sprout-depl.yaml new file mode 100644 index 00000000..1ee4701f --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/sprout-depl.yaml @@ -0,0 +1,61 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: sprout +spec: + replicas: 1 + selector: + matchLabels: + service: sprout + template: + metadata: + labels: + service: sprout + snmp: enabled + spec: + initContainers: + - name: wait-on-ralf + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup ralf; do echo waiting for ralf to start ...; sleep 2; done'] + - name: wait-on-chronos + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup chronos; do echo waiting for chronos to start ...; sleep 2; done'] + - name: wait-on-homestead + image: busybox:1.28 + command: ['sh', '-c', 'until nslookup homestead; do echo waiting for homestead to start ...; sleep 2; done'] + containers: + - image: "{{ .Values.image.path }}-sprout:{{ .Values.image.tag }}" + name: sprout + ports: + - containerPort: 22 + envFrom: + - configMapRef: + name: env-vars + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + livenessProbe: + exec: + command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "5052 5054"] + initialDelaySeconds: 30 + periodSeconds: 3 + readinessProbe: + exec: + command: ["/bin/bash", "/usr/share/kubernetes/liveness.sh", "5052 5054"] + volumeMounts: + - name: sproutlogs + mountPath: /var/log/sprout + - image: busybox:1.28 + name: tailer + command: [ "tail", "-F", "/var/log/sprout/sprout_current.txt" ] + volumeMounts: + - name: sproutlogs + mountPath: /var/log/sprout + volumes: + - name: sproutlogs + emptyDir: {} + imagePullSecrets: + - name: ~ + restartPolicy: Always diff --git a/functest_kubernetes/ims/helm/templates/sprout-svc.yaml b/functest_kubernetes/ims/helm/templates/sprout-svc.yaml new file mode 100644 index 00000000..cf23a33c --- /dev/null +++ b/functest_kubernetes/ims/helm/templates/sprout-svc.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: sprout +spec: + ports: + - name: "5052" + port: 5052 + - name: "5054" + port: 5054 + selector: + service: sprout + clusterIP: None diff --git a/functest_kubernetes/ims/helm/values.yaml b/functest_kubernetes/ims/helm/values.yaml new file mode 100644 index 00000000..b2cb3272 --- /dev/null +++ b/functest_kubernetes/ims/helm/values.yaml @@ -0,0 +1,6 @@ +# Default values for clearwater. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +image: + path: ollivier/clearwater + tag: hunter diff --git a/functest_kubernetes/ims/ims.py b/functest_kubernetes/ims/ims.py index 0d059550..14097c8f 100644 --- a/functest_kubernetes/ims/ims.py +++ b/functest_kubernetes/ims/ims.py @@ -11,8 +11,10 @@ from __future__ import division +import abc import logging import time +import subprocess import re import yaml @@ -53,48 +55,40 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes self.namespace = "" self.zone = "" - def deploy_vnf(self): - """Deploy vIMS as proposed by clearwater-docker + def prepare_vnf(self): + """Prepare vIMS as proposed by clearwater-live-test - It leverages on unofficial Clearwater dockers as proposed in the - documentation. + It creates a dedicated namespace and the configmap needed. - See https://github.com/Metaswitch/clearwater-docker for more details + See https://github.com/Metaswitch/clearwater-live-test for more details """ api_response = self.corev1.create_namespace( client.V1Namespace(metadata=client.V1ObjectMeta( generate_name="ims-"))) self.namespace = api_response.metadata.name self.__logger.debug("create_namespace: %s", api_response) + self.zone = '{}.svc.cluster.local'.format(self.namespace) metadata = client.V1ObjectMeta( name=self.metadata_name, namespace=self.namespace) - self.zone = '{}.svc.cluster.local'.format(self.namespace) body = client.V1ConfigMap( metadata=metadata, data={"ADDITIONAL_SHARED_CONFIG": "", "ZONE": self.zone}) api_response = self.corev1.create_namespaced_config_map( self.namespace, body=body) self.__logger.debug("create_namespaced_config_map: %s", api_response) - for deployment in self.deployment_list: - with open(pkg_resources.resource_filename( - 'functest_kubernetes', - 'ims/{}-depl.yaml'.format(deployment))) as yfile: - body = yaml.safe_load(yfile) - resp = self.appsv1.create_namespaced_deployment( - body=body, namespace=self.namespace) - self.__logger.info("Deployment %s created", resp.metadata.name) - self.__logger.debug( - "create_namespaced_deployment: %s", api_response) - for service in self.deployment_list: - with open(pkg_resources.resource_filename( - 'functest_kubernetes', - 'ims/{}-svc.yaml'.format(service))) as yfile: - body = yaml.safe_load(yfile) - resp = self.corev1.create_namespaced_service( - body=body, namespace=self.namespace) - self.__logger.info("Service %s created", resp.metadata.name) - self.__logger.debug( - "create_namespaced_service: %s", api_response) + + @abc.abstractmethod + def deploy_vnf(self): + """Deploy vIMS as proposed by clearwater-docker + + It must be overriden on purpose. + + See https://github.com/Metaswitch/clearwater-docker for more details + """ + + def wait_vnf(self): + """Wait vIMS is up and running""" + assert self.namespace status = self.deployment_list.copy() watch_deployment = watch.Watch() for event in watch_deployment.stream( @@ -119,12 +113,14 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes def test_vnf(self): """Test vIMS as proposed by clearwater-live-test - It leverages on an unofficial Clearwater docker to allow testing from + It leverages an unofficial Clearwater docker to allow testing from the Kubernetes cluster. See https://github.com/Metaswitch/clearwater-live-test for more details """ time.sleep(120) + assert self.namespace + assert self.zone container = client.V1Container( name=self.test_container_name, image=self.test_image_name, command=["rake", "test[{}]".format(self.zone), @@ -171,7 +167,9 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes def run(self, **kwargs): self.start_time = time.time() try: - if self.deploy_vnf(): + self.prepare_vnf() + self.deploy_vnf() + if self.wait_vnf(): self.test_vnf() except client.rest.ApiException: self.__logger.exception("Cannot deploy and test vIms") @@ -179,6 +177,12 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes def clean(self): try: + api_response = self.corev1.delete_namespaced_pod( + name=self.test_container_name, namespace=self.namespace) + self.__logger.debug("delete_namespaced_pod: %s", api_response) + except client.rest.ApiException: + pass + try: api_response = self.corev1.delete_namespaced_config_map( name=self.metadata_name, namespace=self.namespace) self.__logger.debug( @@ -186,11 +190,51 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes except client.rest.ApiException: pass try: - api_response = self.corev1.delete_namespaced_pod( - name=self.test_container_name, namespace=self.namespace) - self.__logger.debug("delete_namespaced_pod: %s", api_response) + api_response = self.corev1.delete_namespace(self.namespace) + self.__logger.debug("delete_namespace: %s", self.namespace) except client.rest.ApiException: pass + + +class K8sVims(Vims): + """Deploy vIMS via kubectl as proposed by clearwater-docker + + It leverages unofficial Clearwater dockers as proposed in the + documentation. + + See https://github.com/Metaswitch/clearwater-docker for more details + """ + + __logger = logging.getLogger(__name__) + + def deploy_vnf(self): + """Deploy vIMS via kubectl as proposed by clearwater-docker + + See https://github.com/Metaswitch/clearwater-docker for more details + """ + assert self.namespace + for deployment in self.deployment_list: + with open(pkg_resources.resource_filename( + 'functest_kubernetes', + 'ims/{}-depl.yaml'.format(deployment))) as yfile: + body = yaml.safe_load(yfile) + resp = self.appsv1.create_namespaced_deployment( + body=body, namespace=self.namespace) + self.__logger.info("Deployment %s created", resp.metadata.name) + self.__logger.debug( + "create_namespaced_deployment: %s", resp) + for service in self.deployment_list: + with open(pkg_resources.resource_filename( + 'functest_kubernetes', + 'ims/{}-svc.yaml'.format(service))) as yfile: + body = yaml.safe_load(yfile) + resp = self.corev1.create_namespaced_service( + body=body, namespace=self.namespace) + self.__logger.info("Service %s created", resp.metadata.name) + self.__logger.debug( + "create_namespaced_service: %s", resp) + + def clean(self): for deployment in self.deployment_list: try: api_response = self.appsv1.delete_namespaced_deployment( @@ -206,8 +250,34 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes "delete_namespaced_service: %s", api_response) except client.rest.ApiException: pass - try: - api_response = self.corev1.delete_namespace(self.namespace) - self.__logger.debug("delete_namespace: %s", self.namespace) - except client.rest.ApiException: - pass + super(K8sVims, self).clean() + + +class HelmVims(Vims): + """Deploy vIMS via Helm as proposed by clearwater-docker + + It leverages unofficial Clearwater dockers as proposed in the + documentation. + + See https://github.com/Metaswitch/clearwater-docker for more details + """ + + __logger = logging.getLogger(__name__) + + def deploy_vnf(self): + """Deploy vIMS via Helm as proposed by clearwater-docker + + See https://github.com/Metaswitch/clearwater-docker for more details + """ + cmd = [ + "helm", "install", "clearwater", + pkg_resources.resource_filename("functest_kubernetes", "ims/helm"), + "-n", self.namespace] + output = subprocess.check_output(cmd) + self.__logger.debug(output.decode("utf-8")) + + def clean(self): + cmd = ["helm", "uninstall", "clearwater", "-n", self.namespace] + output = subprocess.check_output(cmd) + self.__logger.debug(output.decode("utf-8")) + super(HelmVims, self).clean() @@ -12,7 +12,8 @@ scripts = xtesting.testcase = e2e_testing = functest_kubernetes.k8stest:E2ETesting xrally_kubernetes = functest_kubernetes.rally.rally_kubernetes:RallyKubernetes - k8s_vims = functest_kubernetes.ims.ims:Vims + k8s_vims = functest_kubernetes.ims.ims:K8sVims + helm_vims = functest_kubernetes.ims.ims:HelmVims kube_hunter = functest_kubernetes.security.security:KubeHunter kube_bench = functest_kubernetes.security.security:KubeBench cnf_conformance = functest_kubernetes.cnf_conformance.conformance:CNFConformance |