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

Commit 22fef73

Browse files
Merge pull request #74 from camilamacedo86/update-ansible
upgrade ansible memcached operator project to use version v0.10.0 of sdk
2 parents 8236e01 + e9c5a33 commit 22fef73

File tree

25 files changed

+648
-51
lines changed

25 files changed

+648
-51
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.idea/*
2+
ansible/memcached-operator/.idea/*

ansible/memcached-operator/.gitgnore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# kubuilder project
2+
bin/manager
3+
cover.out
4+
5+
# Binaries for programs and plugins
6+
*.exe
7+
*.exe~
8+
*.dll
9+
*.so
10+
*.dylib
11+
bin
12+
13+
# Test binary, build with `go test -c`
14+
*.test
15+
16+
# Output of the go coverage tool, specifically when used with LiteIDE
17+
*.out
18+
19+
# Kubernetes Generated files - skip generated files, except for vendored files
20+
21+
!vendor/**/zz_generated.*
22+
23+
# editor and IDE paraphernalia
24+
.idea
25+
*.swp
26+
*.swo
27+
*~
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sudo: required
2+
services: docker
3+
language: python
4+
install:
5+
- pip3 install docker molecule openshift
6+
script:
7+
- molecule test -s test-local

ansible/memcached-operator/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.DEFAULT_GOAL:=help
2+
SHELL:=/bin/bash
3+
NAMESPACE=memcached
4+
5+
##@ Application
6+
7+
install: ## Install all resources (CR/CRD's, RBCA and Operator)
8+
@echo ....... Creating namespace .......
9+
- kubectl create namespace ${NAMESPACE}
10+
@echo ....... Applying CRDS and Operator .......
11+
- kubectl apply -f deploy/crds/cache_v1alpha1_memcached_crd.yaml -n ${NAMESPACE}
12+
@echo ....... Applying Rules and Service Account .......
13+
- kubectl apply -f deploy/role.yaml -n ${NAMESPACE}
14+
- kubectl apply -f deploy/role_binding.yaml -n ${NAMESPACE}
15+
- kubectl apply -f deploy/service_account.yaml -n ${NAMESPACE}
16+
@echo ....... Applying Operator .......
17+
- kubectl apply -f deploy/operator.yaml -n ${NAMESPACE}
18+
@echo ....... Creating the Database .......
19+
- kubectl apply -f deploy/crds/cache_v1alpha1_memcached_cr.yaml -n ${NAMESPACE}
20+
21+
uninstall: ## Uninstall all that all performed in the $ make install
22+
@echo ....... Uninstalling .......
23+
@echo ....... Deleting CRDs.......
24+
- kubectl delete -f deploy/crds/cache_v1alpha1_memcached_crd.yaml -n ${NAMESPACE}
25+
@echo ....... Deleting Rules and Service Account .......
26+
- kubectl delete -f deploy/role.yaml -n ${NAMESPACE}
27+
- kubectl delete -f deploy/role_binding.yaml -n ${NAMESPACE}
28+
- kubectl delete -f deploy/service_account.yaml -n ${NAMESPACE}
29+
@echo ....... Deleting Operator .......
30+
- kubectl delete -f deploy/operator.yaml -n ${NAMESPACE}
31+
@echo ....... Deleting namespace ${NAMESPACE}.......
32+
- kubectl delete namespace ${NAMESPACE}
33+
34+
.PHONY: help
35+
help: ## Display this help
36+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\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)

ansible/memcached-operator/README.md

Lines changed: 94 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,106 @@
1-
# Memcached Ansible Operator
1+
# Memcached Operator
22

3-
## Quickstart
3+
## Overview
44

5-
1. Start [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/) (e.g. `minikube start`)
5+
This Memcached operator is a simple example operator for the [Operator SDK][operator_sdk] and includes some basic end-to-end tests.
66

7-
We will be using the `default` namespace, and the `default` account
7+
## Prerequisites
88

9-
1. Deploy the Memcached Ansible Operator
9+
- [docker][docker_tool] version 17.03+
10+
- [kubectl][kubectl_tool] v1.11.3+
11+
- [operator_sdk][operator_install]
12+
- Access to a Kubernetes v1.11.3+ cluster
1013

11-
* Create the Memcached Ansible Operator RBAC and Service Account files
12-
```bash
13-
$ kubectl create -f deploy/service_account.yaml
14-
$ kubectl create -f deploy/role.yaml
15-
$ kubectl create -f deploy/role_binding.yaml
16-
```
14+
## Getting Started
1715

18-
* Create the Memcached Ansible Operator Custom Resource Definitions (CRD)
19-
```bash
20-
kubectl create -f deploy/crds/cache_v1alpha1_memcached_crd.yaml
21-
```
22-
* Deploy the Memcached Ansible Operator
23-
```bash
24-
kubectl create -f deploy/operator.yaml
25-
```
16+
### Cloning the repository
2617

27-
1. Create the Memcached Ansible Operator Custom Resource (CR)
18+
Checkout this Memcached Operator repository
2819

29-
```bash
30-
kubectl create -f deploy/crds/cache_v1alpha1_memcached_cr.yaml
31-
```
20+
```
21+
$ mkdir operator-framework
22+
$ cd operator-framework
23+
$ git clone https://github.com/operator-framework/operator-sdk-samples.git
24+
$ cd operator-sdk-samples/ansible/memcached-operator
25+
```
3226

33-
## Uninstall
27+
### Building the operator
3428

35-
To uninstall the Deployment and the Memcached Ansible Operator, run the following commands
29+
Build the Memcached operator image and push it to a public registry, such as quay.io:
3630

37-
1. Uninstall
38-
```bash
39-
kubectl delete -f deploy/crds/cache_v1alpha1_memcached_cr.yaml
40-
```
41-
1. Uninstall Memcached Ansible Operator
42-
```bash
43-
kubectl delete -f deploy/operator.yaml
44-
```
31+
```
32+
$ export IMAGE=quay.io/example-inc/memcached-operator:v0.0.1
33+
$ operator-sdk build $IMAGE
34+
$ docker push $IMAGE
35+
```
4536

46-
Verify that the all pods created with the deployment are being `terminated` and are deleted
37+
**NOTE** The `quay.io/example-inc/memcached-operator` is an example. You should build and push the image for your repository.
38+
39+
### Using the image
40+
41+
```
42+
# Update the operator manifest to use the built image name (if you are performing these steps on OSX, see note below)
43+
$ sed -i 's|REPLACE_IMAGE|quay.io/example-inc/memcached-operator|g' deploy/operator.yaml
44+
# On OSX use:
45+
$ sed -i "" 's|REPLACE_IMAGE|quay.io/example-inc/memcached-operator|g' deploy/operator.yaml
46+
```
47+
48+
### Installing
49+
50+
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.
51+
52+
Following the expected result.
53+
54+
```shell
55+
$ kubectl get all -n memcached
56+
57+
NAME READY STATUS RESTARTS AGE
58+
pod/example-memcached-memcached-b885dcc75-2crw5 1/1 Running 0 22s
59+
pod/example-memcached-memcached-b885dcc75-69mbg 1/1 Running 0 22s
60+
pod/example-memcached-memcached-b885dcc75-92rd7 1/1 Running 0 22s
61+
pod/memcached-operator-df88b85f7-9s98n 2/2 Running 0 36s
62+
63+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
64+
service/memcached-operator-metrics ClusterIP 10.98.192.187 <none> 8383/TCP 31s
65+
66+
NAME READY UP-TO-DATE AVAILABLE AGE
67+
deployment.apps/example-memcached-memcached 3/3 3 3 22s
68+
deployment.apps/memcached-operator 1/1 1 1 36s
69+
70+
NAME DESIRED CURRENT READY AGE
71+
replicaset.apps/example-memcached-memcached-b885dcc75 3 3 3 22s
72+
replicaset.apps/memcached-operator-df88b85f7 1 1 1 36s
73+
```
74+
75+
### Uninstalling
76+
77+
To uninstall all that was performed in the above step run `make uninstall`.
78+
79+
### Troubleshooting
80+
81+
Use the following command to check the operator logs.
82+
83+
```
84+
kubectl logs deployment.apps/memcached-operator -c operator -n memcached
85+
```
86+
87+
Use the following command to check the Ansible logs.
88+
89+
```
90+
kubectl logs deployment.apps/memcached-operator -c ansible -n memcached
91+
```
92+
93+
**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]
94+
95+
### Testing the Operator
96+
97+
See [Testing Ansible Operators with Molecule][ansible-test-guide] documentation to know how to use the operator framework features to test it.
98+
99+
[python]: https://www.python.org/
100+
[ansible]: https://www.ansible.com/
101+
[kubectl_tool]: https://kubernetes.io/docs/tasks/tools/install-kubectl/
102+
[docker_tool]: https://docs.docker.com/install/
103+
[operator_sdk]: https://github.com/operator-framework/operator-sdk
104+
[operator_install]: https://github.com/operator-framework/operator-sdk/blob/master/doc/user/install-operator-sdk.md
105+
[ansible-test-guide]: https://github.com/operator-framework/operator-sdk/blob/master/doc/ansible/dev/testing_guide.md
106+
[ansible-guide]: https://github.com/operator-framework/operator-sdk/blob/master/doc/ansible/user-guide.md
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM quay.io/water-hole/ansible-operator
1+
FROM quay.io/operator-framework/ansible-operator:v0.10.0
22

3-
COPY roles/ ${HOME}/roles/
43
COPY watches.yaml ${HOME}/watches.yaml
4+
5+
COPY roles/ ${HOME}/roles/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ARG BASEIMAGE
2+
FROM ${BASEIMAGE}
3+
USER 0
4+
5+
# Ensure fresh metadata rather than cached metadata in the base by running
6+
# yum clean all && rm -rf /var/yum/cache/* first
7+
RUN yum clean all && rm -rf /var/cache/yum/* \
8+
&& yum -y update \
9+
&& yum install -y python36-devel python36-pip gcc libffi-devel
10+
RUN pip3 install --user molecule==2.22
11+
12+
ARG NAMESPACEDMAN
13+
ADD $NAMESPACEDMAN /namespaced.yaml
14+
ADD build/test-framework/ansible-test.sh /ansible-test.sh
15+
RUN chmod +x /ansible-test.sh
16+
USER 1001
17+
ADD . /opt/ansible/project
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
export WATCH_NAMESPACE=${TEST_NAMESPACE}
3+
(/usr/local/bin/entrypoint)&
4+
trap "kill $!" SIGINT SIGTERM EXIT
5+
6+
cd ${HOME}/project
7+
exec molecule test -s test-cluster
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
apiVersion: "cache.example.com/v1alpha1"
2-
kind: "Memcached"
1+
apiVersion: cache.example.com/v1alpha1
2+
kind: Memcached
33
metadata:
4-
name: "example"
4+
name: example-memcached
55
spec:
6+
# Add fields here
67
size: 3

ansible/memcached-operator/deploy/crds/cache_v1alpha1_memcached_crd.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ spec:
1010
plural: memcacheds
1111
singular: memcached
1212
scope: Namespaced
13-
version: v1alpha1
13+
subresources:
14+
status: {}
15+
versions:
16+
- name: v1alpha1
17+
served: true
18+
storage: true

ansible/memcached-operator/deploy/operator.yaml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,42 @@ spec:
1212
labels:
1313
name: memcached-operator
1414
spec:
15+
serviceAccountName: memcached-operator
1516
containers:
16-
- name: memcached-operator
17-
image: docker.io/dymurray/memcached-operator
18-
ports:
19-
- containerPort: 60000
20-
name: metrics
21-
imagePullPolicy: Always
17+
- name: ansible
18+
command:
19+
- /usr/local/bin/ao-logs
20+
- /tmp/ansible-operator/runner
21+
- stdout
22+
# Replace this with the built image name
23+
image: "REPLACE_IMAGE"
24+
imagePullPolicy: "Always"
25+
volumeMounts:
26+
- mountPath: /tmp/ansible-operator/runner
27+
name: runner
28+
readOnly: true
29+
- name: operator
30+
# Replace this with the built image name
31+
image: "REPLACE_IMAGE"
32+
imagePullPolicy: "Always"
33+
volumeMounts:
34+
- mountPath: /tmp/ansible-operator/runner
35+
name: runner
2236
env:
2337
- name: WATCH_NAMESPACE
2438
valueFrom:
2539
fieldRef:
2640
fieldPath: metadata.namespace
41+
- name: POD_NAME
42+
valueFrom:
43+
fieldRef:
44+
fieldPath: metadata.name
2745
- name: OPERATOR_NAME
2846
value: "memcached-operator"
47+
- name: ANSIBLE_GATHERING
48+
value: explicit
49+
- name: ANSIBLE_VERBOSITY
50+
value: "4"
51+
volumes:
52+
- name: runner
53+
emptyDir: {}

ansible/memcached-operator/deploy/role.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ rules:
99
resources:
1010
- pods
1111
- services
12+
- services/finalizers
1213
- endpoints
1314
- persistentvolumeclaims
1415
- events
@@ -25,6 +26,33 @@ rules:
2526
- statefulsets
2627
verbs:
2728
- '*'
29+
- apiGroups:
30+
- monitoring.coreos.com
31+
resources:
32+
- servicemonitors
33+
verbs:
34+
- get
35+
- create
36+
- apiGroups:
37+
- apps
38+
resourceNames:
39+
- memcached-operator
40+
resources:
41+
- deployments/finalizers
42+
verbs:
43+
- update
44+
- apiGroups:
45+
- ""
46+
resources:
47+
- pods
48+
verbs:
49+
- get
50+
- apiGroups:
51+
- apps
52+
resources:
53+
- replicasets
54+
verbs:
55+
- get
2856
- apiGroups:
2957
- cache.example.com
3058
resources:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
3+
- name: Verify
4+
hosts: localhost
5+
connection: local
6+
vars:
7+
ansible_python_interpreter: '{{ ansible_playbook_python }}'
8+
tasks:
9+
- name: Get all pods in {{ namespace }}
10+
k8s_facts:
11+
api_version: v1
12+
kind: Pod
13+
namespace: '{{ namespace }}'
14+
register: pods
15+
16+
- name: Output pods
17+
debug: var=pods

0 commit comments

Comments
 (0)