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

Upgrade helm sample to 0.11.0 version of SDK #78

Merged
merged 5 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/*
helm/memcached-operator/.idea/*
ansible/memcached-operator/.idea/*
37 changes: 37 additions & 0 deletions helm/memcached-operator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.DEFAULT_GOAL:=help
SHELL:=/bin/bash
NAMESPACE=helm-memcached

##@ Application

install: ## Install all resources (CR/CRD's, RBCA and Operator)
@echo ....... Creating namespace .......
- kubectl create namespace ${NAMESPACE}
@echo ....... Applying CRDS and Operator .......
- kubectl apply -f deploy/crds/cache.example.com_v1alpha1_memcached_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 Memcached Instance .......
- 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 CR and CRD.......
- kubectl apply -f deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml -n ${NAMESPACE}
- kubectl delete -f deploy/crds/cache.example.com_v1alpha1_memcached_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<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)
107 changes: 107 additions & 0 deletions helm/memcached-operator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Memcached Helm Operator

## Overview

This Memcached operator is a simple example of the Operator SDK Helm-based operator. It is based on the [`stable/memcached` chart][stable/memcached] .

## Prerequisites

- [docker][docker_tool] version 17.03+
- [kubectl][kubectl_tool] v1.12+
- [operator SDK][operator_install]
- Access to a Kubernetes v1.14.5+ cluster

## Getting Started

### Cloning the repository

Checkout this Memcached operator repository

```
$ mkdir operator-framework
$ cd operator-framework
$ git clone https://github.com/operator-framework/operator-sdk-samples.git
$ cd operator-sdk-samples/helm/memcached-operator
```

### Building the operator

Build the Memcached operator image and push it to a public registry, such as quay.io:

```
$ export IMAGE=quay.io/example-inc/memcached-operator:v0.0.1
$ operator-sdk build $IMAGE
$ docker push $IMAGE
```

**NOTE** The `quay.io/example-inc/memcached-operator` is an example. You should build and push the image for your repository.

### Using the image

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|g' deploy/operator.yaml
```

**Note**
If you are performing these steps on OSX, use the following `sed` command instead:
```
$ sed -i "" 's|REPLACE_IMAGE|quay.io/example-inc/memcached-operator|g' deploy/operator.yaml
```

### 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.

Run the following command to verify that the installation was successful:

```shell
$ kubectl get all -n helm-memcached -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/example-memcached-0 1/1 Running 0 37s 172.17.0.5 minikube <none> <none>
pod/example-memcached-1 1/1 Running 0 19s 172.17.0.6 minikube <none> <none>
pod/example-memcached-2 1/1 Running 0 12s 172.17.0.7 minikube <none> <none>
pod/memcached-operator-55d98c7cf8-x6x9p 1/1 Running 0 52s 172.17.0.4 minikube <none> <none>

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/example-memcached ClusterIP None <none> 11211/TCP 37s app=example-memcached
service/memcached-operator-metrics ClusterIP 10.96.212.206 <none> 8686/TCP,8383/TCP 38s name=memcached-operator

NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/memcached-operator 1/1 1 1 52s memcached-operator cmacedo/memcached-operator:test name=memcached-operator

NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/memcached-operator-55d98c7cf8 1 1 1 52s memcached-operator cmacedo/memcached-operator:test name=memcached-operator,pod-template-hash=55d98c7cf8

NAME READY AGE CONTAINERS IMAGES
statefulset.apps/example-memcached 3/3 37s example-memcached memcached:1.5.12-alpine
```

### Uninstalling

Run `make uninstall` to uninstall all that was performed in the above step.

### Troubleshooting

Run the following command to check the operator logs.

```shell
kubectl logs deployment.apps/memcached-operator -n helm-memcached
```

**NOTE** For further information about how to develop Helm operators with Operator SDK, read the [Helm User Guide for Operator SDK][helm_guide]

### Extras

This project was created by using the following command, which means that it is using the official [stable/memcached][stable/memcached] helm chart.

```shell
operator-sdk new memcached-operator --api-version=cache.example.com/v1alpha1 --kind=Memcached --type=helm --helm-chart=stable/memcached
```

[kubectl_tool]: https://kubernetes.io/docs/tasks/tools/install-kubectl/
[docker_tool]: https://docs.docker.com/install/
[operator_install]: https://github.com/operator-framework/operator-sdk/blob/master/doc/user/install-operator-sdk.md
[helm_guide]: https://github.com/operator-framework/operator-sdk/blob/master/doc/helm/user-guide.md
[stable/memcached]: https://github.com/helm/charts/tree/master/stable/memcached
4 changes: 2 additions & 2 deletions helm/memcached-operator/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM quay.io/operator-framework/helm-operator:v0.5.0
FROM quay.io/operator-framework/helm-operator:v0.11.0

COPY helm-charts/ ${HOME}/helm-charts/
COPY watches.yaml ${HOME}/watches.yaml
COPY helm-charts/ ${HOME}/helm-charts/
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
apiVersion: cache.example.com/v1alpha1
kind: Memcached
metadata:
name: example-memcached
spec:
# Default values copied from <project_dir>/helm-charts/memcached/values.yaml

## Memcached image and tag
## ref: https://hub.docker.com/r/library/memcached/tags/
##
image: memcached:1.5.12-alpine

## Specify a imagePullPolicy
## 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
##
# imagePullPolicy:
#

## Replica count
replicaCount: 3

## Pod disruption budget minAvailable count
## Ensure this value is lower than replicaCount in order to allow a worker
## node to drain successfully
pdbMinAvailable: 2

## Select AntiAffinity as either hard or soft, default is hard
AntiAffinity: "soft"

memcached:
## Various values that get set as command-line flags.
## ref: https://github.com/memcached/memcached/wiki/ConfiguringServer#commandline-arguments
##
maxItemMemory: 64
verbosity: v
extendedOptions: modern

## Additional command line arguments to pass to memcached
## E.g. to specify a maximum value size
## extraArgs:
## - -I 2m
extraArgs: []

## Define various attributes of the service
serviceAnnotations: {}
# prometheus.io/scrape: "true"

## StatefulSet or Deployment
kind: StatefulSet

## Update Strategy for the StatefulSet or Deployment
## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies
## ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#updating-a-deployment
updateStrategy:
type: RollingUpdate

## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources:
requests:
memory: 64Mi
cpu: 50m

## Key:value pair for assigning pod to specific sets of nodes
## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
nodeSelector: {}

## ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
tolerations: {}

## Advanced scheduling controls
## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
affinity: {}

## Memcached pod Security Context
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
securityContext:
enabled: true
fsGroup: 1001
runAsUser: 1001

metrics:
## Expose memcached metrics in Prometheus format
enabled: false

## Memcached exporter image and tag
image: quay.io/prometheus/memcached-exporter:v0.4.1

## Specify a imagePullPolicy
## 'Always' if imageTag is 'latest', else set to 'IfNotPresent'
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
##
# imagePullPolicy: IfNotPresent

## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources: {}

extraContainers: |

extraVolumes: |

## Custom metadata labels to be applied to statefulset and pods
# podLabels:
# foo: "bar"
# bar: "foo"

# To be added to the server pod(s)
podAnnotations: {}

## Set pod priority class
# priorityClassName: ""

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ spec:
plural: memcacheds
singular: memcached
scope: Namespaced
version: v1alpha1
subresources:
status: {}
versions:
- name: v1alpha1
served: true
storage: true

This file was deleted.

3 changes: 0 additions & 3 deletions helm/memcached-operator/deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ spec:
- name: memcached-operator
# Replace this with the built image name
image: REPLACE_IMAGE
ports:
- containerPort: 60000
name: metrics
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
Expand Down
44 changes: 35 additions & 9 deletions helm/memcached-operator/deploy/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,63 @@ rules:
- apiGroups:
- ""
resources:
- pods
- services
- endpoints
- persistentvolumeclaims
- events
- namespaces
verbs:
- get
- apiGroups:
- ""
resources:
- configmaps
- secrets
verbs:
- '*'
- apiGroups:
- ""
resources:
- namespaces
- services
verbs:
- get
- '*'
- apiGroups:
- apps
resources:
- deployments
- daemonsets
- replicasets
- statefulsets
verbs:
- '*'
- apiGroups:
- policy
resources:
- poddisruptionbudgets
verbs:
- '*'
- 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:
Expand Down
Loading