Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/test-ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
env
export PATH=/opt/python/3.6.7/bin:${PATH}
sudo apt-get install python3 python3-pip
sudo pip3 install wheel
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can this be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sudo pip3 install --upgrade setuptools pip
sudo pip3 install ansible~=2.9.13
make test-e2e-ansible-molecule
22 changes: 16 additions & 6 deletions hack/tests/e2e-ansible-molecule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ else
fi
KUSTOMIZE_PATH=${KUSTOMIZE} TEST_OPERATOR_NAMESPACE=default molecule test -s kind

cd $TMPDIR
KUSTOMIZE_PATH=${KUSTOMIZE}
rm -rf $KUSTOMIZE
cd $TMPDIR/
rm -rf memcached-molecule-operator
Comment thread
estroz marked this conversation as resolved.

header_text "Test Ansible Molecule scenarios"
pushd "${ROOTDIR}/test/ansible"
DEST_IMAGE="quay.io/example/ansible-test-operator:v0.0.1"
sed -i".bak" -E -e 's/(FROM quay.io\/operator-framework\/ansible-operator)(:.*)?/\1:dev/g' build/Dockerfile; rm -f build/Dockerfile.bak
docker build -f build/Dockerfile -t "$DEST_IMAGE" --no-cache .

make kustomize
if [ -f ./bin/kustomize ] ; then
KUSTOMIZE="$(realpath ./bin/kustomize)"
else
KUSTOMIZE="$(which kustomize)"
fi

DEST_IMAGE="quay.io/example/advanced-molecule-operator:v0.0.1"
sed -i".bak" -E -e 's/(FROM quay.io\/operator-framework\/ansible-operator)(:.*)?/\1:dev/g' Dockerfile; rm -f Dockerfile.bak
docker build -t "$DEST_IMAGE" --no-cache .
load_image_if_kind "$DEST_IMAGE"
OPERATOR_PULL_POLICY=Never OPERATOR_IMAGE=${DEST_IMAGE} TEST_CLUSTER_PORT=24443 TEST_OPERATOR_NAMESPACE=osdk-test molecule test --all
KUSTOMIZE_PATH=$KUSTOMIZE OPERATOR_PULL_POLICY=Never OPERATOR_IMAGE=${DEST_IMAGE} TEST_OPERATOR_NAMESPACE=osdk-test molecule test
Comment thread
estroz marked this conversation as resolved.
14 changes: 14 additions & 0 deletions test/ansible/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
13 changes: 8 additions & 5 deletions test/ansible/build/Dockerfile → test/ansible/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
FROM quay.io/operator-framework/ansible-operator:dev
FROM quay.io/operator-framework/ansible-operator:v1.2.0
Comment thread
asmacdo marked this conversation as resolved.

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

COPY watches.yaml ${HOME}/watches.yaml
COPY roles/ ${HOME}/roles/
COPY playbooks/ ${HOME}/playbooks/

# Customizations done to check advanced scenarios
COPY inventory/ ${HOME}/inventory/
COPY plugins/ ${HOME}/plugins/
COPY ansible.cfg /etc/ansible/ansible.cfg
COPY fixture_collection/ /tmp/fixture_collection/
USER root
RUN chmod -R ug+rwx /tmp/fixture_collection
USER 1001
RUN ansible-galaxy collection build /tmp/fixture_collection/ --output-path /tmp/fixture_collection/ \
&& ansible-galaxy collection install /tmp/fixture_collection/operator_sdk-test_fixtures-0.0.0.tar.gz
&& ansible-galaxy collection install /tmp/fixture_collection/operator_sdk-test_fixtures-0.0.0.tar.gz
RUN echo abc123 > /opt/ansible/pwd.yml \
&& ansible-vault encrypt_string --vault-password-file /opt/ansible/pwd.yml 'thisisatest' --name 'the_secret' > /opt/ansible/vars.yml
&& ansible-vault encrypt_string --vault-password-file /opt/ansible/pwd.yml 'thisisatest' --name 'the_secret' > /opt/ansible/vars.yml

92 changes: 92 additions & 0 deletions test/ansible/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Current Operator version
VERSION ?= 0.0.1
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# Image URL to use all building/pushing image targets
IMG ?= controller:latest

all: docker-build

# Run against the configured Kubernetes cluster in ~/.kube/config
run: ansible-operator
$(ANSIBLE_OPERATOR) run

# Install CRDs into a cluster
install: kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -

# Uninstall CRDs from a cluster
uninstall: kustomize
$(KUSTOMIZE) build config/crd | kubectl delete -f -

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
undeploy: kustomize
$(KUSTOMIZE) build config/default | kubectl delete -f -

# Build the docker image
docker-build:
docker build . -t ${IMG}

# Push the docker image
docker-push:
docker push ${IMG}

PATH := $(PATH):$(PWD)/bin
SHELL := env PATH=$(PATH) /bin/sh
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH = $(shell uname -m | sed 's/x86_64/amd64/')
OSOPER = $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/apple-darwin/' | sed 's/linux/linux-gnu/')
ARCHOPER = $(shell uname -m )

kustomize:
ifeq (, $(shell which kustomize 2>/dev/null))
@{ \
set -e ;\
mkdir -p bin ;\
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/ ;\
}
KUSTOMIZE=$(realpath ./bin/kustomize)
else
KUSTOMIZE=$(shell which kustomize)
endif

ansible-operator:
ifeq (, $(shell which ansible-operator 2>/dev/null))
@{ \
set -e ;\
mkdir -p bin ;\
curl -LO https://github.com/operator-framework/operator-sdk/releases/download/v1.2.0/ansible-operator-v1.2.0-$(ARCHOPER)-$(OSOPER) ;\
mv ansible-operator-v1.2.0-$(ARCHOPER)-$(OSOPER) ./bin/ansible-operator ;\
chmod +x ./bin/ansible-operator ;\
}
ANSIBLE_OPERATOR=$(realpath ./bin/ansible-operator)
else
ANSIBLE_OPERATOR=$(shell which ansible-operator)
endif

# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: kustomize
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle

# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
6 changes: 0 additions & 6 deletions test/ansible/OWNERS

This file was deleted.

24 changes: 24 additions & 0 deletions test/ansible/PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
domain: example.com
layout: ansible.sdk.operatorframework.io/v1
multigroup: true
projectName: advanced-molecule-operator
resources:
- group: test
kind: InventoryTest
version: v1alpha1
- group: test
kind: ArgsTest
version: v1alpha1
- group: test
kind: CaseTest
version: v1alpha1
- group: test
kind: CollectionTest
version: v1alpha1
- group: test
kind: SelectorTest
version: v1alpha1
- group: test
kind: SubresourcesTest
version: v1alpha1
version: 3-alpha
44 changes: 44 additions & 0 deletions test/ansible/config/crd/bases/test.example.com_argstests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: argstests.test.example.com
spec:
group: test.example.com
names:
kind: ArgsTest
listKind: ArgsTestList
plural: argstests
singular: argstest
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: ArgsTest is the Schema for the argstests API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec defines the desired state of ArgsTest
type: object
x-kubernetes-preserve-unknown-fields: true
status:
description: Status defines the observed state of ArgsTest
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
served: true
storage: true
subresources:
status: {}
44 changes: 44 additions & 0 deletions test/ansible/config/crd/bases/test.example.com_casetests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: casetests.test.example.com
spec:
group: test.example.com
names:
kind: CaseTest
listKind: CaseTestList
plural: casetests
singular: casetest
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: CaseTest is the Schema for the casetests API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec defines the desired state of CaseTest
type: object
x-kubernetes-preserve-unknown-fields: true
status:
description: Status defines the observed state of CaseTest
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
served: true
storage: true
subresources:
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: collectiontests.test.example.com
spec:
group: test.example.com
names:
kind: CollectionTest
listKind: CollectionTestList
plural: collectiontests
singular: collectiontest
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: CollectionTest is the Schema for the collectiontests API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec defines the desired state of CollectionTest
type: object
x-kubernetes-preserve-unknown-fields: true
status:
description: Status defines the observed state of CollectionTest
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
served: true
storage: true
subresources:
status: {}
44 changes: 44 additions & 0 deletions test/ansible/config/crd/bases/test.example.com_inventorytests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: inventorytests.test.example.com
spec:
group: test.example.com
names:
kind: InventoryTest
listKind: InventoryTestList
plural: inventorytests
singular: inventorytest
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: InventoryTest is the Schema for the inventorytests API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec defines the desired state of InventoryTest
type: object
x-kubernetes-preserve-unknown-fields: true
status:
description: Status defines the observed state of InventoryTest
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
served: true
storage: true
subresources:
status: {}
Loading