Verified Commit 580919af authored by Pierre-Louis Bonicoli's avatar Pierre-Louis Bonicoli 🏗
Browse files

tests: Add k8s based scenario

quay.io/pilou/test:latest Docker image is the same that the one used for
default scenario.
parent f0886077
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Create molecule instance(s)
k8s:
definition:
apiVersion: v1
kind: pod
metadata:
name: '{{ item.pod|default(item.name) }}'
namespace: '{{ item.namespace|default(lookup("env", "K8S_NAMESPACE")) }}'
labels:
app: '{{ item.pod|default(item.name) }}'
spec:
hostname: '{{ item.name }}' # required for the Pod’s A or AAAA record to be created
containers:
- name: '{{ item.name }}'
image: '{{ item.image }}'
imagePullPolicy: '{{ item.image_pull | default("IfNotPresent") }}'
command: '{{ item.command | default(["/bin/sh", "-c"]) }}'
args: >-
{{ [] if item.command|default(false) else (item.args | default(["while true; do sleep 30; done;"])) }}
workingDir: '{{ item.working_dir | default("/tmp") }}'
restartPolicy: 'Never'
resources:
requests: '{{ "memory: { " + item.memory + "Mi" + " }" if item.memory|default(false) else "{}" }}'
limits: '{{ "memory: { " + item.memory + "Mi" + " }" if item.memory|default(false) else "{}" }}'
volumeMounts: '{{ item.volumeMounts | default([]) }}'
volumes: '{{ item.volumes | default([]) }}'
wait: true
loop: "{{ molecule_yml.platforms }}"
loop_control:
label: '{{ item.name }}'
register: server
- name: Create headless service(s)
vars:
explicit_pods: '{{ molecule_yml.platforms|json_query("[?pod].{pod: pod, namespace: namespace}") }}'
implicit_pods: '{{ molecule_yml.platforms|json_query("[?!pod].{pod: name, namespace: namespace}") }}'
pods: '{{ explicit_pods | union(implicit_pods) | list }}'
k8s:
definition:
apiVersion: v1
kind: Service
metadata:
name: '{{ item.pod|default(item.name) }}'
namespace: '{{ item.namespace|default(lookup("env", "K8S_NAMESPACE"), true) }}'
spec:
clusterIP: None
selector:
app: '{{ item.pod|default(item.name) }}'
loop: '{{ pods }}'
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
vars:
explicit_pods: '{{ molecule_yml.platforms|json_query("[?pod].{pod: pod, namespace: namespace}") }}'
implicit_pods: '{{ molecule_yml.platforms|json_query("[?!pod].{pod: name, namespace: namespace}") }}'
pods: '{{ explicit_pods | union(implicit_pods) | list }}'
tasks:
- name: Destroy headless service(s)
k8s:
name: '{{ item.pod|default(item.name) }}'
api_version: v1
kind: Service
namespace: '{{ item.namespace|default(lookup("env", "K8S_NAMESPACE"), true) }}'
state: absent
wait: true
loop: '{{ pods }}'
- name: Destroy molecule instance(s)
k8s:
name: '{{ item.pod }}'
api_version: v1
kind: Pod
namespace: '{{ item.namespace|default(lookup("env", "K8S_NAMESPACE"), true) }}'
state: absent
wait: true
loop: '{{ pods }}'
loop_control:
label: '{{ item.pod }}'
---
driver:
name: delegated
# options:
# ansible_connection_options:
# ansible_connection: kubectl
provisioner:
name: ansible
inventory:
group_vars:
all:
ansible_connection: kubectl
platforms:
- name: molecule-burp-server
image: quay.io/pilou/test:latest
command: [/sbin/init]
volumeMounts: &volumeMounts
- mountPath: /tmp
name: tmpfs-tmp
- mountPath: /run
name: tmpfs-run
- mountPath: /run/lock
name: tmpfs-lock
- mountPath: /sys/fs/cgroup
name: cgroup
volumes: &volumes
- name: tmpfs-tmp
emptyDir:
medium: Memory
- name: tmpfs-run
emptyDir:
medium: Memory
- name: tmpfs-lock
emptyDir:
medium: Memory
- name: cgroup
hostPath:
path: /sys/fs/cgroup
type: Directory
- name: molecule-burp-client
image: quay.io/pilou/test:latest
command: [/sbin/init]
volumeMounts: *volumeMounts
volumes: *volumes
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment