Skip to content

Commit f409eb4

Browse files
e2e-tests: fix advanced molecule ansible tests (#4273)
**Description of the change:** - update advanced mock static scenario with 1.0+ layout (#3433) - (note that we need to ensure that the test works with the new layout) - Fix CI issue (blocker master): `The error was: urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='172.30.99.1', port=24443): Max retries exceeded with url: /version (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f28647cdb38>: Failed to establish a new connection: [Errno 110] Connection timed out',))` in GA. NOTE: The follow up here is to replace the test/ansible static mock with samples to ensure that we are testing it with the latest changes always. See the issue #4025 and its PR : #4312
1 parent 7a74192 commit f409eb4

File tree

88 files changed

+1225
-676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1225
-676
lines changed

Diff for: .github/workflows/test-ansible.yml

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ jobs:
4949
env
5050
export PATH=/opt/python/3.6.7/bin:${PATH}
5151
sudo apt-get install python3 python3-pip
52-
sudo pip3 install wheel
5352
sudo pip3 install --upgrade setuptools pip
5453
sudo pip3 install ansible~=2.9.13
5554
make test-e2e-ansible-molecule

Diff for: hack/tests/e2e-ansible-molecule.sh

+16-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,22 @@ else
3333
fi
3434
KUSTOMIZE_PATH=${KUSTOMIZE} TEST_OPERATOR_NAMESPACE=default molecule test -s kind
3535

36-
cd $TMPDIR
37-
KUSTOMIZE_PATH=${KUSTOMIZE}
36+
rm -rf $KUSTOMIZE
37+
cd $TMPDIR/
38+
rm -rf memcached-molecule-operator
39+
3840
header_text "Test Ansible Molecule scenarios"
3941
pushd "${ROOTDIR}/test/ansible"
40-
DEST_IMAGE="quay.io/example/ansible-test-operator:v0.0.1"
41-
sed -i".bak" -E -e 's/(FROM quay.io\/operator-framework\/ansible-operator)(:.*)?/\1:dev/g' build/Dockerfile; rm -f build/Dockerfile.bak
42-
docker build -f build/Dockerfile -t "$DEST_IMAGE" --no-cache .
42+
43+
make kustomize
44+
if [ -f ./bin/kustomize ] ; then
45+
KUSTOMIZE="$(realpath ./bin/kustomize)"
46+
else
47+
KUSTOMIZE="$(which kustomize)"
48+
fi
49+
50+
DEST_IMAGE="quay.io/example/advanced-molecule-operator:v0.0.1"
51+
sed -i".bak" -E -e 's/(FROM quay.io\/operator-framework\/ansible-operator)(:.*)?/\1:dev/g' Dockerfile; rm -f Dockerfile.bak
52+
docker build -t "$DEST_IMAGE" --no-cache .
4353
load_image_if_kind "$DEST_IMAGE"
44-
OPERATOR_PULL_POLICY=Never OPERATOR_IMAGE=${DEST_IMAGE} TEST_CLUSTER_PORT=24443 TEST_OPERATOR_NAMESPACE=osdk-test molecule test --all
54+
KUSTOMIZE_PATH=$KUSTOMIZE OPERATOR_PULL_POLICY=Never OPERATOR_IMAGE=${DEST_IMAGE} TEST_OPERATOR_NAMESPACE=osdk-test molecule test

Diff for: test/ansible/.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin
9+
10+
# editor and IDE paraphernalia
11+
.idea
12+
*.swp
13+
*.swo
14+
*~
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
FROM quay.io/operator-framework/ansible-operator:dev
1+
FROM quay.io/operator-framework/ansible-operator:v1.2.0
22

33
COPY requirements.yml ${HOME}/requirements.yml
44
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
55
&& chmod -R ug+rwx ${HOME}/.ansible
6-
COPY ansible.cfg /etc/ansible/ansible.cfg
7-
COPY watches.yaml ${HOME}/watches.yaml
86

7+
COPY watches.yaml ${HOME}/watches.yaml
98
COPY roles/ ${HOME}/roles/
109
COPY playbooks/ ${HOME}/playbooks/
10+
11+
# Customizations done to check advanced scenarios
1112
COPY inventory/ ${HOME}/inventory/
1213
COPY plugins/ ${HOME}/plugins/
14+
COPY ansible.cfg /etc/ansible/ansible.cfg
1315
COPY fixture_collection/ /tmp/fixture_collection/
1416
USER root
1517
RUN chmod -R ug+rwx /tmp/fixture_collection
1618
USER 1001
1719
RUN ansible-galaxy collection build /tmp/fixture_collection/ --output-path /tmp/fixture_collection/ \
18-
&& ansible-galaxy collection install /tmp/fixture_collection/operator_sdk-test_fixtures-0.0.0.tar.gz
20+
&& ansible-galaxy collection install /tmp/fixture_collection/operator_sdk-test_fixtures-0.0.0.tar.gz
1921
RUN echo abc123 > /opt/ansible/pwd.yml \
20-
&& ansible-vault encrypt_string --vault-password-file /opt/ansible/pwd.yml 'thisisatest' --name 'the_secret' > /opt/ansible/vars.yml
22+
&& ansible-vault encrypt_string --vault-password-file /opt/ansible/pwd.yml 'thisisatest' --name 'the_secret' > /opt/ansible/vars.yml
23+

Diff for: test/ansible/Makefile

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Current Operator version
2+
VERSION ?= 0.0.1
3+
# Default bundle image tag
4+
BUNDLE_IMG ?= controller-bundle:$(VERSION)
5+
# Options for 'bundle-build'
6+
ifneq ($(origin CHANNELS), undefined)
7+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
8+
endif
9+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
10+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
11+
endif
12+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
13+
14+
# Image URL to use all building/pushing image targets
15+
IMG ?= controller:latest
16+
17+
all: docker-build
18+
19+
# Run against the configured Kubernetes cluster in ~/.kube/config
20+
run: ansible-operator
21+
$(ANSIBLE_OPERATOR) run
22+
23+
# Install CRDs into a cluster
24+
install: kustomize
25+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
26+
27+
# Uninstall CRDs from a cluster
28+
uninstall: kustomize
29+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
30+
31+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
32+
deploy: kustomize
33+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
34+
$(KUSTOMIZE) build config/default | kubectl apply -f -
35+
36+
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
37+
undeploy: kustomize
38+
$(KUSTOMIZE) build config/default | kubectl delete -f -
39+
40+
# Build the docker image
41+
docker-build:
42+
docker build . -t ${IMG}
43+
44+
# Push the docker image
45+
docker-push:
46+
docker push ${IMG}
47+
48+
PATH := $(PATH):$(PWD)/bin
49+
SHELL := env PATH=$(PATH) /bin/sh
50+
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
51+
ARCH = $(shell uname -m | sed 's/x86_64/amd64/')
52+
OSOPER = $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/apple-darwin/' | sed 's/linux/linux-gnu/')
53+
ARCHOPER = $(shell uname -m )
54+
55+
kustomize:
56+
ifeq (, $(shell which kustomize 2>/dev/null))
57+
@{ \
58+
set -e ;\
59+
mkdir -p bin ;\
60+
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | tar xzf - -C bin/ ;\
61+
}
62+
KUSTOMIZE=$(realpath ./bin/kustomize)
63+
else
64+
KUSTOMIZE=$(shell which kustomize)
65+
endif
66+
67+
ansible-operator:
68+
ifeq (, $(shell which ansible-operator 2>/dev/null))
69+
@{ \
70+
set -e ;\
71+
mkdir -p bin ;\
72+
curl -LO https://github.com/operator-framework/operator-sdk/releases/download/v1.2.0/ansible-operator-v1.2.0-$(ARCHOPER)-$(OSOPER) ;\
73+
mv ansible-operator-v1.2.0-$(ARCHOPER)-$(OSOPER) ./bin/ansible-operator ;\
74+
chmod +x ./bin/ansible-operator ;\
75+
}
76+
ANSIBLE_OPERATOR=$(realpath ./bin/ansible-operator)
77+
else
78+
ANSIBLE_OPERATOR=$(shell which ansible-operator)
79+
endif
80+
81+
# Generate bundle manifests and metadata, then validate generated files.
82+
.PHONY: bundle
83+
bundle: kustomize
84+
operator-sdk generate kustomize manifests -q
85+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
86+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
87+
operator-sdk bundle validate ./bundle
88+
89+
# Build the bundle image.
90+
.PHONY: bundle-build
91+
bundle-build:
92+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

Diff for: test/ansible/OWNERS

-6
This file was deleted.

Diff for: test/ansible/PROJECT

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
domain: example.com
2+
layout: ansible.sdk.operatorframework.io/v1
3+
multigroup: true
4+
projectName: advanced-molecule-operator
5+
resources:
6+
- group: test
7+
kind: InventoryTest
8+
version: v1alpha1
9+
- group: test
10+
kind: ArgsTest
11+
version: v1alpha1
12+
- group: test
13+
kind: CaseTest
14+
version: v1alpha1
15+
- group: test
16+
kind: CollectionTest
17+
version: v1alpha1
18+
- group: test
19+
kind: SelectorTest
20+
version: v1alpha1
21+
- group: test
22+
kind: SubresourcesTest
23+
version: v1alpha1
24+
version: 3-alpha
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: argstests.test.example.com
6+
spec:
7+
group: test.example.com
8+
names:
9+
kind: ArgsTest
10+
listKind: ArgsTestList
11+
plural: argstests
12+
singular: argstest
13+
scope: Namespaced
14+
versions:
15+
- name: v1alpha1
16+
schema:
17+
openAPIV3Schema:
18+
description: ArgsTest is the Schema for the argstests API
19+
properties:
20+
apiVersion:
21+
description: 'APIVersion defines the versioned schema of this representation
22+
of an object. Servers should convert recognized schemas to the latest
23+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
24+
type: string
25+
kind:
26+
description: 'Kind is a string value representing the REST resource this
27+
object represents. Servers may infer this from the endpoint the client
28+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
29+
type: string
30+
metadata:
31+
type: object
32+
spec:
33+
description: Spec defines the desired state of ArgsTest
34+
type: object
35+
x-kubernetes-preserve-unknown-fields: true
36+
status:
37+
description: Status defines the observed state of ArgsTest
38+
type: object
39+
x-kubernetes-preserve-unknown-fields: true
40+
type: object
41+
served: true
42+
storage: true
43+
subresources:
44+
status: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: casetests.test.example.com
6+
spec:
7+
group: test.example.com
8+
names:
9+
kind: CaseTest
10+
listKind: CaseTestList
11+
plural: casetests
12+
singular: casetest
13+
scope: Namespaced
14+
versions:
15+
- name: v1alpha1
16+
schema:
17+
openAPIV3Schema:
18+
description: CaseTest is the Schema for the casetests API
19+
properties:
20+
apiVersion:
21+
description: 'APIVersion defines the versioned schema of this representation
22+
of an object. Servers should convert recognized schemas to the latest
23+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
24+
type: string
25+
kind:
26+
description: 'Kind is a string value representing the REST resource this
27+
object represents. Servers may infer this from the endpoint the client
28+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
29+
type: string
30+
metadata:
31+
type: object
32+
spec:
33+
description: Spec defines the desired state of CaseTest
34+
type: object
35+
x-kubernetes-preserve-unknown-fields: true
36+
status:
37+
description: Status defines the observed state of CaseTest
38+
type: object
39+
x-kubernetes-preserve-unknown-fields: true
40+
type: object
41+
served: true
42+
storage: true
43+
subresources:
44+
status: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: collectiontests.test.example.com
6+
spec:
7+
group: test.example.com
8+
names:
9+
kind: CollectionTest
10+
listKind: CollectionTestList
11+
plural: collectiontests
12+
singular: collectiontest
13+
scope: Namespaced
14+
versions:
15+
- name: v1alpha1
16+
schema:
17+
openAPIV3Schema:
18+
description: CollectionTest is the Schema for the collectiontests API
19+
properties:
20+
apiVersion:
21+
description: 'APIVersion defines the versioned schema of this representation
22+
of an object. Servers should convert recognized schemas to the latest
23+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
24+
type: string
25+
kind:
26+
description: 'Kind is a string value representing the REST resource this
27+
object represents. Servers may infer this from the endpoint the client
28+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
29+
type: string
30+
metadata:
31+
type: object
32+
spec:
33+
description: Spec defines the desired state of CollectionTest
34+
type: object
35+
x-kubernetes-preserve-unknown-fields: true
36+
status:
37+
description: Status defines the observed state of CollectionTest
38+
type: object
39+
x-kubernetes-preserve-unknown-fields: true
40+
type: object
41+
served: true
42+
storage: true
43+
subresources:
44+
status: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: inventorytests.test.example.com
6+
spec:
7+
group: test.example.com
8+
names:
9+
kind: InventoryTest
10+
listKind: InventoryTestList
11+
plural: inventorytests
12+
singular: inventorytest
13+
scope: Namespaced
14+
versions:
15+
- name: v1alpha1
16+
schema:
17+
openAPIV3Schema:
18+
description: InventoryTest is the Schema for the inventorytests API
19+
properties:
20+
apiVersion:
21+
description: 'APIVersion defines the versioned schema of this representation
22+
of an object. Servers should convert recognized schemas to the latest
23+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
24+
type: string
25+
kind:
26+
description: 'Kind is a string value representing the REST resource this
27+
object represents. Servers may infer this from the endpoint the client
28+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
29+
type: string
30+
metadata:
31+
type: object
32+
spec:
33+
description: Spec defines the desired state of InventoryTest
34+
type: object
35+
x-kubernetes-preserve-unknown-fields: true
36+
status:
37+
description: Status defines the observed state of InventoryTest
38+
type: object
39+
x-kubernetes-preserve-unknown-fields: true
40+
type: object
41+
served: true
42+
storage: true
43+
subresources:
44+
status: {}

0 commit comments

Comments
 (0)