From 5208b72f2d875d53e1e7fafb706687e49a958888 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Tue, 28 Jul 2020 00:30:59 +0100 Subject: [PATCH 1/2] migrate ansible sample for new layout --- .../memcached-operator/{build => }/Dockerfile | 4 +- ansible/memcached-operator/Makefile | 127 ++++++++++++----- ansible/memcached-operator/PROJECT | 8 ++ ansible/memcached-operator/README.md | 74 +++++----- .../build/test-framework/Dockerfile | 16 --- .../build/test-framework/ansible-test.sh | 7 - .../bases/cache.example.com_memcacheds.yaml | 44 ++++++ .../config/crd/kustomization.yaml | 6 + .../config/default/kustomization.yaml | 26 ++++ .../default/manager_auth_proxy_patch.yaml | 26 ++++ .../config/manager/kustomization.yaml | 8 ++ .../config/manager/manager.yaml | 34 +++++ .../config/prometheus/kustomization.yaml | 2 + .../config/prometheus/monitor.yaml | 16 +++ .../rbac/auth_proxy_client_clusterrole.yaml | 7 + .../config/rbac/auth_proxy_role.yaml | 13 ++ .../config/rbac/auth_proxy_role_binding.yaml | 12 ++ .../config/rbac/auth_proxy_service.yaml | 14 ++ .../config/rbac/kustomization.yaml | 20 +++ .../config/rbac/leader_election_role.yaml | 25 ++++ .../rbac/leader_election_role_binding.yaml} | 15 +- .../rbac/patches/memcached_editor_role.yaml | 27 ++++ .../memcached-operator/config/rbac/role.yaml | 36 +++++ .../config/rbac/role_binding.yaml | 13 ++ .../samples/cache_v1alpha1_memcached.yaml} | 2 +- .../config/samples/kustomization.yaml | 3 + .../config/scorecard/bases/config.yaml | 7 + .../config/scorecard/kustomization.yaml | 16 +++ .../scorecard/patches/basic.config.yaml | 10 ++ .../config/scorecard/patches/olm.config.yaml | 50 +++++++ .../config/testing/debug_logs_patch.yaml | 14 ++ .../config/testing/kustomization.yaml | 24 ++++ .../config/testing/manager_image.yaml | 12 ++ .../config/testing/pull_policy/Always.yaml | 12 ++ .../testing/pull_policy/IfNotPresent.yaml | 12 ++ .../config/testing/pull_policy/Never.yaml | 12 ++ .../cache.example.com_memcacheds_crd.yaml | 22 --- .../memcached-operator/deploy/operator.yaml | 50 ------- ansible/memcached-operator/deploy/role.yaml | 80 ----------- .../deploy/service_account.yaml | 4 - .../molecule/cluster/converge.yml | 24 ---- .../molecule/cluster/destroy.yml | 34 ----- .../molecule/cluster/molecule.yml | 35 ----- .../molecule/cluster/playbook.yml | 24 ---- .../molecule/cluster/prepare.yml | 31 ----- .../molecule/cluster/verify.yml | 35 ----- .../molecule/default/asserts.yml | 17 --- .../molecule/default/converge.yml | 16 ++- .../molecule/{cluster => default}/create.yml | 0 .../molecule/default/destroy.yml | 24 ++++ .../molecule/default/kustomize.yml | 15 ++ .../molecule/default/molecule.yml | 37 ++--- .../molecule/default/playbook.yml | 10 -- .../molecule/default/prepare.yml | 45 +++--- .../molecule/default/tasks/memcached_test.yml | 19 +++ .../molecule/default/verify.yml | 57 ++++++-- .../molecule/kind/converge.yml | 24 ++++ .../molecule/kind/create.yml | 8 ++ .../molecule/kind/destroy.yml | 11 ++ .../molecule/kind/molecule.yml | 42 ++++++ .../molecule/templates/operator.yaml.j2 | 47 ------- .../molecule/test-cluster/molecule.yml | 43 ------ .../molecule/test-cluster/playbook.yml | 33 ----- .../molecule/test-local/converge.yml | 42 ------ .../molecule/test-local/molecule.yml | 60 -------- .../molecule/test-local/playbook.yml | 129 ------------------ .../molecule/test-local/prepare.yml | 3 - .../molecule/test-local/verify.yml | 2 - .../memcached-operator/playbooks/.placeholder | 0 ansible/memcached-operator/roles/.placeholder | 0 ansible/memcached-operator/watches.yaml | 2 + 71 files changed, 900 insertions(+), 879 deletions(-) rename ansible/memcached-operator/{build => }/Dockerfile (70%) create mode 100644 ansible/memcached-operator/PROJECT delete mode 100644 ansible/memcached-operator/build/test-framework/Dockerfile delete mode 100644 ansible/memcached-operator/build/test-framework/ansible-test.sh create mode 100644 ansible/memcached-operator/config/crd/bases/cache.example.com_memcacheds.yaml create mode 100644 ansible/memcached-operator/config/crd/kustomization.yaml create mode 100644 ansible/memcached-operator/config/default/kustomization.yaml create mode 100644 ansible/memcached-operator/config/default/manager_auth_proxy_patch.yaml create mode 100644 ansible/memcached-operator/config/manager/kustomization.yaml create mode 100644 ansible/memcached-operator/config/manager/manager.yaml create mode 100644 ansible/memcached-operator/config/prometheus/kustomization.yaml create mode 100644 ansible/memcached-operator/config/prometheus/monitor.yaml create mode 100644 ansible/memcached-operator/config/rbac/auth_proxy_client_clusterrole.yaml create mode 100644 ansible/memcached-operator/config/rbac/auth_proxy_role.yaml create mode 100644 ansible/memcached-operator/config/rbac/auth_proxy_role_binding.yaml create mode 100644 ansible/memcached-operator/config/rbac/auth_proxy_service.yaml create mode 100644 ansible/memcached-operator/config/rbac/kustomization.yaml create mode 100644 ansible/memcached-operator/config/rbac/leader_election_role.yaml rename ansible/memcached-operator/{deploy/role_binding.yaml => config/rbac/leader_election_role_binding.yaml} (61%) create mode 100644 ansible/memcached-operator/config/rbac/patches/memcached_editor_role.yaml create mode 100644 ansible/memcached-operator/config/rbac/role.yaml create mode 100644 ansible/memcached-operator/config/rbac/role_binding.yaml rename ansible/memcached-operator/{deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml => config/samples/cache_v1alpha1_memcached.yaml} (79%) create mode 100644 ansible/memcached-operator/config/samples/kustomization.yaml create mode 100644 ansible/memcached-operator/config/scorecard/bases/config.yaml create mode 100644 ansible/memcached-operator/config/scorecard/kustomization.yaml create mode 100644 ansible/memcached-operator/config/scorecard/patches/basic.config.yaml create mode 100644 ansible/memcached-operator/config/scorecard/patches/olm.config.yaml create mode 100644 ansible/memcached-operator/config/testing/debug_logs_patch.yaml create mode 100644 ansible/memcached-operator/config/testing/kustomization.yaml create mode 100644 ansible/memcached-operator/config/testing/manager_image.yaml create mode 100644 ansible/memcached-operator/config/testing/pull_policy/Always.yaml create mode 100644 ansible/memcached-operator/config/testing/pull_policy/IfNotPresent.yaml create mode 100644 ansible/memcached-operator/config/testing/pull_policy/Never.yaml delete mode 100644 ansible/memcached-operator/deploy/crds/cache.example.com_memcacheds_crd.yaml delete mode 100644 ansible/memcached-operator/deploy/operator.yaml delete mode 100644 ansible/memcached-operator/deploy/role.yaml delete mode 100644 ansible/memcached-operator/deploy/service_account.yaml delete mode 100644 ansible/memcached-operator/molecule/cluster/converge.yml delete mode 100644 ansible/memcached-operator/molecule/cluster/destroy.yml delete mode 100644 ansible/memcached-operator/molecule/cluster/molecule.yml delete mode 100644 ansible/memcached-operator/molecule/cluster/playbook.yml delete mode 100644 ansible/memcached-operator/molecule/cluster/prepare.yml delete mode 100644 ansible/memcached-operator/molecule/cluster/verify.yml delete mode 100644 ansible/memcached-operator/molecule/default/asserts.yml rename ansible/memcached-operator/molecule/{cluster => default}/create.yml (100%) create mode 100644 ansible/memcached-operator/molecule/default/destroy.yml create mode 100644 ansible/memcached-operator/molecule/default/kustomize.yml delete mode 100644 ansible/memcached-operator/molecule/default/playbook.yml create mode 100644 ansible/memcached-operator/molecule/default/tasks/memcached_test.yml create mode 100644 ansible/memcached-operator/molecule/kind/converge.yml create mode 100644 ansible/memcached-operator/molecule/kind/create.yml create mode 100644 ansible/memcached-operator/molecule/kind/destroy.yml create mode 100644 ansible/memcached-operator/molecule/kind/molecule.yml delete mode 100644 ansible/memcached-operator/molecule/templates/operator.yaml.j2 delete mode 100644 ansible/memcached-operator/molecule/test-cluster/molecule.yml delete mode 100644 ansible/memcached-operator/molecule/test-cluster/playbook.yml delete mode 100644 ansible/memcached-operator/molecule/test-local/converge.yml delete mode 100644 ansible/memcached-operator/molecule/test-local/molecule.yml delete mode 100644 ansible/memcached-operator/molecule/test-local/playbook.yml delete mode 100644 ansible/memcached-operator/molecule/test-local/prepare.yml delete mode 100644 ansible/memcached-operator/molecule/test-local/verify.yml create mode 100644 ansible/memcached-operator/playbooks/.placeholder create mode 100644 ansible/memcached-operator/roles/.placeholder diff --git a/ansible/memcached-operator/build/Dockerfile b/ansible/memcached-operator/Dockerfile similarity index 70% rename from ansible/memcached-operator/build/Dockerfile rename to ansible/memcached-operator/Dockerfile index 610edec3..77a6936e 100644 --- a/ansible/memcached-operator/build/Dockerfile +++ b/ansible/memcached-operator/Dockerfile @@ -1,9 +1,9 @@ -FROM quay.io/operator-framework/ansible-operator:v0.18.1 +FROM quay.io/operator-framework/ansible-operator:master COPY requirements.yml ${HOME}/requirements.yml RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \ && chmod -R ug+rwx ${HOME}/.ansible COPY watches.yaml ${HOME}/watches.yaml - COPY roles/ ${HOME}/roles/ +COPY playbooks/ ${HOME}/playbooks/ diff --git a/ansible/memcached-operator/Makefile b/ansible/memcached-operator/Makefile index 36c43245..f6dc82a3 100644 --- a/ansible/memcached-operator/Makefile +++ b/ansible/memcached-operator/Makefile @@ -1,36 +1,91 @@ -.DEFAULT_GOAL:=help -SHELL:=/bin/bash -NAMESPACE=memcached - -##@ Application - -install: ## Install all resources (CR/CRD's, RBAC and Operator) - @echo ....... Creating namespace ....... - - kubectl create namespace ${NAMESPACE} - @echo ....... Applying CRDs and Operator ....... - - kubectl apply -f deploy/crds/cache.example.com_memcacheds_crd.yaml -n ${NAMESPACE} - @echo ....... Applying Rules and Service Account ....... - - kubectl apply -f deploy/role.yaml -n ${NAMESPACE} - - kubectl apply -f deploy/role_binding.yaml -n ${NAMESPACE} - - kubectl apply -f deploy/service_account.yaml -n ${NAMESPACE} - @echo ....... Applying Operator ....... - - kubectl apply -f deploy/operator.yaml -n ${NAMESPACE} - @echo ....... Creating the Database ....... - - kubectl apply -f deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml -n ${NAMESPACE} - -uninstall: ## Uninstall all that all performed in the $ make install - @echo ....... Uninstalling ....... - @echo ....... Deleting CRDs....... - - kubectl delete -f deploy/crds/cache.example.com_memcacheds_crd.yaml -n ${NAMESPACE} - @echo ....... Deleting Rules and Service Account ....... - - kubectl delete -f deploy/role.yaml -n ${NAMESPACE} - - kubectl delete -f deploy/role_binding.yaml -n ${NAMESPACE} - - kubectl delete -f deploy/service_account.yaml -n ${NAMESPACE} - @echo ....... Deleting Operator ....... - - kubectl delete -f deploy/operator.yaml -n ${NAMESPACE} - @echo ....... Deleting namespace ${NAMESPACE}....... - - kubectl delete namespace ${NAMESPACE} - -.PHONY: help -help: ## Display this help - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) +# 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) + +.PHONY: bundle + +# 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) + +# 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=./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/v0.19.0/ansible-operator-v0.19.0-$(ARCHOPER)-$(OSOPER) ;\ + mv ansible-operator-v0.19.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. +bundle: kustomize + operator-sdk generate kustomize manifests -q + $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) + operator-sdk bundle validate ./bundle + +# Build the bundle image. +bundle-build: + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . diff --git a/ansible/memcached-operator/PROJECT b/ansible/memcached-operator/PROJECT new file mode 100644 index 00000000..8c79d65b --- /dev/null +++ b/ansible/memcached-operator/PROJECT @@ -0,0 +1,8 @@ +domain: example.com +layout: ansible.sdk.operatorframework.io/v1 +projectName: memcached-operator +resources: +- group: cache + kind: Memcached + version: v1alpha1 +version: 3-alpha diff --git a/ansible/memcached-operator/README.md b/ansible/memcached-operator/README.md index 3de62efc..45ee138d 100644 --- a/ansible/memcached-operator/README.md +++ b/ansible/memcached-operator/README.md @@ -8,7 +8,7 @@ This Memcached operator is a simple example operator for the [Operator SDK][oper - [docker][docker_tool] version 17.03+ - [kubectl][kubectl_tool] v1.14.1+ -- [operator_sdk][operator_install] +- [operator_sdk][operator_install] v1.0.0+ - Access to a Kubernetes v1.14.1+ cluster ## Getting Started @@ -24,52 +24,58 @@ $ git clone https://github.com/operator-framework/operator-sdk-samples.git $ cd operator-sdk-samples/ansible/memcached-operator ``` -### Building the operator - -Build the Memcached operator image and push it to a public registry, such as quay.io: +## Building and Pushing the Project Image +To build and push your image to your repository : ``` -$ export IMAGE=quay.io/example-inc/memcached-operator:v0.0.1 -$ operator-sdk build $IMAGE -$ docker push $IMAGE +$ make docker-build docker-push IMG=/:tag ``` -**NOTE** The `quay.io/example-inc/memcached-operator:v0.0.1` is an example. You should build and push the image for your repository. +Note: To allow the cluster pull the image the repository needs to be set as public. -### Using the image +## Applying the CRDs into the cluster: +To apply the Memcached Kind(CRD): ``` -# Update the operator manifest to use the built image name (if you are performing these steps on OSX, see note below) -$ sed -i 's|REPLACE_IMAGE|quay.io/example-inc/memcached-operator:v0.0.1|g' deploy/operator.yaml -# On OSX use: -$ sed -i "" 's|REPLACE_IMAGE|quay.io/example-inc/memcached-operator:v0.0.1|g' deploy/operator.yaml +$ make install ``` -### Installing - -Run `make install` to install the operator. Check that the operator is running in the cluster, also check that the example Memcached service was deployed. - -Following the expected result. +## Applying the CR’s into the cluster: -```shell -$ kubectl get all -n memcached +To create instances (CR’s) of the Memcached Kind (CRD) in the same namespaced of the operator: +``` +$ kubectl apply -f config/samples/cache_v1alpha1_memcached.yaml -n memcached-operator-system +``` -NAME READY STATUS RESTARTS AGE -pod/example-memcached-memcached-b885dcc75-2crw5 1/1 Running 0 22s -pod/example-memcached-memcached-b885dcc75-69mbg 1/1 Running 0 22s -pod/example-memcached-memcached-b885dcc75-92rd7 1/1 Running 0 22s -pod/memcached-operator-df88b85f7-9s98n 2/2 Running 0 36s +## Running it on Cluster +Deploy the project to the cluster: -NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE -service/memcached-operator-metrics ClusterIP 10.98.192.187 8383/TCP 31s +``` +$ make deploy IMG=/:tag +``` -NAME READY UP-TO-DATE AVAILABLE AGE -deployment.apps/example-memcached-memcached 3/3 3 3 22s -deployment.apps/memcached-operator 1/1 1 1 36s +Following the expected result. -NAME DESIRED CURRENT READY AGE -replicaset.apps/example-memcached-memcached-b885dcc75 3 3 3 22s -replicaset.apps/memcached-operator-df88b85f7 1 1 1 36s +```shell + $ kubectl get all -n memcached-operator-system +NAME READY STATUS RESTARTS AGE +pod/memcached-operator-controller-manager-7dbcd676f9-s9nrz 2/2 Running 0 113s +pod/memcached-sample-memcached-6456bdd5fc-fdbfg 1/1 Running 0 67s +pod/memcached-sample-memcached-6456bdd5fc-p97h8 1/1 Running 0 67s +pod/memcached-sample-memcached-6456bdd5fc-q4wbb 1/1 Running 0 67s + +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +service/memcached-operator-controller-manager-metrics-service ClusterIP 10.96.153.103 8443/TCP 4h52m + +NAME READY UP-TO-DATE AVAILABLE AGE +deployment.apps/memcached-operator-controller-manager 1/1 1 1 4h52m +deployment.apps/memcached-sample-memcached 3/3 3 3 67s + +NAME DESIRED CURRENT READY AGE +replicaset.apps/memcached-operator-controller-manager-5b7f656f48 0 0 0 4h52m +replicaset.apps/memcached-operator-controller-manager-7dbcd676f9 1 1 1 113s +replicaset.apps/memcached-operator-controller-manager-7dbdb5b9ff 0 0 0 52m +replicaset.apps/memcached-sample-memcached-6456bdd5fc 3 3 3 67s ``` ### Uninstalling @@ -81,7 +87,7 @@ To uninstall all that was performed in the above step run `make uninstall`. Use the following command to check the operator logs. ``` -kubectl logs deployment.apps/memcached-operator -n memcached +$ kubectl logs deployment.apps/memcached-operator-controller-manager -n memcached-operator-system -c manager ``` **NOTE:** This project is configured with the environment variable `ANSIBLE_DEBUG_LOGS` as `True`, however, note that it is `False` by default. diff --git a/ansible/memcached-operator/build/test-framework/Dockerfile b/ansible/memcached-operator/build/test-framework/Dockerfile deleted file mode 100644 index 67ef10e5..00000000 --- a/ansible/memcached-operator/build/test-framework/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -ARG BASEIMAGE -FROM ${BASEIMAGE} -USER 0 - -# Ensure fresh metadata rather than cached metadata in the base by running -# yum clean all && rm -rf /var/yum/cache/* first -RUN yum clean all && rm -rf /var/cache/yum/* \ - && yum -y update \ - && yum install -y python36-devel gcc libffi-devel python3-pip -RUN pip3 install --user molecule==2.22 -ARG NAMESPACEDMAN -ADD $NAMESPACEDMAN /namespaced.yaml -ADD build/test-framework/ansible-test.sh /ansible-test.sh -RUN chmod +x /ansible-test.sh -USER 1001 -ADD . /opt/ansible/project diff --git a/ansible/memcached-operator/build/test-framework/ansible-test.sh b/ansible/memcached-operator/build/test-framework/ansible-test.sh deleted file mode 100644 index 9719f260..00000000 --- a/ansible/memcached-operator/build/test-framework/ansible-test.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -export WATCH_NAMESPACE=${TEST_NAMESPACE} -(/usr/local/bin/entrypoint)& -trap "kill $!" SIGINT SIGTERM EXIT - -cd ${HOME}/project -exec molecule test -s test-cluster diff --git a/ansible/memcached-operator/config/crd/bases/cache.example.com_memcacheds.yaml b/ansible/memcached-operator/config/crd/bases/cache.example.com_memcacheds.yaml new file mode 100644 index 00000000..b019a46e --- /dev/null +++ b/ansible/memcached-operator/config/crd/bases/cache.example.com_memcacheds.yaml @@ -0,0 +1,44 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: memcacheds.cache.example.com +spec: + group: cache.example.com + names: + kind: Memcached + listKind: MemcachedList + plural: memcacheds + singular: memcached + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: Memcached is the Schema for the memcacheds 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 Memcached + type: object + x-kubernetes-preserve-unknown-fields: true + status: + description: Status defines the observed state of Memcached + type: object + x-kubernetes-preserve-unknown-fields: true + type: object + served: true + storage: true + subresources: + status: {} diff --git a/ansible/memcached-operator/config/crd/kustomization.yaml b/ansible/memcached-operator/config/crd/kustomization.yaml new file mode 100644 index 00000000..f7aed174 --- /dev/null +++ b/ansible/memcached-operator/config/crd/kustomization.yaml @@ -0,0 +1,6 @@ +# This kustomization.yaml is not intended to be run by itself, +# since it depends on service name and namespace that are out of this kustomize package. +# It should be run by config/default +resources: +- bases/cache.example.com_memcacheds.yaml +# +kubebuilder:scaffold:crdkustomizeresource diff --git a/ansible/memcached-operator/config/default/kustomization.yaml b/ansible/memcached-operator/config/default/kustomization.yaml new file mode 100644 index 00000000..db7390fc --- /dev/null +++ b/ansible/memcached-operator/config/default/kustomization.yaml @@ -0,0 +1,26 @@ +# Adds namespace to all resources. +namespace: memcached-operator-system + +# Value of this field is prepended to the +# names of all resources, e.g. a deployment named +# "wordpress" becomes "alices-wordpress". +# Note that it should also match with the prefix (text before '-') of the namespace +# field above. +namePrefix: memcached-operator- + +# Labels to add to all resources and selectors. +#commonLabels: +# someName: someValue + +bases: +- ../crd +- ../rbac +- ../manager +# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. +#- ../prometheus + +patchesStrategicMerge: + # Protect the /metrics endpoint by putting it behind auth. + # If you want your controller-manager to expose the /metrics + # endpoint w/o any authn/z, please comment the following line. +- manager_auth_proxy_patch.yaml diff --git a/ansible/memcached-operator/config/default/manager_auth_proxy_patch.yaml b/ansible/memcached-operator/config/default/manager_auth_proxy_patch.yaml new file mode 100644 index 00000000..2f618979 --- /dev/null +++ b/ansible/memcached-operator/config/default/manager_auth_proxy_patch.yaml @@ -0,0 +1,26 @@ +# This patch inject a sidecar container which is a HTTP proxy for the +# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews. +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system +spec: + template: + spec: + containers: + - name: kube-rbac-proxy + image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 + args: + - "--secure-listen-address=0.0.0.0:8443" + - "--upstream=http://127.0.0.1:8080/" + - "--logtostderr=true" + - "--v=10" + ports: + - containerPort: 8443 + name: https + - name: manager + args: + - "--metrics-addr=127.0.0.1:8080" + - "--enable-leader-election" + - "--leader-election-id=memcached-operator" diff --git a/ansible/memcached-operator/config/manager/kustomization.yaml b/ansible/memcached-operator/config/manager/kustomization.yaml new file mode 100644 index 00000000..60322c55 --- /dev/null +++ b/ansible/memcached-operator/config/manager/kustomization.yaml @@ -0,0 +1,8 @@ +resources: +- manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: camila + newTag: "88" diff --git a/ansible/memcached-operator/config/manager/manager.yaml b/ansible/memcached-operator/config/manager/manager.yaml new file mode 100644 index 00000000..de7f85a1 --- /dev/null +++ b/ansible/memcached-operator/config/manager/manager.yaml @@ -0,0 +1,34 @@ +apiVersion: v1 +kind: Namespace +metadata: + labels: + control-plane: controller-manager + name: system +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system + labels: + control-plane: controller-manager +spec: + selector: + matchLabels: + control-plane: controller-manager + replicas: 1 + template: + metadata: + labels: + control-plane: controller-manager + spec: + containers: + - name: manager + args: + - "--enable-leader-election" + - "--leader-election-id=memcached-operator" + image: controller:latest + env: + - name: ANSIBLE_DEBUG_LOGS + value: "True" + terminationGracePeriodSeconds: 10 diff --git a/ansible/memcached-operator/config/prometheus/kustomization.yaml b/ansible/memcached-operator/config/prometheus/kustomization.yaml new file mode 100644 index 00000000..ed137168 --- /dev/null +++ b/ansible/memcached-operator/config/prometheus/kustomization.yaml @@ -0,0 +1,2 @@ +resources: +- monitor.yaml diff --git a/ansible/memcached-operator/config/prometheus/monitor.yaml b/ansible/memcached-operator/config/prometheus/monitor.yaml new file mode 100644 index 00000000..1b44d4f6 --- /dev/null +++ b/ansible/memcached-operator/config/prometheus/monitor.yaml @@ -0,0 +1,16 @@ +--- +# Prometheus Monitor Service (Metrics) +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + control-plane: controller-manager + name: controller-manager-metrics-monitor + namespace: system +spec: + endpoints: + - path: /metrics + port: https + selector: + matchLabels: + control-plane: controller-manager diff --git a/ansible/memcached-operator/config/rbac/auth_proxy_client_clusterrole.yaml b/ansible/memcached-operator/config/rbac/auth_proxy_client_clusterrole.yaml new file mode 100644 index 00000000..7d62534c --- /dev/null +++ b/ansible/memcached-operator/config/rbac/auth_proxy_client_clusterrole.yaml @@ -0,0 +1,7 @@ +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRole +metadata: + name: metrics-reader +rules: +- nonResourceURLs: ["/metrics"] + verbs: ["get"] diff --git a/ansible/memcached-operator/config/rbac/auth_proxy_role.yaml b/ansible/memcached-operator/config/rbac/auth_proxy_role.yaml new file mode 100644 index 00000000..618f5e41 --- /dev/null +++ b/ansible/memcached-operator/config/rbac/auth_proxy_role.yaml @@ -0,0 +1,13 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: proxy-role +rules: +- apiGroups: ["authentication.k8s.io"] + resources: + - tokenreviews + verbs: ["create"] +- apiGroups: ["authorization.k8s.io"] + resources: + - subjectaccessreviews + verbs: ["create"] diff --git a/ansible/memcached-operator/config/rbac/auth_proxy_role_binding.yaml b/ansible/memcached-operator/config/rbac/auth_proxy_role_binding.yaml new file mode 100644 index 00000000..48ed1e4b --- /dev/null +++ b/ansible/memcached-operator/config/rbac/auth_proxy_role_binding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: proxy-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: proxy-role +subjects: +- kind: ServiceAccount + name: default + namespace: system diff --git a/ansible/memcached-operator/config/rbac/auth_proxy_service.yaml b/ansible/memcached-operator/config/rbac/auth_proxy_service.yaml new file mode 100644 index 00000000..6cf656be --- /dev/null +++ b/ansible/memcached-operator/config/rbac/auth_proxy_service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + control-plane: controller-manager + name: controller-manager-metrics-service + namespace: system +spec: + ports: + - name: https + port: 8443 + targetPort: https + selector: + control-plane: controller-manager diff --git a/ansible/memcached-operator/config/rbac/kustomization.yaml b/ansible/memcached-operator/config/rbac/kustomization.yaml new file mode 100644 index 00000000..fb2b74fe --- /dev/null +++ b/ansible/memcached-operator/config/rbac/kustomization.yaml @@ -0,0 +1,20 @@ +resources: + - role.yaml + - role_binding.yaml + - leader_election_role.yaml + - leader_election_role_binding.yaml + # Comment the following 4 lines if you want to disable + # the auth proxy (https://github.com/brancz/kube-rbac-proxy) + # which protects your /metrics endpoint. + - auth_proxy_service.yaml + - auth_proxy_role.yaml + - auth_proxy_role_binding.yaml + - auth_proxy_client_clusterrole.yaml +patchesJson6902: + - target: + group: rbac.authorization.k8s.io + version: v1 + kind: ClusterRole + name: manager-role + path: patches/memcached_editor_role.yaml +# +kubebuilder:scaffold:patch6902 diff --git a/ansible/memcached-operator/config/rbac/leader_election_role.yaml b/ansible/memcached-operator/config/rbac/leader_election_role.yaml new file mode 100644 index 00000000..53e97491 --- /dev/null +++ b/ansible/memcached-operator/config/rbac/leader_election_role.yaml @@ -0,0 +1,25 @@ +# permissions to do leader election. +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: leader-election-role +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch diff --git a/ansible/memcached-operator/deploy/role_binding.yaml b/ansible/memcached-operator/config/rbac/leader_election_role_binding.yaml similarity index 61% rename from ansible/memcached-operator/deploy/role_binding.yaml rename to ansible/memcached-operator/config/rbac/leader_election_role_binding.yaml index 322ecc9e..eed16906 100644 --- a/ansible/memcached-operator/deploy/role_binding.yaml +++ b/ansible/memcached-operator/config/rbac/leader_election_role_binding.yaml @@ -1,11 +1,12 @@ -kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding metadata: - name: memcached-operator -subjects: -- kind: ServiceAccount - name: memcached-operator + name: leader-election-rolebinding roleRef: - kind: Role - name: memcached-operator apiGroup: rbac.authorization.k8s.io + kind: Role + name: leader-election-role +subjects: +- kind: ServiceAccount + name: default + namespace: system diff --git a/ansible/memcached-operator/config/rbac/patches/memcached_editor_role.yaml b/ansible/memcached-operator/config/rbac/patches/memcached_editor_role.yaml new file mode 100644 index 00000000..5334f556 --- /dev/null +++ b/ansible/memcached-operator/config/rbac/patches/memcached_editor_role.yaml @@ -0,0 +1,27 @@ +--- +- op: add + path: /rules/- + value: + apiGroups: + - cache.example.com + resources: + - memcacheds + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- op: add + path: /rules/- + value: + apiGroups: + - cache.example.com + resources: + - memcacheds/status + verbs: + - get + - patch + - update diff --git a/ansible/memcached-operator/config/rbac/role.yaml b/ansible/memcached-operator/config/rbac/role.yaml new file mode 100644 index 00000000..2d256998 --- /dev/null +++ b/ansible/memcached-operator/config/rbac/role.yaml @@ -0,0 +1,36 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: manager-role +rules: +- apiGroups: + - "" + resources: + - secrets + - pods + - pods/exec + - pods/log + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - apps + resources: + - deployments + - daemonsets + - replicasets + - statefulsets + verbs: + - create + - delete + - get + - list + - patch + - update + - watch diff --git a/ansible/memcached-operator/config/rbac/role_binding.yaml b/ansible/memcached-operator/config/rbac/role_binding.yaml new file mode 100644 index 00000000..98f87829 --- /dev/null +++ b/ansible/memcached-operator/config/rbac/role_binding.yaml @@ -0,0 +1,13 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: manager-role +subjects: +- kind: ServiceAccount + name: default + namespace: system diff --git a/ansible/memcached-operator/deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml b/ansible/memcached-operator/config/samples/cache_v1alpha1_memcached.yaml similarity index 79% rename from ansible/memcached-operator/deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml rename to ansible/memcached-operator/config/samples/cache_v1alpha1_memcached.yaml index 2b8f17c3..a5dccd86 100644 --- a/ansible/memcached-operator/deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml +++ b/ansible/memcached-operator/config/samples/cache_v1alpha1_memcached.yaml @@ -1,7 +1,7 @@ apiVersion: cache.example.com/v1alpha1 kind: Memcached metadata: - name: example-memcached + name: memcached-sample spec: # Add fields here size: 3 diff --git a/ansible/memcached-operator/config/samples/kustomization.yaml b/ansible/memcached-operator/config/samples/kustomization.yaml new file mode 100644 index 00000000..64c215af --- /dev/null +++ b/ansible/memcached-operator/config/samples/kustomization.yaml @@ -0,0 +1,3 @@ +## This file is auto-generated, do not modify ## +resources: +- cache_v1alpha1_memcached.yaml diff --git a/ansible/memcached-operator/config/scorecard/bases/config.yaml b/ansible/memcached-operator/config/scorecard/bases/config.yaml new file mode 100644 index 00000000..c7704784 --- /dev/null +++ b/ansible/memcached-operator/config/scorecard/bases/config.yaml @@ -0,0 +1,7 @@ +apiVersion: scorecard.operatorframework.io/v1alpha3 +kind: Configuration +metadata: + name: config +stages: +- parallel: true + tests: [] diff --git a/ansible/memcached-operator/config/scorecard/kustomization.yaml b/ansible/memcached-operator/config/scorecard/kustomization.yaml new file mode 100644 index 00000000..d73509ee --- /dev/null +++ b/ansible/memcached-operator/config/scorecard/kustomization.yaml @@ -0,0 +1,16 @@ +resources: +- bases/config.yaml +patchesJson6902: +- path: patches/basic.config.yaml + target: + group: scorecard.operatorframework.io + version: v1alpha3 + kind: Configuration + name: config +- path: patches/olm.config.yaml + target: + group: scorecard.operatorframework.io + version: v1alpha3 + kind: Configuration + name: config +# +kubebuilder:scaffold:patchesJson6902 diff --git a/ansible/memcached-operator/config/scorecard/patches/basic.config.yaml b/ansible/memcached-operator/config/scorecard/patches/basic.config.yaml new file mode 100644 index 00000000..e7fa3050 --- /dev/null +++ b/ansible/memcached-operator/config/scorecard/patches/basic.config.yaml @@ -0,0 +1,10 @@ +- op: add + path: /stages/0/tests/- + value: + entrypoint: + - scorecard-test + - basic-check-spec + image: quay.io/operator-framework/scorecard-test:master + labels: + suite: basic + test: basic-check-spec-test diff --git a/ansible/memcached-operator/config/scorecard/patches/olm.config.yaml b/ansible/memcached-operator/config/scorecard/patches/olm.config.yaml new file mode 100644 index 00000000..e564c42f --- /dev/null +++ b/ansible/memcached-operator/config/scorecard/patches/olm.config.yaml @@ -0,0 +1,50 @@ +- op: add + path: /stages/0/tests/- + value: + entrypoint: + - scorecard-test + - olm-bundle-validation + image: quay.io/operator-framework/scorecard-test:master + labels: + suite: olm + test: olm-bundle-validation-test +- op: add + path: /stages/0/tests/- + value: + entrypoint: + - scorecard-test + - olm-crds-have-validation + image: quay.io/operator-framework/scorecard-test:master + labels: + suite: olm + test: olm-crds-have-validation-test +- op: add + path: /stages/0/tests/- + value: + entrypoint: + - scorecard-test + - olm-crds-have-resources + image: quay.io/operator-framework/scorecard-test:master + labels: + suite: olm + test: olm-crds-have-resources-test +- op: add + path: /stages/0/tests/- + value: + entrypoint: + - scorecard-test + - olm-spec-descriptors + image: quay.io/operator-framework/scorecard-test:master + labels: + suite: olm + test: olm-spec-descriptors-test +- op: add + path: /stages/0/tests/- + value: + entrypoint: + - scorecard-test + - olm-status-descriptors + image: quay.io/operator-framework/scorecard-test:master + labels: + suite: olm + test: olm-status-descriptors-test diff --git a/ansible/memcached-operator/config/testing/debug_logs_patch.yaml b/ansible/memcached-operator/config/testing/debug_logs_patch.yaml new file mode 100644 index 00000000..3e31e2fb --- /dev/null +++ b/ansible/memcached-operator/config/testing/debug_logs_patch.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system +spec: + template: + spec: + containers: + - name: manager + env: + - name: ANSIBLE_DEBUG_LOGS + value: "TRUE" diff --git a/ansible/memcached-operator/config/testing/kustomization.yaml b/ansible/memcached-operator/config/testing/kustomization.yaml new file mode 100644 index 00000000..9757d27f --- /dev/null +++ b/ansible/memcached-operator/config/testing/kustomization.yaml @@ -0,0 +1,24 @@ +# Adds namespace to all resources. +namespace: osdk-test + +namePrefix: osdk- + +# Labels to add to all resources and selectors. +#commonLabels: +# someName: someValue + +patchesStrategicMerge: +- manager_image.yaml +- pull_policy/Never.yaml +- debug_logs_patch.yaml +- ../default/manager_auth_proxy_patch.yaml + +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../crd +- ../rbac +- ../manager +images: +- name: testing + newName: testing-operator diff --git a/ansible/memcached-operator/config/testing/manager_image.yaml b/ansible/memcached-operator/config/testing/manager_image.yaml new file mode 100644 index 00000000..e44f542d --- /dev/null +++ b/ansible/memcached-operator/config/testing/manager_image.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system +spec: + template: + spec: + containers: + - name: manager + image: testing diff --git a/ansible/memcached-operator/config/testing/pull_policy/Always.yaml b/ansible/memcached-operator/config/testing/pull_policy/Always.yaml new file mode 100644 index 00000000..6b0a8e2a --- /dev/null +++ b/ansible/memcached-operator/config/testing/pull_policy/Always.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system +spec: + template: + spec: + containers: + - name: manager + imagePullPolicy: Always diff --git a/ansible/memcached-operator/config/testing/pull_policy/IfNotPresent.yaml b/ansible/memcached-operator/config/testing/pull_policy/IfNotPresent.yaml new file mode 100644 index 00000000..2f52f496 --- /dev/null +++ b/ansible/memcached-operator/config/testing/pull_policy/IfNotPresent.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system +spec: + template: + spec: + containers: + - name: manager + imagePullPolicy: IfNotPresent diff --git a/ansible/memcached-operator/config/testing/pull_policy/Never.yaml b/ansible/memcached-operator/config/testing/pull_policy/Never.yaml new file mode 100644 index 00000000..86f13d81 --- /dev/null +++ b/ansible/memcached-operator/config/testing/pull_policy/Never.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system +spec: + template: + spec: + containers: + - name: manager + imagePullPolicy: Never diff --git a/ansible/memcached-operator/deploy/crds/cache.example.com_memcacheds_crd.yaml b/ansible/memcached-operator/deploy/crds/cache.example.com_memcacheds_crd.yaml deleted file mode 100644 index 282336e0..00000000 --- a/ansible/memcached-operator/deploy/crds/cache.example.com_memcacheds_crd.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - name: memcacheds.cache.example.com -spec: - group: cache.example.com - names: - kind: Memcached - listKind: MemcachedList - plural: memcacheds - singular: memcached - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - type: object - x-kubernetes-preserve-unknown-fields: true - served: true - storage: true - subresources: - status: {} diff --git a/ansible/memcached-operator/deploy/operator.yaml b/ansible/memcached-operator/deploy/operator.yaml deleted file mode 100644 index eb843fd6..00000000 --- a/ansible/memcached-operator/deploy/operator.yaml +++ /dev/null @@ -1,50 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: memcached-operator -spec: - replicas: 1 - selector: - matchLabels: - name: memcached-operator - template: - metadata: - labels: - name: memcached-operator - spec: - serviceAccountName: memcached-operator - containers: - - name: memcached-operator - # Replace this with the built image name - image: "REPLACE_IMAGE" - imagePullPolicy: "Always" - volumeMounts: - - mountPath: /tmp/ansible-operator/runner - name: runner - env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: OPERATOR_NAME - value: "memcached-operator" - - name: ANSIBLE_GATHERING - value: explicit - - name: ANSIBLE_VERBOSITY - value: "4" - - name: ANSIBLE_DEBUG_LOGS - value: "True" - livenessProbe: - httpGet: - path: /healthz - port: 6789 - initialDelaySeconds: 5 - periodSeconds: 3 - volumes: - - name: runner - emptyDir: {} diff --git a/ansible/memcached-operator/deploy/role.yaml b/ansible/memcached-operator/deploy/role.yaml deleted file mode 100644 index 8bfec9ed..00000000 --- a/ansible/memcached-operator/deploy/role.yaml +++ /dev/null @@ -1,80 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - creationTimestamp: null - name: memcached-operator -rules: -- apiGroups: - - "" - resources: - - pods - - services - - services/finalizers - - endpoints - - persistentvolumeclaims - - events - - configmaps - - secrets - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - apps - resources: - - deployments - - daemonsets - - replicasets - - statefulsets - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - monitoring.coreos.com - resources: - - servicemonitors - verbs: - - get - - create -- apiGroups: - - apps - resourceNames: - - memcached-operator - resources: - - deployments/finalizers - verbs: - - update -- apiGroups: - - "" - resources: - - pods - verbs: - - get -- apiGroups: - - apps - resources: - - replicasets - - deployments - verbs: - - get -- apiGroups: - - cache.example.com - resources: - - '*' - verbs: - - create - - delete - - get - - list - - patch - - update - - watch diff --git a/ansible/memcached-operator/deploy/service_account.yaml b/ansible/memcached-operator/deploy/service_account.yaml deleted file mode 100644 index 8d58bc78..00000000 --- a/ansible/memcached-operator/deploy/service_account.yaml +++ /dev/null @@ -1,4 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: memcached-operator diff --git a/ansible/memcached-operator/molecule/cluster/converge.yml b/ansible/memcached-operator/molecule/cluster/converge.yml deleted file mode 100644 index 8877f825..00000000 --- a/ansible/memcached-operator/molecule/cluster/converge.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- 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 }}' diff --git a/ansible/memcached-operator/molecule/cluster/destroy.yml b/ansible/memcached-operator/molecule/cluster/destroy.yml deleted file mode 100644 index 9a0939c9..00000000 --- a/ansible/memcached-operator/molecule/cluster/destroy.yml +++ /dev/null @@ -1,34 +0,0 @@ ---- -- name: Destroy - hosts: localhost - connection: local - gather_facts: false - no_log: "{{ molecule_no_log }}" - collections: - - community.kubernetes - - tasks: - - name: Delete namespace - k8s: - api_version: v1 - kind: Namespace - name: '{{ namespace }}' - state: absent - wait: yes - - - name: Delete RBAC resources - k8s: - definition: "{{ lookup('template', '/'.join([deploy_dir, item])) }}" - namespace: '{{ namespace }}' - state: absent - wait: yes - with_items: - - role.yaml - - role_binding.yaml - - service_account.yaml - - - name: Delete Custom Resource Definition - k8s: - definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/cache.example.com_memcacheds_crd.yaml'])) }}" - state: absent - wait: yes diff --git a/ansible/memcached-operator/molecule/cluster/molecule.yml b/ansible/memcached-operator/molecule/cluster/molecule.yml deleted file mode 100644 index 06b307f7..00000000 --- a/ansible/memcached-operator/molecule/cluster/molecule.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- -dependency: - name: galaxy -driver: - name: delegated -lint: | - set -e - yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" . -platforms: -- name: cluster - groups: - - k8s -provisioner: - name: ansible - lint: | - set -e - ansible-lint - inventory: - group_vars: - all: - namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test} - host_vars: - localhost: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - deploy_dir: ${MOLECULE_PROJECT_DIRECTORY}/deploy - template_dir: ${MOLECULE_PROJECT_DIRECTORY}/molecule/templates - operator_image: ${OPERATOR_IMAGE:-""} - operator_pull_policy: ${OPERATOR_PULL_POLICY:-"Always"} - env: - K8S_AUTH_KUBECONFIG: ${KUBECONFIG:-"~/.kube/config"} -verifier: - name: ansible - lint: | - set -e - ansible-lint diff --git a/ansible/memcached-operator/molecule/cluster/playbook.yml b/ansible/memcached-operator/molecule/cluster/playbook.yml deleted file mode 100644 index 8877f825..00000000 --- a/ansible/memcached-operator/molecule/cluster/playbook.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- 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 }}' diff --git a/ansible/memcached-operator/molecule/cluster/prepare.yml b/ansible/memcached-operator/molecule/cluster/prepare.yml deleted file mode 100644 index 31b7b2b7..00000000 --- a/ansible/memcached-operator/molecule/cluster/prepare.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- name: Prepare - hosts: localhost - connection: local - gather_facts: false - no_log: "{{ molecule_no_log }}" - collections: - - community.kubernetes - - vars: - deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy" - - tasks: - - name: Create Custom Resource Definition - k8s: - definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/cache.example.com_memcacheds_crd.yaml'])) }}" - - - name: Create namespace - k8s: - api_version: v1 - kind: Namespace - name: '{{ namespace }}' - - - name: Create RBAC resources - k8s: - definition: "{{ lookup('template', '/'.join([deploy_dir, item])) }}" - namespace: '{{ namespace }}' - with_items: - - role.yaml - - role_binding.yaml - - service_account.yaml diff --git a/ansible/memcached-operator/molecule/cluster/verify.yml b/ansible/memcached-operator/molecule/cluster/verify.yml deleted file mode 100644 index 71b58dad..00000000 --- a/ansible/memcached-operator/molecule/cluster/verify.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- -# This is an example playbook to execute Ansible tests. -- name: Verify - hosts: localhost - connection: local - gather_facts: no - collections: - - community.kubernetes - - vars: - custom_resource: "{{ lookup('template', '/'.join([deploy_dir, 'crds/cache.example.com_v1alpha1_memcached_cr.yaml'])) | from_yaml }}" - - tasks: - - name: Create the cache.example.com/v1alpha1.Memcached and wait for reconciliation to complete - k8s: - state: present - namespace: '{{ namespace }}' - definition: '{{ custom_resource }}' - wait: yes - wait_timeout: 300 - wait_condition: - type: Running - reason: Successful - status: "True" - - - name: Get Pods - k8s_info: - api_version: v1 - kind: Pod - namespace: '{{ namespace }}' - register: pods - - - name: Example assertion - assert: - that: (pods | length) > 0 diff --git a/ansible/memcached-operator/molecule/default/asserts.yml b/ansible/memcached-operator/molecule/default/asserts.yml deleted file mode 100644 index 53894306..00000000 --- a/ansible/memcached-operator/molecule/default/asserts.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- - -- name: Verify - hosts: localhost - connection: local - vars: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - tasks: - - name: Get all pods in {{ namespace }} - k8s_info: - api_version: v1 - kind: Pod - namespace: '{{ namespace }}' - register: pods - - - name: Output pods - debug: var=pods diff --git a/ansible/memcached-operator/molecule/default/converge.yml b/ansible/memcached-operator/molecule/default/converge.yml index aac702ce..0633db98 100644 --- a/ansible/memcached-operator/molecule/default/converge.yml +++ b/ansible/memcached-operator/molecule/default/converge.yml @@ -2,5 +2,17 @@ - name: Converge hosts: localhost connection: local - roles: - - memcached + gather_facts: no + collections: + - community.kubernetes + + tasks: + - name: Create Namespace + k8s: + api_version: v1 + kind: Namespace + name: '{{ namespace }}' + + - import_tasks: kustomize.yml + vars: + state: present diff --git a/ansible/memcached-operator/molecule/cluster/create.yml b/ansible/memcached-operator/molecule/default/create.yml similarity index 100% rename from ansible/memcached-operator/molecule/cluster/create.yml rename to ansible/memcached-operator/molecule/default/create.yml diff --git a/ansible/memcached-operator/molecule/default/destroy.yml b/ansible/memcached-operator/molecule/default/destroy.yml new file mode 100644 index 00000000..f935cff1 --- /dev/null +++ b/ansible/memcached-operator/molecule/default/destroy.yml @@ -0,0 +1,24 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: false + collections: + - community.kubernetes + + tasks: + - import_tasks: kustomize.yml + vars: + state: absent + + - name: Destroy Namespace + k8s: + api_version: v1 + kind: Namespace + name: '{{ namespace }}' + state: absent + + - name: Unset pull policy + command: '{{ kustomize }} edit remove patch pull_policy/{{ pull_policy }}.yaml' + args: + chdir: '{{ config_dir }}/testing' diff --git a/ansible/memcached-operator/molecule/default/kustomize.yml b/ansible/memcached-operator/molecule/default/kustomize.yml new file mode 100644 index 00000000..f3d888c2 --- /dev/null +++ b/ansible/memcached-operator/molecule/default/kustomize.yml @@ -0,0 +1,15 @@ +--- +- name: Build kustomize testing overlay + # load_restrictor must be set to none so we can load patch files from the default overlay + command: '{{ kustomize }} build --load_restrictor none .' + args: + chdir: '{{ config_dir }}/testing' + register: resources + changed_when: false + +- name: Set resources to {{ state }} + k8s: + definition: '{{ item }}' + state: '{{ state }}' + wait: yes + loop: '{{ resources.stdout | from_yaml_all | list }}' diff --git a/ansible/memcached-operator/molecule/default/molecule.yml b/ansible/memcached-operator/molecule/default/molecule.yml index dbb68008..94f4fe6e 100644 --- a/ansible/memcached-operator/molecule/default/molecule.yml +++ b/ansible/memcached-operator/molecule/default/molecule.yml @@ -2,23 +2,23 @@ dependency: name: galaxy driver: - name: docker + name: delegated 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.17} - privileged: True - override_command: no - exposed_ports: - - 8443/tcp - - 10080/tcp - published_ports: - - 0.0.0.0:${TEST_CLUSTER_PORT:-9443}:8443/tcp - pre_build_image: yes + - name: cluster + groups: + - k8s + image: bsycorp/kind:latest-${KUBE_VERSION:-1.17} + privileged: True + override_command: no + exposed_ports: + - 8443/tcp + - 10080/tcp + published_ports: + - 0.0.0.0:${TEST_CLUSTER_PORT:-9443}:8443/tcp + pre_build_image: yes provisioner: name: ansible log: True @@ -29,13 +29,18 @@ provisioner: group_vars: all: namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test} - kubeconfig_file: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig + kubeconfig_file: ${KUBECONFIG:-"~/.kube/config"} host_vars: localhost: ansible_python_interpreter: '{{ ansible_playbook_python }}' + config_dir: ${MOLECULE_PROJECT_DIRECTORY}/config + samples_dir: ${MOLECULE_PROJECT_DIRECTORY}/config/samples + operator_image: ${OPERATOR_IMAGE:-""} + operator_pull_policy: ${OPERATOR_PULL_POLICY:-"Always"} + kustomize: ${KUSTOMIZE_PATH:-kustomize} env: - K8S_AUTH_KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig + K8S_AUTH_KUBECONFIG: ${KUBECONFIG:-"~/.kube/config"} + KUBECONFIG: ${KUBECONFIG:-"~/.kube/config"} ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles KIND_PORT: '${TEST_CLUSTER_PORT:-9443}' verifier: diff --git a/ansible/memcached-operator/molecule/default/playbook.yml b/ansible/memcached-operator/molecule/default/playbook.yml deleted file mode 100644 index 1b7ed282..00000000 --- a/ansible/memcached-operator/molecule/default/playbook.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Converge - hosts: localhost - connection: local - vars: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - roles: - - memcached - -- import_playbook: '{{ playbook_dir }}/asserts.yml' diff --git a/ansible/memcached-operator/molecule/default/prepare.yml b/ansible/memcached-operator/molecule/default/prepare.yml index 0ef09072..f269f3bf 100644 --- a/ansible/memcached-operator/molecule/default/prepare.yml +++ b/ansible/memcached-operator/molecule/default/prepare.yml @@ -1,27 +1,28 @@ --- - name: Prepare - hosts: k8s - gather_facts: no + hosts: localhost + connection: local + gather_facts: false + tasks: - - name: Fetch the kubeconfig - fetch: - dest: '{{ kubeconfig_file }}' - flat: yes - src: /root/.kube/config + - name: Ensure operator image is set + fail: + msg: | + You must specify the OPERATOR_IMAGE environment variable in order to run the + 'default' scenario + when: not operator_image + + - name: Set testing image + command: '{{ kustomize }} edit set image testing={{ operator_image }}' + args: + chdir: '{{ config_dir }}/testing' - - name: Change the kubeconfig port to the proper value - replace: - regexp: '8443' - replace: "{{ lookup('env', 'KIND_PORT') }}" - path: '{{ kubeconfig_file }}' - delegate_to: localhost + - name: Set pull policy + command: '{{ kustomize }} edit add patch pull_policy/{{ pull_policy }}.yaml' + args: + chdir: '{{ config_dir }}/testing' - - name: Wait for the Kubernetes API to become available (this could take a minute) - uri: - url: "http://localhost:10080/kubernetes-ready" - status_code: 200 - validate_certs: no - register: result - until: (result.status|default(-1)) == 200 - retries: 60 - delay: 5 + - name: Set testing namespace + command: '{{ kustomize }} edit set namespace {{ namespace }}' + args: + chdir: '{{ config_dir }}/testing' diff --git a/ansible/memcached-operator/molecule/default/tasks/memcached_test.yml b/ansible/memcached-operator/molecule/default/tasks/memcached_test.yml new file mode 100644 index 00000000..df4834a3 --- /dev/null +++ b/ansible/memcached-operator/molecule/default/tasks/memcached_test.yml @@ -0,0 +1,19 @@ +--- +- name: Create the cache.example.com/v1alpha1.Memcached + k8s: + state: present + namespace: '{{ namespace }}' + definition: "{{ lookup('template', '/'.join([samples_dir, cr_file])) | from_yaml }}" + wait: yes + wait_timeout: 300 + wait_condition: + type: Running + reason: Successful + status: "True" + vars: + cr_file: 'cache_v1alpha1_memcached.yaml' + +- name: Add assertions here + assert: + that: false + fail_msg: FIXME Add real assertions for your operator diff --git a/ansible/memcached-operator/molecule/default/verify.yml b/ansible/memcached-operator/molecule/default/verify.yml index cf5b2540..1e77643c 100644 --- a/ansible/memcached-operator/molecule/default/verify.yml +++ b/ansible/memcached-operator/molecule/default/verify.yml @@ -2,17 +2,52 @@ - name: Verify hosts: localhost connection: local + gather_facts: no + collections: + - community.kubernetes + tasks: - - name: Get all pods in {{ namespace }} - k8s_info: - api_version: v1 - kind: Pod - namespace: '{{ namespace }}' - register: pods + - block: + - name: Import all test files from tasks/ + include_tasks: '{{ item }}' + with_fileglob: + - tasks/*_test.yml + rescue: + - name: Retrieve relevant resources + k8s_info: + api_version: '{{ item.api_version }}' + kind: '{{ item.kind }}' + namespace: '{{ namespace }}' + loop: + - api_version: v1 + kind: Pod + - api_version: apps/v1 + kind: Deployment + - api_version: v1 + kind: Secret + - api_version: v1 + kind: ConfigMap + register: debug_resources + + - name: Retrieve Pod logs + k8s_log: + name: '{{ item.metadata.name }}' + namespace: '{{ namespace }}' + loop: "{{ q('k8s', api_version='v1', kind='Pod', namespace=namespace) }}" + register: debug_logs + + - name: Output gathered resources + debug: + var: debug_resources - - name: Output pods - debug: var=pods + - name: Output gathered logs + debug: + var: item.log_lines + loop: '{{ debug_logs.results }}' - - name: Example assertion - assert: - that: true + - name: Re-emit failure + vars: + failed_task: + result: '{{ ansible_failed_result }}' + fail: + msg: '{{ failed_task }}' diff --git a/ansible/memcached-operator/molecule/kind/converge.yml b/ansible/memcached-operator/molecule/kind/converge.yml new file mode 100644 index 00000000..8bd5700f --- /dev/null +++ b/ansible/memcached-operator/molecule/kind/converge.yml @@ -0,0 +1,24 @@ +--- +- name: Converge + hosts: localhost + connection: local + gather_facts: no + + tasks: + - name: Build operator image + docker_image: + build: + path: '{{ project_dir }}' + pull: no + name: '{{ operator_image }}' + tag: latest + push: no + source: build + force_source: yes + + - name: Load image into kind cluster + command: kind load docker-image --name osdk-test '{{ operator_image }}' + register: result + changed_when: '"not yet present" in result.stdout' + +- import_playbook: ../default/converge.yml diff --git a/ansible/memcached-operator/molecule/kind/create.yml b/ansible/memcached-operator/molecule/kind/create.yml new file mode 100644 index 00000000..66a84a14 --- /dev/null +++ b/ansible/memcached-operator/molecule/kind/create.yml @@ -0,0 +1,8 @@ +--- +- name: Create + hosts: localhost + connection: local + gather_facts: false + tasks: + - name: Create test kind cluster + command: kind create cluster --name osdk-test --kubeconfig {{ kubeconfig }} diff --git a/ansible/memcached-operator/molecule/kind/destroy.yml b/ansible/memcached-operator/molecule/kind/destroy.yml new file mode 100644 index 00000000..9393e4fa --- /dev/null +++ b/ansible/memcached-operator/molecule/kind/destroy.yml @@ -0,0 +1,11 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: false + collections: + - community.kubernetes + + tasks: + - name: Destroy test kind cluster + command: kind delete cluster --name osdk-test --kubeconfig {{ kubeconfig }} diff --git a/ansible/memcached-operator/molecule/kind/molecule.yml b/ansible/memcached-operator/molecule/kind/molecule.yml new file mode 100644 index 00000000..38d6990f --- /dev/null +++ b/ansible/memcached-operator/molecule/kind/molecule.yml @@ -0,0 +1,42 @@ +--- +dependency: + name: galaxy +driver: + name: delegated +lint: | + set -e + yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" . +platforms: + - name: cluster + groups: + - k8s +provisioner: + name: ansible + playbooks: + prepare: ../default/prepare.yml + verify: ../default/verify.yml + lint: | + set -e + ansible-lint + inventory: + group_vars: + all: + namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test} + host_vars: + localhost: + ansible_python_interpreter: '{{ ansible_playbook_python }}' + config_dir: ${MOLECULE_PROJECT_DIRECTORY}/config + samples_dir: ${MOLECULE_PROJECT_DIRECTORY}/config/samples + project_dir: ${MOLECULE_PROJECT_DIRECTORY} + operator_image: testing-operator + pull_policy: "Never" + kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}" + kustomize: ${KUSTOMIZE_PATH:-kustomize} + env: + K8S_AUTH_KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig + KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig +verifier: + name: ansible + lint: | + set -e + ansible-lint diff --git a/ansible/memcached-operator/molecule/templates/operator.yaml.j2 b/ansible/memcached-operator/molecule/templates/operator.yaml.j2 deleted file mode 100644 index 5a5ea46b..00000000 --- a/ansible/memcached-operator/molecule/templates/operator.yaml.j2 +++ /dev/null @@ -1,47 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: memcached-operator -spec: - replicas: 1 - selector: - matchLabels: - name: memcached-operator - template: - metadata: - labels: - name: memcached-operator - spec: - serviceAccountName: memcached-operator - containers: - - name: memcached-operator - # Replace this with the built image name - image: "{{ image }}" - imagePullPolicy: "{{ pull_policy }}" - volumeMounts: - - mountPath: /tmp/ansible-operator/runner - name: runner - env: - - name: WATCH_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: OPERATOR_NAME - value: "memcached-operator" - - name: ANSIBLE_GATHERING - value: explicit - livenessProbe: - httpGet: - path: /healthz - port: 6789 - initialDelaySeconds: 5 - periodSeconds: 3 - - volumes: - - name: runner - emptyDir: {} diff --git a/ansible/memcached-operator/molecule/test-cluster/molecule.yml b/ansible/memcached-operator/molecule/test-cluster/molecule.yml deleted file mode 100644 index 2eaa5faa..00000000 --- a/ansible/memcached-operator/molecule/test-cluster/molecule.yml +++ /dev/null @@ -1,43 +0,0 @@ ---- -dependency: - name: galaxy -driver: - name: delegated - options: - managed: False - ansible_connection_options: {} -lint: - name: yamllint - enabled: False -platforms: -- name: test-cluster - groups: - - k8s -provisioner: - name: ansible - inventory: - group_vars: - all: - namespace: ${TEST_NAMESPACE:-osdk-test} - lint: - name: ansible-lint - enabled: False - env: - ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles -scenario: - name: test-cluster - test_sequence: - - lint - - destroy - - dependency - - syntax - - create - - prepare - - converge - - side_effect - - verify - - destroy -verifier: - name: testinfra - lint: - name: flake8 diff --git a/ansible/memcached-operator/molecule/test-cluster/playbook.yml b/ansible/memcached-operator/molecule/test-cluster/playbook.yml deleted file mode 100644 index 35d73ec6..00000000 --- a/ansible/memcached-operator/molecule/test-cluster/playbook.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- - -- name: Converge - hosts: localhost - connection: local - vars: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy" - image_name: cache.example.com/memcached-operator:testing - custom_resource: "{{ lookup('file', '/'.join([deploy_dir, 'crds/cache.example.com_v1alpha1_memcached_cr.yaml'])) | from_yaml }}" - tasks: - - name: Create the cache.example.com/v1alpha1.Memcached - k8s: - namespace: '{{ namespace }}' - definition: "{{ lookup('file', '/'.join([deploy_dir, 'crds/cache.example.com_v1alpha1_memcached_cr.yaml'])) }}" - - - name: Get the newly created Custom Resource - debug: - msg: "{{ lookup('k8s', group='cache.example.com', api_version='v1alpha1', kind='Memcached', namespace=namespace, resource_name=custom_resource.metadata.name) }}" - - - name: Wait 2m for reconciliation to run - k8s_info: - api_version: 'v1alpha1' - kind: 'Memcached' - namespace: '{{ namespace }}' - name: '{{ custom_resource.metadata.name }}' - register: reconcile_cr - until: - - "'Successful' in (reconcile_cr | json_query('resources[].status.conditions[].reason'))" - delay: 12 - retries: 10 - -- import_playbook: '{{ playbook_dir }}/../default/asserts.yml' diff --git a/ansible/memcached-operator/molecule/test-local/converge.yml b/ansible/memcached-operator/molecule/test-local/converge.yml deleted file mode 100644 index 4e58ca24..00000000 --- a/ansible/memcached-operator/molecule/test-local/converge.yml +++ /dev/null @@ -1,42 +0,0 @@ ---- -- 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 diff --git a/ansible/memcached-operator/molecule/test-local/molecule.yml b/ansible/memcached-operator/molecule/test-local/molecule.yml deleted file mode 100644 index e8fb7906..00000000 --- a/ansible/memcached-operator/molecule/test-local/molecule.yml +++ /dev/null @@ -1,60 +0,0 @@ ---- -dependency: - name: galaxy -driver: - name: docker -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.17} - privileged: true - override_command: false - exposed_ports: - - 8443/tcp - - 10080/tcp - published_ports: - - 0.0.0.0:${TEST_CLUSTER_PORT:-10443}:8443/tcp - pre_build_image: true - volumes: - - ${MOLECULE_PROJECT_DIRECTORY}:/build:Z -provisioner: - name: ansible - log: true - lint: - name: ansible-lint - inventory: - group_vars: - all: - namespace: ${TEST_OPERATOR_NAMESPACE:-osdk-test} - kubeconfig_file: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - host_vars: - localhost: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - template_dir: ${MOLECULE_PROJECT_DIRECTORY}/molecule/templates - deploy_dir: ${MOLECULE_PROJECT_DIRECTORY}/deploy - env: - K8S_AUTH_KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - KUBECONFIG: ${MOLECULE_EPHEMERAL_DIRECTORY}/kubeconfig - ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles - KIND_PORT: '${TEST_CLUSTER_PORT:-10443}' -scenario: - name: test-local - test_sequence: - - lint - - destroy - - dependency - - syntax - - create - - prepare - - converge - - side_effect - - verify - - destroy -verifier: - name: ansible - lint: - name: ansible-lint diff --git a/ansible/memcached-operator/molecule/test-local/playbook.yml b/ansible/memcached-operator/molecule/test-local/playbook.yml deleted file mode 100644 index 52d76495..00000000 --- a/ansible/memcached-operator/molecule/test-local/playbook.yml +++ /dev/null @@ -1,129 +0,0 @@ ---- -- 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: - ansible_python_interpreter: '{{ ansible_playbook_python }}' - deploy_dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/deploy" - pull_policy: Never - REPLACE_IMAGE: cache.example.com/memcached-operator:testing - custom_resource: "{{ lookup('file', '/'.join([deploy_dir, 'crds/cache.example.com_v1alpha1_memcached_cr.yaml'])) | from_yaml }}" - image: cache.example.com/memcached-operator:testing - operator_template: "{{ '/'.join([template_dir, 'operator.yaml.j2']) }}" - - tasks: - - block: - - name: Delete the Operator Deployment - k8s: - state: absent - namespace: '{{ namespace }}' - definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) }}" - register: delete_deployment - when: hostvars[groups.k8s.0].build_cmd.changed - - - name: Wait 30s for Operator Deployment to terminate - k8s_info: - api_version: '{{ definition.apiVersion }}' - kind: '{{ definition.kind }}' - namespace: '{{ namespace }}' - name: '{{ definition.metadata.name }}' - vars: - definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) | from_yaml }}" - register: deployment - until: not deployment.resources - delay: 3 - retries: 10 - when: delete_deployment.changed - - - name: Create the Operator Deployment - k8s: - namespace: '{{ namespace }}' - definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) }}" - - - name: Create the cache.example.com/v1alpha1.Memcached - k8s: - state: present - namespace: '{{ namespace }}' - definition: '{{ custom_resource }}' - - - name: Wait 2m for reconciliation to run - k8s_info: - api_version: '{{ custom_resource.apiVersion }}' - kind: '{{ custom_resource.kind }}' - namespace: '{{ namespace }}' - name: '{{ custom_resource.metadata.name }}' - register: cr - until: - - "'Successful' in (cr | json_query('resources[].status.conditions[].reason'))" - delay: 12 - retries: 10 - rescue: - - name: debug cr - ignore_errors: yes - failed_when: false - debug: - var: debug_cr - vars: - debug_cr: '{{ lookup("k8s", - kind=custom_resource.kind, - api_version=custom_resource.apiVersion, - namespace=namespace, - resource_name=custom_resource.metadata.name - )}}' - - - name: debug memcached lookup - ignore_errors: yes - failed_when: false - debug: - var: deploy - vars: - deploy: '{{ lookup("k8s", - kind="Deployment", - api_version="apps/v1", - namespace=namespace, - label_selector="app=memcached" - )}}' - - - name: get operator logs - ignore_errors: yes - failed_when: false - command: kubectl logs deployment/{{ definition.metadata.name }} -n {{ namespace }} - environment: - KUBECONFIG: '{{ lookup("env", "KUBECONFIG") }}' - vars: - definition: "{{ lookup('template', '/'.join([deploy_dir, 'operator.yaml'])) | from_yaml }}" - register: log - - - debug: var=log.stdout_lines - - - fail: - msg: "Failed on action: converge" - -- import_playbook: '{{ playbook_dir }}/../default/asserts.yml' diff --git a/ansible/memcached-operator/molecule/test-local/prepare.yml b/ansible/memcached-operator/molecule/test-local/prepare.yml deleted file mode 100644 index 6d57ace5..00000000 --- a/ansible/memcached-operator/molecule/test-local/prepare.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -- import_playbook: ../default/prepare.yml -- import_playbook: ../cluster/prepare.yml diff --git a/ansible/memcached-operator/molecule/test-local/verify.yml b/ansible/memcached-operator/molecule/test-local/verify.yml deleted file mode 100644 index 4c003088..00000000 --- a/ansible/memcached-operator/molecule/test-local/verify.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- import_playbook: ../cluster/verify.yml diff --git a/ansible/memcached-operator/playbooks/.placeholder b/ansible/memcached-operator/playbooks/.placeholder new file mode 100644 index 00000000..e69de29b diff --git a/ansible/memcached-operator/roles/.placeholder b/ansible/memcached-operator/roles/.placeholder new file mode 100644 index 00000000..e69de29b diff --git a/ansible/memcached-operator/watches.yaml b/ansible/memcached-operator/watches.yaml index 88d1d6de..9ebc8a99 100644 --- a/ansible/memcached-operator/watches.yaml +++ b/ansible/memcached-operator/watches.yaml @@ -1,5 +1,7 @@ --- +# Use the 'create api' subcommand to add watches to this file. - version: v1alpha1 group: cache.example.com kind: Memcached role: memcached +# +kubebuilder:scaffold:watch From 95b6fa80e284ba2c1556fd3e4540bf4598396373 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Tue, 28 Jul 2020 00:36:38 +0100 Subject: [PATCH 2/2] readme --- ansible/memcached-operator/README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ansible/memcached-operator/README.md b/ansible/memcached-operator/README.md index 45ee138d..cfb8dc4b 100644 --- a/ansible/memcached-operator/README.md +++ b/ansible/memcached-operator/README.md @@ -90,13 +90,8 @@ Use the following command to check the operator logs. $ kubectl logs deployment.apps/memcached-operator-controller-manager -n memcached-operator-system -c manager ``` -**NOTE:** This project is configured with the environment variable `ANSIBLE_DEBUG_LOGS` as `True`, however, note that it is `False` by default. +**NOTE** To have further information about how to develop Ansible operators with [Operator-SDK][operator_sdk] check the [Ansible docs][ansible-docs]. -**NOTE** To have further information about how to develop Ansible operators with [Operator-SDK][operator_sdk] check the [Ansible User Guide for Operator-SDK][ansible-guide] - -### Testing the Operator - -See [Testing Ansible Operators with Molecule][ansible-test-guide] documentation to know how to use the operator framework features to test it. [python]: https://www.python.org/ [ansible]: https://www.ansible.com/ @@ -104,5 +99,4 @@ See [Testing Ansible Operators with Molecule][ansible-test-guide] documentation [docker_tool]: https://docs.docker.com/install/ [operator_sdk]: https://github.com/operator-framework/operator-sdk [operator_install]: https://sdk.operatorframework.io/docs/install-operator-sdk/ -[ansible-test-guide]: https://sdk.operatorframework.io/docs/ansible/testing-guide/ -[ansible-guide]: https://sdk.operatorframework.io/docs/ansible/quickstart/ +[ansible-docs]: https://sdk.operatorframework.io/docs/docs/building-operators/ansible/