Merge pull request #32 from ansible-collections/30-molecule-3

Test with Molecule 3.0 alpha release.
This commit is contained in:
Jeff Geerling
2020-02-20 10:54:10 -06:00
committed by GitHub
21 changed files with 267 additions and 246 deletions

View File

@@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python_version: ["3.6"] python_version: ['3.6']
steps: steps:
- name: Check out code - name: Check out code
uses: actions/checkout@v1 uses: actions/checkout@v1
@@ -36,7 +36,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python_version: ["3.6"] python_version: ['3.6']
steps: steps:
- name: Check out code - name: Check out code
uses: actions/checkout@v1 uses: actions/checkout@v1
@@ -61,7 +61,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python_version: ['3.7'] python_version: ['3.7']
steps: steps:
- name: Check out code - name: Check out code
uses: actions/checkout@v1 uses: actions/checkout@v1
@@ -77,7 +77,7 @@ jobs:
python-version: ${{ matrix.python_version }} python-version: ${{ matrix.python_version }}
- name: Install molecule and openshift dependencies - name: Install molecule and openshift dependencies
run: pip install molecule openshift run: pip install molecule yamllint openshift
- name: Install ansible-base - name: Install ansible-base
run: pip install git+https://github.com/ansible-collection-migration/ansible-base.git --disable-pip-version-check run: pip install git+https://github.com/ansible-collection-migration/ansible-base.git --disable-pip-version-check

12
.yamllint Normal file
View File

@@ -0,0 +1,12 @@
---
extends: default
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
line-length: disable
truthy: disable

View File

@@ -6,12 +6,8 @@ driver:
login_cmd_template: 'docker exec -ti {instance} bash' login_cmd_template: 'docker exec -ti {instance} bash'
ansible_connection_options: ansible_connection_options:
ansible_connection: docker ansible_connection: docker
lint: lint: |
name: yamllint yamllint .
options:
config-data:
line-length:
max: 160
platforms: platforms:
- name: instance-kind - name: instance-kind
provisioner: provisioner:
@@ -27,6 +23,7 @@ provisioner:
scenario: scenario:
name: default name: default
test_sequence: test_sequence:
- lint
- syntax - syntax
- converge - converge
- verify - verify

View File

@@ -1,3 +1,4 @@
---
- block: - block:
- name: Ensure that append_hash namespace exists - name: Ensure that append_hash namespace exists
k8s: k8s:

View File

@@ -88,8 +88,8 @@
- not pods_delete.resources - not pods_delete.resources
always: always:
- name: Remove namespace - name: Remove namespace
k8s: k8s:
kind: Namespace kind: Namespace
name: "{{ delete_namespace }}" name: "{{ delete_namespace }}"
state: absent state: absent

View File

@@ -54,10 +54,10 @@
app: galaxy app: galaxy
service: web service: web
ports: ports:
- protocol: TCP - protocol: TCP
targetPort: 8000 targetPort: 8000
name: port-8000-tcp name: port-8000-tcp
port: 8000 port: 8000
register: output register: output
- name: Show output - name: Show output
@@ -107,7 +107,7 @@
requests: requests:
storage: 5Gi storage: 5Gi
accessModes: accessModes:
- ReadWriteOnce - ReadWriteOnce
- name: Show output - name: Show output
debug: debug:
@@ -149,14 +149,14 @@
containers: containers:
- name: elastic - name: elastic
volumeMounts: volumeMounts:
- mountPath: /usr/share/elasticsearch/data - mountPath: /usr/share/elasticsearch/data
name: elastic-volume name: elastic-volume
command: ['elasticsearch'] command: ['elasticsearch']
image: 'ansible/galaxy-elasticsearch:2.4.6' image: 'ansible/galaxy-elasticsearch:2.4.6'
volumes: volumes:
- name: elastic-volume - name: elastic-volume
persistentVolumeClaim: persistentVolumeClaim:
claimName: elastic-volume claimName: elastic-volume
strategy: strategy:
type: RollingUpdate type: RollingUpdate
register: output register: output

View File

@@ -1,5 +1,4 @@
--- ---
- name: Ensure testing1 namespace exists - name: Ensure testing1 namespace exists
k8s: k8s:
api_version: v1 api_version: v1
@@ -7,134 +6,134 @@
name: testing1 name: testing1
- block: - block:
- name: Create configmaps - name: Create configmaps
k8s: k8s:
namespace: testing1 namespace: testing1
definition: definition:
apiVersion: v1 apiVersion: v1
kind: ConfigMapList kind: ConfigMapList
items: '{{ configmaps }}' items: '{{ configmaps }}'
- name: Get ConfigMaps - name: Get ConfigMaps
k8s_info: k8s_info:
api_version: v1 api_version: v1
kind: ConfigMap kind: ConfigMap
namespace: testing1 namespace: testing1
label_selectors: label_selectors:
- app=test - app=test
register: cms register: cms
- name: All three configmaps should exist - name: All three configmaps should exist
assert: assert:
that: item.data.a is defined that: item.data.a is defined
with_items: '{{ cms.resources }}' with_items: '{{ cms.resources }}'
- name: Delete configmaps - name: Delete configmaps
k8s: k8s:
state: absent state: absent
namespace: testing1 namespace: testing1
definition: definition:
apiVersion: v1 apiVersion: v1
kind: ConfigMapList kind: ConfigMapList
items: '{{ configmaps }}' items: '{{ configmaps }}'
- name: Get ConfigMaps - name: Get ConfigMaps
k8s_info: k8s_info:
api_version: v1 api_version: v1
kind: ConfigMap kind: ConfigMap
namespace: testing1 namespace: testing1
label_selectors: label_selectors:
- app=test - app=test
register: cms register: cms
- name: All three configmaps should not exist - name: All three configmaps should not exist
assert: assert:
that: not cms.resources that: not cms.resources
vars: vars:
configmaps: configmaps:
- metadata: - metadata:
name: list-example-1 name: list-example-1
labels: labels:
app: test app: test
data: data:
a: first a: first
- metadata: - metadata:
name: list-example-2 name: list-example-2
labels: labels:
app: test app: test
data: data:
a: second a: second
- metadata: - metadata:
name: list-example-3 name: list-example-3
labels: labels:
app: test app: test
data: data:
a: third a: third
- block: - block:
- name: Create list of arbitrary resources - name: Create list of arbitrary resources
k8s: k8s:
namespace: testing1
definition:
apiVersion: v1
kind: List
namespace: testing1 namespace: testing1
items: '{{ resources }}' definition:
apiVersion: v1
kind: List
namespace: testing1
items: '{{ resources }}'
- name: Get the created resources - name: Get the created resources
k8s_info: k8s_info:
api_version: '{{ item.apiVersion }}' api_version: '{{ item.apiVersion }}'
kind: '{{ item.kind }}' kind: '{{ item.kind }}'
namespace: testing1
name: '{{ item.metadata.name }}'
register: list_resources
with_items: '{{ resources }}'
- name: All resources should exist
assert:
that: ((list_resources.results | sum(attribute="resources", start=[])) | length) == (resources | length)
- name: Delete list of arbitrary resources
k8s:
state: absent
namespace: testing1
definition:
apiVersion: v1
kind: List
namespace: testing1 namespace: testing1
items: '{{ resources }}' name: '{{ item.metadata.name }}'
register: list_resources
with_items: '{{ resources }}'
- name: Get the resources - name: All resources should exist
k8s_info: assert:
api_version: '{{ item.apiVersion }}' that: ((list_resources.results | sum(attribute="resources", start=[])) | length) == (resources | length)
kind: '{{ item.kind }}'
namespace: testing1
name: '{{ item.metadata.name }}'
register: list_resources
with_items: '{{ resources }}'
- name: The resources should not exist - name: Delete list of arbitrary resources
assert: k8s:
that: not ((list_resources.results | sum(attribute="resources", start=[])) | length) state: absent
namespace: testing1
definition:
apiVersion: v1
kind: List
namespace: testing1
items: '{{ resources }}'
- name: Get the resources
k8s_info:
api_version: '{{ item.apiVersion }}'
kind: '{{ item.kind }}'
namespace: testing1
name: '{{ item.metadata.name }}'
register: list_resources
with_items: '{{ resources }}'
- name: The resources should not exist
assert:
that: not ((list_resources.results | sum(attribute="resources", start=[])) | length)
vars: vars:
resources: resources:
- apiVersion: v1 - apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: list-example-4 name: list-example-4
data: data:
key: value key: value
- apiVersion: v1 - apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: list-example-svc name: list-example-svc
labels: labels:
app: test app: test
spec: spec:
selector: selector:
app: test app: test
ports: ports:
- protocol: TCP - protocol: TCP
targetPort: 8000 targetPort: 8000
name: port-8000-tcp name: port-8000-tcp
port: 8000 port: 8000

View File

@@ -24,10 +24,10 @@
app: hello-world app: hello-world
spec: spec:
containers: containers:
- image: busybox - image: busybox
name: hello-world name: hello-world
command: ['sh'] command: ['sh']
args: ['-c', 'while true ; do echo "hello world" && sleep 10 ; done'] args: ['-c', 'while true ; do echo "hello world" && sleep 10 ; done']
restartPolicy: Always restartPolicy: Always
- name: retrieve the log by providing the deployment - name: retrieve the log by providing the deployment

View File

@@ -1,3 +1,4 @@
---
apiVersion: certmanager.k8s.io/v1alpha1 apiVersion: certmanager.k8s.io/v1alpha1
kind: Certificate kind: Certificate
metadata: metadata:
@@ -5,14 +6,14 @@ metadata:
spec: spec:
secretName: acme-crt-secret secretName: acme-crt-secret
dnsNames: dnsNames:
- foo.example.com - foo.example.com
- bar.example.com - bar.example.com
acme: acme:
config: config:
- ingressClass: nginx - ingressClass: nginx
domains: domains:
- foo.example.com - foo.example.com
- bar.example.com - bar.example.com
issuerRef: issuerRef:
name: letsencrypt-prod name: letsencrypt-prod
# We can reference ClusterIssuers by changing the kind here. # We can reference ClusterIssuers by changing the kind here.

View File

@@ -1,3 +1,4 @@
---
apiVersion: extensions/v1beta1 apiVersion: extensions/v1beta1
kind: Deployment kind: Deployment
metadata: metadata:
@@ -17,5 +18,5 @@ spec:
app: kuard app: kuard
spec: spec:
containers: containers:
- image: gcr.io/kuar-demo/kuard-amd64:1 - image: gcr.io/kuar-demo/kuard-amd64:1
name: kuard name: kuard

View File

@@ -1,3 +1,4 @@
---
apiVersion: extensions/v1beta1 apiVersion: extensions/v1beta1
kind: Deployment kind: Deployment
metadata: metadata:
@@ -16,5 +17,5 @@ spec:
app: kuard app: kuard
spec: spec:
containers: containers:
- image: gcr.io/kuar-demo/kuard-amd64:1 - image: gcr.io/kuar-demo/kuard-amd64:1
name: kuard name: kuard

View File

@@ -1,3 +1,4 @@
---
apiVersion: apiextensions.k8s.io/v1beta1 apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition kind: CustomResourceDefinition
metadata: metadata:

View File

@@ -1,3 +1,4 @@
---
- name: delete temporary directory - name: delete temporary directory
file: file:
path: "{{ remote_tmp_dir }}" path: "{{ remote_tmp_dir }}"

View File

@@ -1 +1,2 @@
---
dependencies: [] dependencies: []

View File

@@ -1,3 +1,4 @@
---
- include_tasks: setup_remote_tmp_dir.yml - include_tasks: setup_remote_tmp_dir.yml
- set_fact: - set_fact:

View File

@@ -1,70 +1,71 @@
# TODO: Not available in ansible-base ---
# - python_requirements_info: # TODO: Not available in ansible-base
# dependencies: # - python_requirements_info:
# - openshift==0.6.0 # dependencies:
# - kubernetes==6.0.0 # - openshift==0.6.0
# - kubernetes==6.0.0
# append_hash # append_hash
- name: use append_hash with ConfigMap - name: use append_hash with ConfigMap
k8s: k8s:
definition: definition:
metadata: metadata:
name: config-map-test name: config-map-test
namespace: "{{ playbook_namespace }}" namespace: "{{ playbook_namespace }}"
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
data: data:
hello: world hello: world
append_hash: yes append_hash: yes
ignore_errors: yes ignore_errors: yes
register: k8s_append_hash register: k8s_append_hash
- name: assert that append_hash fails gracefully - name: assert that append_hash fails gracefully
assert: assert:
that: that:
- k8s_append_hash is failed - k8s_append_hash is failed
- "'Failed to import the required Python library (openshift >= 0.7.2)' in k8s_append_hash.msg" - "'Failed to import the required Python library (openshift >= 0.7.2)' in k8s_append_hash.msg"
- "'. This is required for append_hash.' in k8s_append_hash.msg" - "'. This is required for append_hash.' in k8s_append_hash.msg"
# validate # validate
- name: attempt to use validate with older openshift - name: attempt to use validate with older openshift
k8s: k8s:
definition: definition:
metadata: metadata:
name: config-map-test name: config-map-test
namespace: "{{ playbook_namespace }}" namespace: "{{ playbook_namespace }}"
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
data: data:
hello: world hello: world
validate: validate:
fail_on_error: yes fail_on_error: yes
ignore_errors: yes ignore_errors: yes
register: k8s_validate register: k8s_validate
- name: assert that validate fails gracefully - name: assert that validate fails gracefully
assert: assert:
that: that:
- k8s_validate is failed - k8s_validate is failed
- "k8s_validate.msg == 'openshift >= 0.8.0 is required for validate'" - "k8s_validate.msg == 'openshift >= 0.8.0 is required for validate'"
# apply # apply
- name: attempt to use apply with older openshift - name: attempt to use apply with older openshift
k8s: k8s:
definition: definition:
metadata: metadata:
name: config-map-test name: config-map-test
namespace: "{{ playbook_namespace }}" namespace: "{{ playbook_namespace }}"
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
data: data:
hello: world hello: world
apply: yes apply: yes
ignore_errors: yes ignore_errors: yes
register: k8s_apply register: k8s_apply
- name: assert that apply fails gracefully - name: assert that apply fails gracefully
assert: assert:
that: that:
- k8s_apply is failed - k8s_apply is failed
- "k8s_apply.msg.startswith('Failed to import the required Python library (openshift >= 0.9.2)')" - "k8s_apply.msg.startswith('Failed to import the required Python library (openshift >= 0.9.2)')"

View File

@@ -1,3 +1,4 @@
---
# OpenShift Resources # OpenShift Resources
- name: Create a project - name: Create a project
k8s: k8s:
@@ -33,14 +34,14 @@
containers: containers:
- name: elastic - name: elastic
volumeMounts: volumeMounts:
- mountPath: /usr/share/elasticsearch/data - mountPath: /usr/share/elasticsearch/data
name: elastic-volume name: elastic-volume
command: ['elasticsearch'] command: ['elasticsearch']
image: 'ansible/galaxy-elasticsearch:2.4.6' image: 'ansible/galaxy-elasticsearch:2.4.6'
volumes: volumes:
- name: elastic-volume - name: elastic-volume
persistentVolumeClaim: persistentVolumeClaim:
claimName: elastic-volume claimName: elastic-volume
replicas: 1 replicas: 1
strategy: strategy:
type: Rolling type: Rolling

View File

@@ -1,3 +1,4 @@
---
- name: create temporary directory - name: create temporary directory
test_tempfile: test_tempfile:
state: directory state: directory

View File

@@ -1,3 +1,4 @@
---
- block: - block:
- name: Create a namespace - name: Create a namespace
k8s: k8s:

View File

@@ -1,24 +1,25 @@
# TODO: Not available in ansible-base ---
# - python_requirements_info: # TODO: Not available in ansible-base
# dependencies: # - python_requirements_info:
# - openshift # dependencies:
# - kubernetes # - openshift
# - kubernetes-validate # - kubernetes
# - kubernetes-validate
- k8s: - k8s:
definition: definition:
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: hello name: hello
namespace: default namespace: default
validate: validate:
fail_on_error: yes fail_on_error: yes
ignore_errors: yes ignore_errors: yes
register: k8s_no_validate register: k8s_no_validate
- name: assert that k8s_no_validate fails gracefully - name: assert that k8s_no_validate fails gracefully
assert: assert:
that: that:
- k8s_no_validate is failed - k8s_no_validate is failed
- "k8s_no_validate.msg == 'kubernetes-validate python library is required to validate resources'" - "k8s_no_validate.msg == 'kubernetes-validate python library is required to validate resources'"