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

Commit dde0c6c

Browse files
Upgrade Ansible Sample to use 0.17 (#119)
1 parent 47e5d45 commit dde0c6c

File tree

9 files changed

+106
-55
lines changed

9 files changed

+106
-55
lines changed

ansible/memcached-operator/.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
services: docker
33
language: python
44
install:
5-
- pip3 install docker molecule openshift jmespath
5+
- pip3 install docker molecule ansible-lint yamllint flake8 openshift jmespath
66
script:
77
- molecule test -s test-local

ansible/memcached-operator/build/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM quay.io/operator-framework/ansible-operator:v0.16.0
1+
FROM quay.io/operator-framework/ansible-operator:v0.17.0
22

33
COPY requirements.yml ${HOME}/requirements.yml
44
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
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 }}'

ansible/memcached-operator/molecule/cluster/molecule.yml

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@ dependency:
33
name: galaxy
44
driver:
55
name: delegated
6-
lint:
7-
name: yamllint
8-
options:
9-
config-data:
10-
line-length:
11-
max: 120
6+
lint: |
7+
set -e
8+
yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" .
129
platforms:
1310
- name: cluster
1411
groups:
1512
- k8s
1613
provisioner:
1714
name: ansible
18-
lint:
19-
name: ansible-lint
15+
lint: |
16+
set -e
17+
ansible-lint
2018
inventory:
2119
group_vars:
2220
all:
23-
namespace: ${TEST_NAMESPACE:-osdk-test}
21+
namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test}
2422
host_vars:
2523
localhost:
2624
ansible_python_interpreter: '{{ ansible_playbook_python }}'
@@ -32,5 +30,6 @@ provisioner:
3230
K8S_AUTH_KUBECONFIG: ${KUBECONFIG:-"~/.kube/config"}
3331
verifier:
3432
name: ansible
35-
lint:
36-
name: ansible-lint
33+
lint: |
34+
set -e
35+
ansible-lint
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Converge
3+
hosts: localhost
4+
connection: local
5+
roles:
6+
- memcached

ansible/memcached-operator/molecule/default/molecule.yml

+12-18
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@ dependency:
33
name: galaxy
44
driver:
55
name: docker
6-
lint:
7-
name: yamllint
8-
enabled: False
9-
options:
10-
config-data:
11-
line-length:
12-
max: 120
13-
6+
lint: |
7+
set -e
8+
yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" .
149
platforms:
1510
- name: kind-default
1611
groups:
1712
- k8s
18-
image: bsycorp/kind:latest-${KUBE_VERSION:-1.16}
13+
image: bsycorp/kind:latest-${KUBE_VERSION:-1.17}
1914
privileged: True
2015
override_command: no
2116
exposed_ports:
@@ -27,13 +22,13 @@ platforms:
2722
provisioner:
2823
name: ansible
2924
log: True
30-
lint:
31-
name: ansible-lint
32-
enabled: False
25+
lint: |
26+
set -e
27+
ansible-lint
3328
inventory:
3429
group_vars:
3530
all:
36-
namespace: ${TEST_NAMESPACE:-osdk-test}
31+
namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test}
3732
kubeconfig_file: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig
3833
host_vars:
3934
localhost:
@@ -43,9 +38,8 @@ provisioner:
4338
KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig
4439
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles
4540
KIND_PORT: '${TEST_CLUSTER_PORT:-9443}'
46-
scenario:
47-
name: default
4841
verifier:
49-
name: testinfra
50-
lint:
51-
name: flake8
42+
name: ansible
43+
lint: |
44+
set -e
45+
ansible-lint

ansible/memcached-operator/molecule/default/prepare.yml

+2-10
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,18 @@
22
- name: Prepare
33
hosts: k8s
44
gather_facts: no
5-
vars:
6-
kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}"
75
tasks:
8-
- name: delete the kubeconfig if present
9-
file:
10-
path: '{{ kubeconfig }}'
11-
state: absent
12-
delegate_to: localhost
13-
146
- name: Fetch the kubeconfig
157
fetch:
16-
dest: '{{ kubeconfig }}'
8+
dest: '{{ kubeconfig_file }}'
179
flat: yes
1810
src: /root/.kube/config
1911

2012
- name: Change the kubeconfig port to the proper value
2113
replace:
2214
regexp: '8443'
2315
replace: "{{ lookup('env', 'KIND_PORT') }}"
24-
path: '{{ kubeconfig }}'
16+
path: '{{ kubeconfig_file }}'
2517
delegate_to: localhost
2618

2719
- name: Wait for the Kubernetes API to become available (this could take a minute)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
- name: Build Operator in Kubernetes docker container
3+
hosts: k8s
4+
collections:
5+
- community.kubernetes
6+
7+
vars:
8+
image: cache.example.com/memcached-operator:testing
9+
10+
tasks:
11+
# using command so we don't need to install any dependencies
12+
- name: Get existing image hash
13+
command: docker images -q {{ image }}
14+
register: prev_hash_raw
15+
changed_when: false
16+
17+
- name: Build Operator Image
18+
command: docker build -f /build/build/Dockerfile -t {{ image }} /build
19+
register: build_cmd
20+
changed_when: not hash or (hash and hash not in cmd_out)
21+
vars:
22+
hash: '{{ prev_hash_raw.stdout }}'
23+
cmd_out: '{{ "".join(build_cmd.stdout_lines[-2:]) }}'
24+
25+
- name: Converge
26+
hosts: localhost
27+
connection: local
28+
collections:
29+
- community.kubernetes
30+
31+
vars:
32+
image: cache.example.com/memcached-operator:testing
33+
operator_template: "{{ '/'.join([template_dir, 'operator.yaml.j2']) }}"
34+
35+
tasks:
36+
- name: Create the Operator Deployment
37+
k8s:
38+
namespace: '{{ namespace }}'
39+
definition: "{{ lookup('template', operator_template) }}"
40+
wait: yes
41+
vars:
42+
pull_policy: Never

ansible/memcached-operator/molecule/test-local/molecule.yml

+8-14
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@ dependency:
33
name: galaxy
44
driver:
55
name: docker
6-
lint:
7-
name: yamllint
8-
enabled: False
9-
options:
10-
config-data:
11-
line-length:
12-
max: 120
13-
6+
lint: |
7+
set -e
8+
yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" .
149
platforms:
1510
- name: kind-test-local
1611
groups:
1712
- k8s
18-
image: bsycorp/kind:latest-${KUBE_VERSION:-1.16}
13+
image: bsycorp/kind:latest-${KUBE_VERSION:-1.17}
1914
privileged: true
2015
override_command: false
2116
exposed_ports:
@@ -28,14 +23,13 @@ platforms:
2823
- ${MOLECULE_PROJECT_DIRECTORY}:/build:Z
2924
provisioner:
3025
name: ansible
31-
log: True
26+
log: true
3227
lint:
3328
name: ansible-lint
34-
enabled: False
3529
inventory:
3630
group_vars:
3731
all:
38-
namespace: ${TEST_NAMESPACE:-osdk-test}
32+
namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test}
3933
kubeconfig_file: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig
4034
host_vars:
4135
localhost:
@@ -61,6 +55,6 @@ scenario:
6155
- verify
6256
- destroy
6357
verifier:
64-
name: testinfra
58+
name: ansible
6559
lint:
66-
name: flake8
60+
name: ansible-lint

0 commit comments

Comments
 (0)