2018-07-09 15:33:16 +02:00
|
|
|
# TODO: This is the only way I could get the kubeconfig, I don't know why. Running the lookup outside of debug seems to return an empty string
|
2018-08-31 02:42:47 +02:00
|
|
|
#- debug: msg={{ lookup('env', 'K8S_AUTH_KUBECONFIG') }}
|
|
|
|
# register: kubeconfig
|
2018-07-09 15:33:16 +02:00
|
|
|
|
2018-05-30 19:04:48 +02:00
|
|
|
# Kubernetes resources
|
2018-08-31 02:42:47 +02:00
|
|
|
|
2019-05-30 01:26:43 +02:00
|
|
|
- include_tasks: delete.yml
|
2019-07-08 22:47:41 +02:00
|
|
|
- include_tasks: apply.yml
|
2018-11-13 13:50:15 +01:00
|
|
|
- include_tasks: waiter.yml
|
|
|
|
|
2018-08-31 02:42:47 +02:00
|
|
|
- block:
|
|
|
|
- name: Create a namespace
|
|
|
|
k8s:
|
|
|
|
name: testing
|
2019-07-08 22:47:41 +02:00
|
|
|
kind: Namespace
|
2018-08-31 02:42:47 +02:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: show output
|
|
|
|
debug:
|
|
|
|
var: output
|
|
|
|
|
2019-06-06 10:51:24 +02:00
|
|
|
- name: Setting validate_certs to true causes a failure
|
|
|
|
k8s:
|
|
|
|
name: testing
|
2019-07-08 22:47:41 +02:00
|
|
|
kind: Namespace
|
2019-06-06 10:51:24 +02:00
|
|
|
validate_certs: yes
|
|
|
|
ignore_errors: yes
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: assert that validate_certs caused a failure (and therefore was correctly translated to verify_ssl)
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- output is failed
|
|
|
|
|
2019-05-27 18:17:42 +02:00
|
|
|
- name: k8s_info works with empty resources
|
|
|
|
k8s_info:
|
2018-10-12 11:11:48 +02:00
|
|
|
kind: Deployment
|
|
|
|
namespace: testing
|
|
|
|
api_version: extensions/v1beta1
|
2019-05-27 18:17:42 +02:00
|
|
|
register: k8s_info
|
2018-10-12 11:11:48 +02:00
|
|
|
|
2019-05-27 18:17:42 +02:00
|
|
|
- name: assert that k8s_info is in correct format
|
2018-10-12 11:11:48 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2019-05-27 18:17:42 +02:00
|
|
|
- "'resources' in k8s_info"
|
|
|
|
- not k8s_info.resources
|
2018-10-12 11:11:48 +02:00
|
|
|
|
2018-08-31 02:42:47 +02:00
|
|
|
- name: Create a service
|
|
|
|
k8s:
|
|
|
|
state: present
|
|
|
|
resource_definition: &svc
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Service
|
2018-05-30 19:04:48 +02:00
|
|
|
metadata:
|
2018-08-31 02:42:47 +02:00
|
|
|
name: web
|
|
|
|
namespace: testing
|
|
|
|
labels:
|
|
|
|
app: galaxy
|
|
|
|
service: web
|
|
|
|
spec:
|
|
|
|
selector:
|
|
|
|
app: galaxy
|
|
|
|
service: web
|
|
|
|
ports:
|
|
|
|
- protocol: TCP
|
|
|
|
targetPort: 8000
|
|
|
|
name: port-8000-tcp
|
|
|
|
port: 8000
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: show output
|
|
|
|
debug:
|
|
|
|
var: output
|
|
|
|
|
|
|
|
- name: Create the service again
|
|
|
|
k8s:
|
|
|
|
state: present
|
|
|
|
resource_definition: *svc
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: Service creation should be idempotent
|
|
|
|
assert:
|
|
|
|
that: not output.changed
|
|
|
|
|
2019-06-06 10:59:19 +02:00
|
|
|
- name: Create a ConfigMap
|
|
|
|
k8s:
|
|
|
|
kind: ConfigMap
|
|
|
|
name: test-force-update
|
|
|
|
namespace: testing
|
|
|
|
definition:
|
|
|
|
data:
|
|
|
|
key: value
|
|
|
|
|
|
|
|
- name: Force update ConfigMap
|
|
|
|
k8s:
|
|
|
|
kind: ConfigMap
|
|
|
|
name: test-force-update
|
|
|
|
namespace: testing
|
|
|
|
definition:
|
|
|
|
data:
|
|
|
|
key: newvalue
|
|
|
|
force: yes
|
|
|
|
|
2018-08-31 02:42:47 +02:00
|
|
|
- name: Create PVC
|
|
|
|
k8s:
|
|
|
|
state: present
|
|
|
|
inline: &pvc
|
|
|
|
apiVersion: v1
|
|
|
|
kind: PersistentVolumeClaim
|
|
|
|
metadata:
|
|
|
|
name: elastic-volume
|
|
|
|
namespace: testing
|
|
|
|
spec:
|
|
|
|
resources:
|
|
|
|
requests:
|
|
|
|
storage: 5Gi
|
|
|
|
accessModes:
|
|
|
|
- ReadWriteOnce
|
|
|
|
|
|
|
|
- name: Show output
|
|
|
|
debug:
|
|
|
|
var: output
|
|
|
|
|
|
|
|
- name: Create the PVC again
|
|
|
|
k8s:
|
|
|
|
state: present
|
|
|
|
inline: *pvc
|
|
|
|
|
|
|
|
- name: PVC creation should be idempotent
|
|
|
|
assert:
|
|
|
|
that: not output.changed
|
|
|
|
|
|
|
|
- name: Create deployment
|
|
|
|
k8s:
|
|
|
|
state: present
|
|
|
|
inline: &deployment
|
2018-10-12 11:11:48 +02:00
|
|
|
apiVersion: extensions/v1beta1
|
2018-08-31 02:42:47 +02:00
|
|
|
kind: Deployment
|
|
|
|
metadata:
|
|
|
|
name: elastic
|
2018-05-30 19:04:48 +02:00
|
|
|
labels:
|
|
|
|
app: galaxy
|
|
|
|
service: elastic
|
2018-08-31 02:42:47 +02:00
|
|
|
namespace: testing
|
2018-05-30 19:04:48 +02:00
|
|
|
spec:
|
2018-08-31 02:42:47 +02:00
|
|
|
template:
|
|
|
|
metadata:
|
|
|
|
labels:
|
|
|
|
app: galaxy
|
|
|
|
service: elastic
|
|
|
|
spec:
|
|
|
|
containers:
|
|
|
|
- name: elastic
|
|
|
|
volumeMounts:
|
|
|
|
- mountPath: /usr/share/elasticsearch/data
|
|
|
|
name: elastic-volume
|
|
|
|
command: ['elasticsearch']
|
|
|
|
image: 'ansible/galaxy-elasticsearch:2.4.6'
|
|
|
|
volumes:
|
|
|
|
- name: elastic-volume
|
|
|
|
persistentVolumeClaim:
|
|
|
|
claimName: elastic-volume
|
|
|
|
replicas: 1
|
|
|
|
strategy:
|
|
|
|
type: RollingUpdate
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: Show output
|
|
|
|
debug:
|
|
|
|
var: output
|
|
|
|
|
|
|
|
- name: Create deployment again
|
|
|
|
k8s:
|
|
|
|
state: present
|
|
|
|
inline: *deployment
|
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: Deployment creation should be idempotent
|
|
|
|
assert:
|
|
|
|
that: not output.changed
|
|
|
|
|
2018-11-13 13:50:15 +01:00
|
|
|
- debug:
|
|
|
|
var: k8s_openshift
|
2018-08-31 02:42:47 +02:00
|
|
|
|
2018-11-13 13:50:15 +01:00
|
|
|
- include: openshift.yml
|
|
|
|
when: k8s_openshift | bool
|
2018-08-31 02:42:47 +02:00
|
|
|
|
|
|
|
### Type tests
|
|
|
|
- name: Create a namespace from a string
|
|
|
|
k8s:
|
|
|
|
definition: |+
|
|
|
|
---
|
|
|
|
kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing1
|
|
|
|
|
|
|
|
- name: Namespace should exist
|
2019-05-27 18:17:42 +02:00
|
|
|
k8s_info:
|
2018-08-31 02:42:47 +02:00
|
|
|
kind: Namespace
|
|
|
|
api_version: v1
|
2018-07-09 15:33:16 +02:00
|
|
|
name: testing1
|
2019-05-27 18:17:42 +02:00
|
|
|
register: k8s_info_testing1
|
|
|
|
failed_when: not k8s_info_testing1.resources or k8s_info_testing1.resources[0].status.phase != "Active"
|
2018-08-31 02:42:47 +02:00
|
|
|
|
|
|
|
- name: Create resources from a multidocument yaml string
|
|
|
|
k8s:
|
|
|
|
definition: |+
|
|
|
|
---
|
|
|
|
kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing2
|
|
|
|
---
|
|
|
|
kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing3
|
|
|
|
|
|
|
|
- name: Lookup namespaces
|
2019-05-27 18:17:42 +02:00
|
|
|
k8s_info:
|
2018-08-31 02:42:47 +02:00
|
|
|
api_version: v1
|
|
|
|
kind: Namespace
|
|
|
|
name: "{{ item }}"
|
|
|
|
loop:
|
|
|
|
- testing2
|
|
|
|
- testing3
|
|
|
|
register: k8s_namespaces
|
|
|
|
|
|
|
|
- name: Resources should exist
|
|
|
|
assert:
|
|
|
|
that: item.resources[0].status.phase == 'Active'
|
|
|
|
loop: "{{ k8s_namespaces.results }}"
|
|
|
|
|
|
|
|
- name: Delete resources from a multidocument yaml string
|
|
|
|
k8s:
|
|
|
|
state: absent
|
|
|
|
definition: |+
|
|
|
|
---
|
|
|
|
kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing2
|
|
|
|
---
|
|
|
|
kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing3
|
|
|
|
|
|
|
|
- name: Lookup namespaces
|
2019-05-27 18:17:42 +02:00
|
|
|
k8s_info:
|
2018-08-31 02:42:47 +02:00
|
|
|
api_version: v1
|
|
|
|
kind: Namespace
|
|
|
|
name: "{{ item }}"
|
|
|
|
loop:
|
|
|
|
- testing2
|
|
|
|
- testing3
|
|
|
|
register: k8s_namespaces
|
|
|
|
|
|
|
|
- name: Resources should not exist
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- not item.resources or item.resources[0].status.phase == "Terminating"
|
|
|
|
loop: "{{ k8s_namespaces.results }}"
|
|
|
|
|
|
|
|
- name: Create resources from a list
|
|
|
|
k8s:
|
|
|
|
definition:
|
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing4
|
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing5
|
|
|
|
|
|
|
|
- name: Lookup namespaces
|
2019-05-27 18:17:42 +02:00
|
|
|
k8s_info:
|
2018-08-31 02:42:47 +02:00
|
|
|
api_version: v1
|
|
|
|
kind: Namespace
|
|
|
|
name: "{{ item }}"
|
|
|
|
loop:
|
|
|
|
- testing4
|
|
|
|
- testing5
|
|
|
|
register: k8s_namespaces
|
|
|
|
|
|
|
|
- name: Resources should exist
|
|
|
|
assert:
|
|
|
|
that: item.resources[0].status.phase == 'Active'
|
|
|
|
loop: "{{ k8s_namespaces.results }}"
|
|
|
|
|
|
|
|
- name: Delete resources from a list
|
|
|
|
k8s:
|
|
|
|
state: absent
|
|
|
|
definition:
|
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing4
|
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing5
|
|
|
|
|
2019-05-27 18:17:42 +02:00
|
|
|
- k8s_info:
|
2018-08-31 02:42:47 +02:00
|
|
|
api_version: v1
|
|
|
|
kind: Namespace
|
|
|
|
name: "{{ item }}"
|
|
|
|
loop:
|
|
|
|
- testing4
|
|
|
|
- testing5
|
2019-05-27 18:17:42 +02:00
|
|
|
register: k8s_info
|
2018-08-31 02:42:47 +02:00
|
|
|
|
2018-11-22 09:14:43 +01:00
|
|
|
|
2018-08-31 02:42:47 +02:00
|
|
|
- name: Resources are terminating if still in results
|
|
|
|
assert:
|
|
|
|
that: not item.resources or item.resources[0].status.phase == "Terminating"
|
2019-05-27 18:17:42 +02:00
|
|
|
loop: "{{ k8s_info.results }}"
|
2018-08-31 02:42:47 +02:00
|
|
|
|
2018-11-13 13:50:15 +01:00
|
|
|
- include_tasks: crd.yml
|
2019-02-23 03:10:42 +01:00
|
|
|
- include_tasks: lists.yml
|
2018-11-22 09:14:43 +01:00
|
|
|
- include_tasks: append_hash.yml
|
2018-11-13 13:50:15 +01:00
|
|
|
|
2018-08-31 02:42:47 +02:00
|
|
|
always:
|
|
|
|
- name: Delete all namespaces
|
|
|
|
k8s:
|
|
|
|
state: absent
|
|
|
|
definition:
|
2018-11-13 13:50:15 +01:00
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing
|
2018-08-31 02:42:47 +02:00
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing1
|
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing2
|
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing3
|
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing4
|
|
|
|
- kind: Namespace
|
|
|
|
apiVersion: v1
|
|
|
|
metadata:
|
|
|
|
name: testing5
|
|
|
|
ignore_errors: yes
|