Prepare scripts and scenarios to use in MOSK testing of Kubernetes

Related-PROD: PROD-36128
Change-Id: I0d9145045c2a95e34966519157e9c7200bea4e3e
diff --git a/k8s/gen_kubespec.sh b/k8s/gen_kubespec.sh
new file mode 100644
index 0000000..d4053aa
--- /dev/null
+++ b/k8s/gen_kubespec.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# files
+ca_crt=$(pwd)/ca.crt
+client_crt=$(pwd)/client.crt
+client_key=$(pwd)/client.key
+
+function show_help() {
+   printf "\ngen_kubespec.sh <kubeconfig.yaml>\n"
+   exit 1
+}
+
+# Check for a config file
+if [[ -z ${1+x} ]]; then
+   show_help
+   printf "\nERROR: No kubeconfig.yaml specified\n"
+   exit 1
+fi
+
+# Check if file exists
+if [[ ! -f $1 ]]; then
+   show_help
+   printf "\nERROR: Supplied kubeconfig file not exists at '$1'\n"
+   exit 1
+fi
+
+# extract data as variables
+declare $(sed -e 's/:[^:\/\/,:4]/=/g;s/ *=/=/g;s/-/_/g' $1 | grep 'certificate\|key\|server' | tr -d ' ')
+
+### Uncomment if separate files needed
+printf "Creating 'ca.crt', 'client.crt' and 'client.key'\n"
+echo "# '${ca_crt}'"
+echo $certificate_authority_data | base64 -d >${ca_crt}
+echo "# '${client_crt}'"
+echo $client_certificate_data | base64 -d >${client_crt}
+echo "# '${client_key}'"
+echo $client_key_data | base64 -d >${client_key}
+
+printf "Generating 'kubespec.yaml'\n"
+cat << EOF >kubespec_generated.yaml
+---
+existing@kubernetes:
+    server: $server
+    certificate-authority: ${ca_crt}
+    client-certificate: ${client_crt}
+    client-key: ${client_key}
+    tls_insecure: True
+EOF
diff --git a/k8s/k8s-mos-scenarios-100.yaml b/k8s/k8s-mos-scenarios-100.yaml
new file mode 100644
index 0000000..da9448a
--- /dev/null
+++ b/k8s/k8s-mos-scenarios-100.yaml
@@ -0,0 +1,120 @@
+{% set image_box = "busybox" %}
+{% set image_pause = "mirantis.azurecr.io/general/external/pause:3.1" %}
+{% set image_cirros = "virtlet/download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img" %}
+{% set concurrency = 5 %}
+{% set times = 100 %}
+{% set replicas = 3 %}
+{% set replicas_scaled = 4 %}
+{% set namespaces = 10 %}
+
+
+---
+version: 2
+title: MOS Kubenetes performance checks
+subtasks:
+- title: Run a single workload with listing existing kubernetes namespaces
+  scenario:
+    Kubernetes.list_namespaces: {}
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+- title: Run a single workload with create/read/delete namespace
+  scenario:
+    Kubernetes.create_and_delete_namespace: {}
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+- title: Run a single workload with create/read/delete job
+  scenario:
+    Kubernetes.create_and_delete_job:
+      image: {{image_cirros}}
+      command:
+      - echo
+      - "SUCCESS"
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
+- title: Run a single workload with create/read/delete pod with configMap volume
+  scenario:
+    Kubernetes.create_and_delete_pod_with_configmap_volume:
+      image: {{image_pause}}
+      mount_path: /var/log/check.txt
+      subpath: check.txt
+      configmap_data:
+        check.txt: |
+          test
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
+- title: Run a single workload with create/read/delete pod with local PVC
+  scenario:
+    Kubernetes.create_and_delete_pod_with_local_persistent_volume:
+      persistent_volume:
+        size: 1Gi
+        volume_mode: Block
+        local_path: /var/tmp
+        access_modes:
+        - ReadWriteOnce
+        node_affinity:
+          required:
+            nodeSelectorTerms:
+            - matchExpressions:
+              - key: kubernetes.io/os
+                operator: In
+                values:
+                - linux
+      persistent_volume_claim:
+        size: 250Mi
+        access_modes:
+        - ReadWriteOnce
+      image: {{image_box}}
+      mount_path: /opt/check
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
+    local_storageclass: {}
+- title: Run a single workload with create/delete NodePort service
+  scenario:
+    Kubernetes.create_and_delete_pod_with_node_port_service:
+      image: {{image_pause}}
+      port: 80
+      protocol: TCP
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
+    kubernetes.cfg:
+      prepoll_delay: 1
+- title: Run a single workload with create/read/delete pod
+  scenario:
+    Kubernetes.create_and_delete_pod:
+      image: {{image_pause}}
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
diff --git a/k8s/k8s-mos-scenarios.yaml b/k8s/k8s-mos-scenarios.yaml
new file mode 100644
index 0000000..eaf62dd
--- /dev/null
+++ b/k8s/k8s-mos-scenarios.yaml
@@ -0,0 +1,120 @@
+{% set image_box = "busybox" %}
+{% set image_pause = "mirantis.azurecr.io/general/external/pause:3.1" %}
+{% set image_cirros = "virtlet/download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img" %}
+{% set concurrency = 1 %}
+{% set times = 1 %}
+{% set replicas = 1 %}
+{% set replicas_scaled = 2 %}
+{% set namespaces = 1 %}
+
+
+---
+version: 2
+title: MOS Kubenetes performance checks
+subtasks:
+- title: Run a single workload with listing existing kubernetes namespaces
+  scenario:
+    Kubernetes.list_namespaces: {}
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+- title: Run a single workload with create/read/delete namespace
+  scenario:
+    Kubernetes.create_and_delete_namespace: {}
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+- title: Run a single workload with create/read/delete job
+  scenario:
+    Kubernetes.create_and_delete_job:
+      image: {{image_cirros}}
+      command:
+      - echo
+      - "SUCCESS"
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
+- title: Run a single workload with create/read/delete pod with configMap volume
+  scenario:
+    Kubernetes.create_and_delete_pod_with_configmap_volume:
+      image: {{image_pause}}
+      mount_path: /var/log/check.txt
+      subpath: check.txt
+      configmap_data:
+        check.txt: |
+          test
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
+- title: Run a single workload with create/read/delete pod with local PVC
+  scenario:
+    Kubernetes.create_and_delete_pod_with_local_persistent_volume:
+      persistent_volume:
+        size: 1Gi
+        volume_mode: Block
+        local_path: /var/tmp
+        access_modes:
+        - ReadWriteOnce
+        node_affinity:
+          required:
+            nodeSelectorTerms:
+            - matchExpressions:
+              - key: kubernetes.io/os
+                operator: In
+                values:
+                - linux
+      persistent_volume_claim:
+        size: 250Mi
+        access_modes:
+        - ReadWriteOnce
+      image: {{image_box}}
+      mount_path: /opt/check
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
+    local_storageclass: {}
+- title: Run a single workload with create/delete NodePort service
+  scenario:
+    Kubernetes.create_and_delete_pod_with_node_port_service:
+      image: {{image_pause}}
+      port: 80
+      protocol: TCP
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
+    kubernetes.cfg:
+      prepoll_delay: 1
+- title: Run a single workload with create/read/delete pod
+  scenario:
+    Kubernetes.create_and_delete_pod:
+      image: {{image_pause}}
+  runner:
+    constant:
+      concurrency: {{concurrency}}
+      times: {{times}}
+  contexts:
+    namespaces:
+      count: {{namespaces}}
+      with_serviceaccount: true
diff --git a/k8s/k8s-resources.yaml b/k8s/k8s-resources.yaml
new file mode 100644
index 0000000..af974d7
--- /dev/null
+++ b/k8s/k8s-resources.yaml
@@ -0,0 +1,115 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: qa-space
+---
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: qa-pv
+  namespace: qa-space
+  labels:
+    type: local
+spec:
+  storageClassName: volumes-nvme
+  capacity:
+    storage: 50Gi
+  accessModes:
+    - ReadWriteOnce
+  hostPath:
+    path: "/tmp/artifacts"
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: qa-pvc
+  namespace: qa-space
+spec:
+  storageClassName: volumes-nvme
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 50Gi
+---
+apiVersion: v1
+kind: Pod
+metadata:
+  name: qa-pod
+  namespace: qa-space
+spec:
+  containers:
+  - command:
+    - /bin/sleep
+    - infinity
+    env:
+    - name: LANG
+      value: C.UTF-8
+    - name: OS_IDENTITY_API_VERSION
+      value: "3"
+    - name: OS_AUTH_URL
+      valueFrom:
+        secretKeyRef:
+          key: OS_AUTH_URL
+          name: keystone-keystone-admin
+    - name: OS_REGION_NAME
+      valueFrom:
+        secretKeyRef:
+          key: OS_REGION_NAME
+          name: keystone-keystone-admin
+    - name: OS_INTERFACE
+      valueFrom:
+        secretKeyRef:
+          key: OS_INTERFACE
+          name: keystone-keystone-admin
+    - name: OS_ENDPOINT_TYPE
+      valueFrom:
+        secretKeyRef:
+          key: OS_INTERFACE
+          name: keystone-keystone-admin
+    - name: OS_PROJECT_DOMAIN_NAME
+      valueFrom:
+        secretKeyRef:
+          key: OS_PROJECT_DOMAIN_NAME
+          name: keystone-keystone-admin
+    - name: OS_PROJECT_NAME
+      valueFrom:
+        secretKeyRef:
+          key: OS_PROJECT_NAME
+          name: keystone-keystone-admin
+    - name: OS_USER_DOMAIN_NAME
+      valueFrom:
+        secretKeyRef:
+          key: OS_USER_DOMAIN_NAME
+          name: keystone-keystone-admin
+    - name: OS_USERNAME
+      valueFrom:
+        secretKeyRef:
+          key: OS_USERNAME
+          name: keystone-keystone-admin
+    - name: OS_PASSWORD
+      valueFrom:
+        secretKeyRef:
+          key: OS_PASSWORD
+          name: keystone-keystone-admin
+    - name: OS_DEFAULT_DOMAIN
+      valueFrom:
+        secretKeyRef:
+          key: OS_DEFAULT_DOMAIN
+          name: keystone-keystone-admin
+# enable this image is rally is not enough
+#    image: mirantis.azurecr.io/openstack/heat:ussuri-bionic-20201121180111
+    image: xrally/xrally-openstack:2.1.0
+    imagePullPolicy: IfNotPresent
+    name: qa-pod
+    volumeMounts:
+    - mountPath: /artifacts
+      name: qa-pv
+  dnsPolicy: ClusterFirst
+  volumes:
+  - emptyDir: {}
+    name: pod-tmp
+  - name: qa-pv
+    persistentVolumeClaim:
+      claimName: qa-pvc
+
diff --git a/k8s/kubespec.yaml.sample b/k8s/kubespec.yaml.sample
new file mode 100644
index 0000000..d123a0c
--- /dev/null
+++ b/k8s/kubespec.yaml.sample
@@ -0,0 +1,7 @@
+---
+existing@kubernetes:
+    server: https://172.16.30.4:443
+    certificate-authority: /artifacts/ca.crt
+    client-certificate: /artifacts/client.crt
+    client-key: /artifacts/client.key
+    tls_insecure: True