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

Commit

Permalink
Upgrade Ansible Sample to use 0.17 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 authored Apr 23, 2020
1 parent 47e5d45 commit dde0c6c
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 55 deletions.
2 changes: 1 addition & 1 deletion ansible/memcached-operator/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
services: docker
language: python
install:
- pip3 install docker molecule openshift jmespath
- pip3 install docker molecule ansible-lint yamllint flake8 openshift jmespath
script:
- molecule test -s test-local
2 changes: 1 addition & 1 deletion ansible/memcached-operator/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM quay.io/operator-framework/ansible-operator:v0.16.0
FROM quay.io/operator-framework/ansible-operator:v0.17.0

COPY requirements.yml ${HOME}/requirements.yml
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
Expand Down
24 changes: 24 additions & 0 deletions ansible/memcached-operator/molecule/cluster/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: Converge
hosts: localhost
connection: local
gather_facts: no
collections:
- community.kubernetes

tasks:
- name: Ensure operator image is set
fail:
msg: |
You must specify the OPERATOR_IMAGE environment variable in order to run the
'cluster' scenario
when: not operator_image

- name: Create the Operator Deployment
k8s:
namespace: '{{ namespace }}'
definition: "{{ lookup('template', '/'.join([template_dir, 'operator.yaml.j2'])) }}"
wait: yes
vars:
image: '{{ operator_image }}'
pull_policy: '{{ operator_pull_policy }}'
21 changes: 10 additions & 11 deletions ansible/memcached-operator/molecule/cluster/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ dependency:
name: galaxy
driver:
name: delegated
lint:
name: yamllint
options:
config-data:
line-length:
max: 120
lint: |
set -e
yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" .
platforms:
- name: cluster
groups:
- k8s
provisioner:
name: ansible
lint:
name: ansible-lint
lint: |
set -e
ansible-lint
inventory:
group_vars:
all:
namespace: ${TEST_NAMESPACE:-osdk-test}
namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test}
host_vars:
localhost:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
Expand All @@ -32,5 +30,6 @@ provisioner:
K8S_AUTH_KUBECONFIG: ${KUBECONFIG:-"~/.kube/config"}
verifier:
name: ansible
lint:
name: ansible-lint
lint: |
set -e
ansible-lint
6 changes: 6 additions & 0 deletions ansible/memcached-operator/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Converge
hosts: localhost
connection: local
roles:
- memcached
30 changes: 12 additions & 18 deletions ansible/memcached-operator/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
enabled: False
options:
config-data:
line-length:
max: 120

lint: |
set -e
yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" .
platforms:
- name: kind-default
groups:
- k8s
image: bsycorp/kind:latest-${KUBE_VERSION:-1.16}
image: bsycorp/kind:latest-${KUBE_VERSION:-1.17}
privileged: True
override_command: no
exposed_ports:
Expand All @@ -27,13 +22,13 @@ platforms:
provisioner:
name: ansible
log: True
lint:
name: ansible-lint
enabled: False
lint: |
set -e
ansible-lint
inventory:
group_vars:
all:
namespace: ${TEST_NAMESPACE:-osdk-test}
namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test}
kubeconfig_file: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig
host_vars:
localhost:
Expand All @@ -43,9 +38,8 @@ provisioner:
KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig
ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles
KIND_PORT: '${TEST_CLUSTER_PORT:-9443}'
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
name: ansible
lint: |
set -e
ansible-lint
12 changes: 2 additions & 10 deletions ansible/memcached-operator/molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@
- name: Prepare
hosts: k8s
gather_facts: no
vars:
kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}"
tasks:
- name: delete the kubeconfig if present
file:
path: '{{ kubeconfig }}'
state: absent
delegate_to: localhost

- name: Fetch the kubeconfig
fetch:
dest: '{{ kubeconfig }}'
dest: '{{ kubeconfig_file }}'
flat: yes
src: /root/.kube/config

- name: Change the kubeconfig port to the proper value
replace:
regexp: '8443'
replace: "{{ lookup('env', 'KIND_PORT') }}"
path: '{{ kubeconfig }}'
path: '{{ kubeconfig_file }}'
delegate_to: localhost

- name: Wait for the Kubernetes API to become available (this could take a minute)
Expand Down
42 changes: 42 additions & 0 deletions ansible/memcached-operator/molecule/test-local/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- name: Build Operator in Kubernetes docker container
hosts: k8s
collections:
- community.kubernetes

vars:
image: cache.example.com/memcached-operator:testing

tasks:
# using command so we don't need to install any dependencies
- name: Get existing image hash
command: docker images -q {{ image }}
register: prev_hash_raw
changed_when: false

- name: Build Operator Image
command: docker build -f /build/build/Dockerfile -t {{ image }} /build
register: build_cmd
changed_when: not hash or (hash and hash not in cmd_out)
vars:
hash: '{{ prev_hash_raw.stdout }}'
cmd_out: '{{ "".join(build_cmd.stdout_lines[-2:]) }}'

- name: Converge
hosts: localhost
connection: local
collections:
- community.kubernetes

vars:
image: cache.example.com/memcached-operator:testing
operator_template: "{{ '/'.join([template_dir, 'operator.yaml.j2']) }}"

tasks:
- name: Create the Operator Deployment
k8s:
namespace: '{{ namespace }}'
definition: "{{ lookup('template', operator_template) }}"
wait: yes
vars:
pull_policy: Never
22 changes: 8 additions & 14 deletions ansible/memcached-operator/molecule/test-local/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
enabled: False
options:
config-data:
line-length:
max: 120

lint: |
set -e
yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" .
platforms:
- name: kind-test-local
groups:
- k8s
image: bsycorp/kind:latest-${KUBE_VERSION:-1.16}
image: bsycorp/kind:latest-${KUBE_VERSION:-1.17}
privileged: true
override_command: false
exposed_ports:
Expand All @@ -28,14 +23,13 @@ platforms:
- ${MOLECULE_PROJECT_DIRECTORY}:/build:Z
provisioner:
name: ansible
log: True
log: true
lint:
name: ansible-lint
enabled: False
inventory:
group_vars:
all:
namespace: ${TEST_NAMESPACE:-osdk-test}
namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test}
kubeconfig_file: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig
host_vars:
localhost:
Expand All @@ -61,6 +55,6 @@ scenario:
- verify
- destroy
verifier:
name: testinfra
name: ansible
lint:
name: flake8
name: ansible-lint

0 comments on commit dde0c6c

Please sign in to comment.