Skip to content
This repository was archived by the owner on Nov 18, 2020. It is now read-only.

Commit a7311f1

Browse files
upgrade ansible sample to use sdk 0.16 (#118)
* upgrade ansible sample to use sdk 0.16
1 parent 0d98e8c commit a7311f1

24 files changed

Lines changed: 323 additions & 86 deletions

File tree

ansible/memcached-operator/.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sudo: required
1+
---
22
services: docker
33
language: python
44
install:

ansible/memcached-operator/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,10 @@ To uninstall all that was performed in the above step run `make uninstall`.
8181
Use the following command to check the operator logs.
8282

8383
```
84-
kubectl logs deployment.apps/memcached-operator -c operator -n memcached
84+
kubectl logs deployment.apps/memcached-operator -n memcached
8585
```
8686

87-
Use the following command to check the Ansible logs.
88-
89-
```
90-
kubectl logs deployment.apps/memcached-operator -c ansible -n memcached
91-
```
87+
**NOTE:** This project is configured with the environment variable `ANSIBLE_DEBUG_LOGS` as `True`, however, note that it is `False` by default.
9288

9389
**NOTE** To have further information about how to develop Ansible operators with [Operator-SDK][operator_sdk] check the [Ansible User Guide for Operator-SDK][ansible-guide]
9490

ansible/memcached-operator/build/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
FROM quay.io/operator-framework/ansible-operator:v0.15.2
1+
FROM quay.io/operator-framework/ansible-operator:v0.16.0
2+
3+
COPY requirements.yml ${HOME}/requirements.yml
4+
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
5+
&& chmod -R ug+rwx ${HOME}/.ansible
26

37
COPY watches.yaml ${HOME}/watches.yaml
48

ansible/memcached-operator/deploy/operator.yaml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: apps/v1
23
kind: Deployment
34
metadata:
@@ -14,19 +15,7 @@ spec:
1415
spec:
1516
serviceAccountName: memcached-operator
1617
containers:
17-
- name: ansible
18-
command:
19-
- /usr/local/bin/ao-logs
20-
- /tmp/ansible-operator/runner
21-
- stdout
22-
# Replace this with the built image name
23-
image: "REPLACE_IMAGE"
24-
imagePullPolicy: "Always"
25-
volumeMounts:
26-
- mountPath: /tmp/ansible-operator/runner
27-
name: runner
28-
readOnly: true
29-
- name: operator
18+
- name: memcached-operator
3019
# Replace this with the built image name
3120
image: "REPLACE_IMAGE"
3221
imagePullPolicy: "Always"
@@ -48,6 +37,8 @@ spec:
4837
value: explicit
4938
- name: ANSIBLE_VERBOSITY
5039
value: "4"
40+
- name: ANSIBLE_DEBUG_LOGS
41+
value: "True"
5142
volumes:
5243
- name: runner
5344
emptyDir: {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Create
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
tasks: []
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
- name: Destroy
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
no_log: "{{ molecule_no_log }}"
7+
collections:
8+
- community.kubernetes
9+
10+
tasks:
11+
- name: Delete namespace
12+
k8s:
13+
api_version: v1
14+
kind: Namespace
15+
name: '{{ namespace }}'
16+
state: absent
17+
wait: yes
18+
19+
- name: Delete RBAC resources
20+
k8s:
21+
definition: "{{ lookup('template', '/'.join([deploy_dir, item])) }}"
22+
namespace: '{{ namespace }}'
23+
state: absent
24+
wait: yes
25+
with_items:
26+
- role.yaml
27+
- role_binding.yaml
28+
- service_account.yaml
29+
30+
- name: Delete Custom Resource Definition
31+
k8s:
32+
definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/cache.example.com_memcacheds_crd.yaml'])) }}"
33+
state: absent
34+
wait: yes
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: delegated
6+
lint:
7+
name: yamllint
8+
options:
9+
config-data:
10+
line-length:
11+
max: 120
12+
platforms:
13+
- name: cluster
14+
groups:
15+
- k8s
16+
provisioner:
17+
name: ansible
18+
lint:
19+
name: ansible-lint
20+
inventory:
21+
group_vars:
22+
all:
23+
namespace: ${TEST_NAMESPACE:-osdk-test}
24+
host_vars:
25+
localhost:
26+
ansible_python_interpreter: '{{ ansible_playbook_python }}'
27+
deploy_dir: ${MOLECULE_PROJECT_DIRECTORY}/deploy
28+
template_dir: ${MOLECULE_PROJECT_DIRECTORY}/molecule/templates
29+
operator_image: ${OPERATOR_IMAGE:-""}
30+
operator_pull_policy: ${OPERATOR_PULL_POLICY:-"Always"}
31+
env:
32+
K8S_AUTH_KUBECONFIG: ${KUBECONFIG:-"~/.kube/config"}
33+
verifier:
34+
name: ansible
35+
lint:
36+
name: ansible-lint
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
- name: Converge
3+
hosts: localhost
4+
connection: local
5+
gather_facts: no
6+
collections:
7+
- community.kubernetes
8+
9+
tasks:
10+
- name: Ensure operator image is set
11+
fail:
12+
msg: |
13+
You must specify the OPERATOR_IMAGE environment variable in order to run the
14+
'cluster' scenario
15+
when: not operator_image
16+
17+
- name: Create the Operator Deployment
18+
k8s:
19+
namespace: '{{ namespace }}'
20+
definition: "{{ lookup('template', '/'.join([template_dir, 'operator.yaml.j2'])) }}"
21+
wait: yes
22+
vars:
23+
image: '{{ operator_image }}'
24+
pull_policy: '{{ operator_pull_policy }}'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
- name: Prepare
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
no_log: "{{ molecule_no_log }}"
7+
collections:
8+
- community.kubernetes
9+
10+
vars:
11+
deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy"
12+
13+
tasks:
14+
- name: Create Custom Resource Definition
15+
k8s:
16+
definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/cache.example.com_memcacheds_crd.yaml'])) }}"
17+
18+
- name: Create namespace
19+
k8s:
20+
api_version: v1
21+
kind: Namespace
22+
name: '{{ namespace }}'
23+
24+
- name: Create RBAC resources
25+
k8s:
26+
definition: "{{ lookup('template', '/'.join([deploy_dir, item])) }}"
27+
namespace: '{{ namespace }}'
28+
with_items:
29+
- role.yaml
30+
- role_binding.yaml
31+
- service_account.yaml
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
# This is an example playbook to execute Ansible tests.
3+
- name: Verify
4+
hosts: localhost
5+
connection: local
6+
gather_facts: no
7+
collections:
8+
- community.kubernetes
9+
10+
vars:
11+
custom_resource: "{{ lookup('template', '/'.join([deploy_dir, 'crds/cache.example.com_v1alpha1_memcached_cr.yaml'])) | from_yaml }}"
12+
13+
tasks:
14+
- name: Create the cache.example.com/v1alpha1.Memcached and wait for reconciliation to complete
15+
k8s:
16+
state: present
17+
namespace: '{{ namespace }}'
18+
definition: '{{ custom_resource }}'
19+
wait: yes
20+
wait_timeout: 300
21+
wait_condition:
22+
type: Running
23+
reason: Successful
24+
status: "True"
25+
26+
- name: Get Pods
27+
k8s_info:
28+
api_version: v1
29+
kind: Pod
30+
namespace: '{{ namespace }}'
31+
register: pods
32+
33+
- name: Example assertion
34+
assert:
35+
that: (pods | length) > 0

0 commit comments

Comments
 (0)