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

Commit eefb019

Browse files
Merge pull request #78 from camilamacedo86/updat-helm
Upgrade helm sample to 0.11.0 version of SDK
2 parents 98c56cb + 2c9a675 commit eefb019

21 files changed

+748
-133
lines changed

.gitignore

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

helm/memcached-operator/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.DEFAULT_GOAL:=help
2+
SHELL:=/bin/bash
3+
NAMESPACE=helm-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.example.com_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 Memcached Instance .......
19+
- kubectl apply -f deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml -n ${NAMESPACE}
20+
21+
uninstall: ## Uninstall all that all performed in the $ make install
22+
@echo ....... Uninstalling .......
23+
@echo ....... Deleting CR and CRD.......
24+
- kubectl apply -f deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml -n ${NAMESPACE}
25+
- kubectl delete -f deploy/crds/cache.example.com_v1alpha1_memcached_crd.yaml -n ${NAMESPACE}
26+
@echo ....... Deleting Rules and Service Account .......
27+
- kubectl delete -f deploy/role.yaml -n ${NAMESPACE}
28+
- kubectl delete -f deploy/role_binding.yaml -n ${NAMESPACE}
29+
- kubectl delete -f deploy/service_account.yaml -n ${NAMESPACE}
30+
@echo ....... Deleting Operator .......
31+
- kubectl delete -f deploy/operator.yaml -n ${NAMESPACE}
32+
@echo ....... Deleting namespace ${NAMESPACE}.......
33+
- kubectl delete namespace ${NAMESPACE}
34+
35+
.PHONY: help
36+
help: ## Display this help
37+
@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)

helm/memcached-operator/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Memcached Helm Operator
2+
3+
## Overview
4+
5+
This Memcached operator is a simple example of the Operator SDK Helm-based operator. It is based on the [`stable/memcached` chart][stable/memcached] .
6+
7+
## Prerequisites
8+
9+
- [docker][docker_tool] version 17.03+
10+
- [kubectl][kubectl_tool] v1.12+
11+
- [operator SDK][operator_install]
12+
- Access to a Kubernetes v1.14.5+ cluster
13+
14+
## Getting Started
15+
16+
### Cloning the repository
17+
18+
Checkout this Memcached operator repository
19+
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/helm/memcached-operator
25+
```
26+
27+
### Building the operator
28+
29+
Build the Memcached operator image and push it to a public registry, such as quay.io:
30+
31+
```
32+
$ export IMAGE=quay.io/example-inc/memcached-operator:v0.0.1
33+
$ operator-sdk build $IMAGE
34+
$ docker push $IMAGE
35+
```
36+
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+
Update the operator manifest to use the built image name (if you are performing these steps on OSX, see note below)
42+
43+
```
44+
$ sed -i 's|REPLACE_IMAGE|quay.io/example-inc/memcached-operator|g' deploy/operator.yaml
45+
```
46+
47+
**Note**
48+
If you are performing these steps on OSX, use the following `sed` command instead:
49+
```
50+
$ sed -i "" 's|REPLACE_IMAGE|quay.io/example-inc/memcached-operator|g' deploy/operator.yaml
51+
```
52+
53+
### Installing
54+
55+
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.
56+
57+
Run the following command to verify that the installation was successful:
58+
59+
```shell
60+
$ kubectl get all -n helm-memcached -o wide
61+
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
62+
pod/example-memcached-0 1/1 Running 0 37s 172.17.0.5 minikube <none> <none>
63+
pod/example-memcached-1 1/1 Running 0 19s 172.17.0.6 minikube <none> <none>
64+
pod/example-memcached-2 1/1 Running 0 12s 172.17.0.7 minikube <none> <none>
65+
pod/memcached-operator-55d98c7cf8-x6x9p 1/1 Running 0 52s 172.17.0.4 minikube <none> <none>
66+
67+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
68+
service/example-memcached ClusterIP None <none> 11211/TCP 37s app=example-memcached
69+
service/memcached-operator-metrics ClusterIP 10.96.212.206 <none> 8686/TCP,8383/TCP 38s name=memcached-operator
70+
71+
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
72+
deployment.apps/memcached-operator 1/1 1 1 52s memcached-operator cmacedo/memcached-operator:test name=memcached-operator
73+
74+
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
75+
replicaset.apps/memcached-operator-55d98c7cf8 1 1 1 52s memcached-operator cmacedo/memcached-operator:test name=memcached-operator,pod-template-hash=55d98c7cf8
76+
77+
NAME READY AGE CONTAINERS IMAGES
78+
statefulset.apps/example-memcached 3/3 37s example-memcached memcached:1.5.12-alpine
79+
```
80+
81+
### Uninstalling
82+
83+
Run `make uninstall` to uninstall all that was performed in the above step.
84+
85+
### Troubleshooting
86+
87+
Run the following command to check the operator logs.
88+
89+
```shell
90+
kubectl logs deployment.apps/memcached-operator -n helm-memcached
91+
```
92+
93+
**NOTE** For further information about how to develop Helm operators with Operator SDK, read the [Helm User Guide for Operator SDK][helm_guide]
94+
95+
### Extras
96+
97+
This project was created by using the following command, which means that it is using the official [stable/memcached][stable/memcached] helm chart.
98+
99+
```shell
100+
operator-sdk new memcached-operator --api-version=cache.example.com/v1alpha1 --kind=Memcached --type=helm --helm-chart=stable/memcached
101+
```
102+
103+
[kubectl_tool]: https://kubernetes.io/docs/tasks/tools/install-kubectl/
104+
[docker_tool]: https://docs.docker.com/install/
105+
[operator_install]: https://github.com/operator-framework/operator-sdk/blob/master/doc/user/install-operator-sdk.md
106+
[helm_guide]: https://github.com/operator-framework/operator-sdk/blob/master/doc/helm/user-guide.md
107+
[stable/memcached]: https://github.com/helm/charts/tree/master/stable/memcached
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM quay.io/operator-framework/helm-operator:v0.5.0
1+
FROM quay.io/operator-framework/helm-operator:v0.11.0
22

3-
COPY helm-charts/ ${HOME}/helm-charts/
43
COPY watches.yaml ${HOME}/watches.yaml
4+
COPY helm-charts/ ${HOME}/helm-charts/
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
apiVersion: cache.example.com/v1alpha1
2+
kind: Memcached
3+
metadata:
4+
name: example-memcached
5+
spec:
6+
# Default values copied from <project_dir>/helm-charts/memcached/values.yaml
7+
8+
## Memcached image and tag
9+
## ref: https://hub.docker.com/r/library/memcached/tags/
10+
##
11+
image: memcached:1.5.12-alpine
12+
13+
## Specify a imagePullPolicy
14+
## 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
15+
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
16+
##
17+
# imagePullPolicy:
18+
#
19+
20+
## Replica count
21+
replicaCount: 3
22+
23+
## Pod disruption budget minAvailable count
24+
## Ensure this value is lower than replicaCount in order to allow a worker
25+
## node to drain successfully
26+
pdbMinAvailable: 2
27+
28+
## Select AntiAffinity as either hard or soft, default is hard
29+
AntiAffinity: "soft"
30+
31+
memcached:
32+
## Various values that get set as command-line flags.
33+
## ref: https://github.com/memcached/memcached/wiki/ConfiguringServer#commandline-arguments
34+
##
35+
maxItemMemory: 64
36+
verbosity: v
37+
extendedOptions: modern
38+
39+
## Additional command line arguments to pass to memcached
40+
## E.g. to specify a maximum value size
41+
## extraArgs:
42+
## - -I 2m
43+
extraArgs: []
44+
45+
## Define various attributes of the service
46+
serviceAnnotations: {}
47+
# prometheus.io/scrape: "true"
48+
49+
## StatefulSet or Deployment
50+
kind: StatefulSet
51+
52+
## Update Strategy for the StatefulSet or Deployment
53+
## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies
54+
## ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#updating-a-deployment
55+
updateStrategy:
56+
type: RollingUpdate
57+
58+
## Configure resource requests and limits
59+
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
60+
##
61+
resources:
62+
requests:
63+
memory: 64Mi
64+
cpu: 50m
65+
66+
## Key:value pair for assigning pod to specific sets of nodes
67+
## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
68+
nodeSelector: {}
69+
70+
## ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
71+
tolerations: {}
72+
73+
## Advanced scheduling controls
74+
## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
75+
affinity: {}
76+
77+
## Memcached pod Security Context
78+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
79+
securityContext:
80+
enabled: true
81+
fsGroup: 1001
82+
runAsUser: 1001
83+
84+
metrics:
85+
## Expose memcached metrics in Prometheus format
86+
enabled: false
87+
88+
## Memcached exporter image and tag
89+
image: quay.io/prometheus/memcached-exporter:v0.4.1
90+
91+
## Specify a imagePullPolicy
92+
## 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
93+
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
94+
##
95+
# imagePullPolicy: IfNotPresent
96+
97+
## Configure resource requests and limits
98+
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
99+
##
100+
resources: {}
101+
102+
extraContainers: |
103+
104+
extraVolumes: |
105+
106+
## Custom metadata labels to be applied to statefulset and pods
107+
# podLabels:
108+
# foo: "bar"
109+
# bar: "foo"
110+
111+
# To be added to the server pod(s)
112+
podAnnotations: {}
113+
114+
## Set pod priority class
115+
# priorityClassName: ""
116+

helm/memcached-operator/deploy/crds/cache_v1alpha1_memcached_crd.yaml renamed to helm/memcached-operator/deploy/crds/cache.example.com_v1alpha1_memcached_crd.yaml

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

helm/memcached-operator/deploy/crds/cache_v1alpha1_memcached_cr.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

helm/memcached-operator/deploy/operator.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ spec:
1717
- name: memcached-operator
1818
# Replace this with the built image name
1919
image: REPLACE_IMAGE
20-
ports:
21-
- containerPort: 60000
22-
name: metrics
2320
imagePullPolicy: Always
2421
env:
2522
- name: WATCH_NAMESPACE

helm/memcached-operator/deploy/role.yaml

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,63 @@ rules:
77
- apiGroups:
88
- ""
99
resources:
10-
- pods
11-
- services
12-
- endpoints
13-
- persistentvolumeclaims
14-
- events
10+
- namespaces
11+
verbs:
12+
- get
13+
- apiGroups:
14+
- ""
15+
resources:
1516
- configmaps
1617
- secrets
1718
verbs:
1819
- '*'
1920
- apiGroups:
2021
- ""
2122
resources:
22-
- namespaces
23+
- services
2324
verbs:
24-
- get
25+
- '*'
2526
- apiGroups:
2627
- apps
2728
resources:
2829
- deployments
29-
- daemonsets
30-
- replicasets
3130
- statefulsets
3231
verbs:
3332
- '*'
33+
- apiGroups:
34+
- policy
35+
resources:
36+
- poddisruptionbudgets
37+
verbs:
38+
- '*'
3439
- apiGroups:
3540
- monitoring.coreos.com
3641
resources:
3742
- servicemonitors
3843
verbs:
3944
- get
4045
- create
46+
- apiGroups:
47+
- apps
48+
resourceNames:
49+
- memcached-operator
50+
resources:
51+
- deployments/finalizers
52+
verbs:
53+
- update
54+
- apiGroups:
55+
- ""
56+
resources:
57+
- pods
58+
verbs:
59+
- get
60+
- apiGroups:
61+
- apps
62+
resources:
63+
- replicasets
64+
- deployments
65+
verbs:
66+
- get
4167
- apiGroups:
4268
- cache.example.com
4369
resources:

0 commit comments

Comments
 (0)