diff --git a/incubator/cassandra-operator/Chart.yaml b/incubator/cassandra-operator/Chart.yaml new file mode 100644 index 0000000000..f1b0d01d6a --- /dev/null +++ b/incubator/cassandra-operator/Chart.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +description: A Helm chart for CassKop - the Orange Cassandra Kubernetes operator +name: cassandra-operator +home: https://github.com/Orange-OpenSource/cassandra-k8s-operator +sources: + - https://github.com/Orange-OpenSource/cassandra-k8s-operator +version: 0.3.1 +appVersion: 0.3.1-mater +maintainers: + - name: allamand + email: sebastien.allamand@orange.com + - name: Orange-cscetbon + email: cscetbon.ext@orange.com + - name: jal06 + email: jeanarmel.luce@orange.com +keywords: +- operator +- cassandra +- casskop diff --git a/incubator/cassandra-operator/OWNERS b/incubator/cassandra-operator/OWNERS new file mode 100644 index 0000000000..48d06d2fd8 --- /dev/null +++ b/incubator/cassandra-operator/OWNERS @@ -0,0 +1,8 @@ +approvers: +- allamand +- jal06 +- Orange-cscetbon +reviewers: +- allamand +- jal06 +- Orange-cscetbon diff --git a/incubator/cassandra-operator/readme.md b/incubator/cassandra-operator/readme.md new file mode 100644 index 0000000000..c0fa2b4063 --- /dev/null +++ b/incubator/cassandra-operator/readme.md @@ -0,0 +1,139 @@ + +# CassKop - Cassandra Kubernetes operator Helm chart + +This Helm chart install CassKop the Orange's Cassandra Kubernetes operator to create/configure/manage Cassandra +clusters in a Kubernetes Namespace. +It will uses a Custom Ressource Definition CRD: `cassandraclusters.db.orange.com`, +which implements a `CassandraCluster` kubernetes custom ressource definition. + + +## Introduction + + +### Configuration + +The following tables lists the configurable parameters of the Cassandra Operator Helm chart and their default values. + + +| Parameter | Description | Default | +|----------------------------------|--------------------------------------------------|-------------------------------------------| +| `image.repository` | Image | `orangeopensource/cassandra-k8s-operator` | +| `image.tag` | Image tag | `0.3.1-master` | +| `image.pullPolicy` | Image pull policy | `Always` | +| `image.imagePullSecrets.enabled` | Enable tue use of secret for docker image | `false` | +| `image.imagePullSecrets.name` | Name of the secret to connect to docker registry | - | +| `rbacEnable` | If true, create & use RBAC resources | `true` | +| `resources` | Pod resource requests & limits | `{}` | +| `metricService` | deploy service for metrics | `false` | +| `debug.enabled` | activate DEBUG log level | `false` | + + + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, + +```console +$ helm install --name casskop incubator/cassandra-operator -f values.yaml +``` + +### Installing the Chart + +You can make a dry run of the chart before deploying : + +```console +helm install --dry-run --debug.enabled incubator/cassandra-operator --set debug.enabled=true --name casskop +``` + +To install the chart with the release name my-release: + +```console +$ helm install --name casskop incubator/cassandra-operator +``` + +We can surcharge default parameters using `--set` flag : + +```console +$ helm install --replace --set image.tag=asyncronous --name casskop incubator/cassandra-operator +``` + +> the `-replace` flag allow you to reuses a charts release name + + +### Listing deployed charts + +``` +helm list +``` + +### Get Status for the helm deployment : + +``` +helm status casskop + +``` + +## Uninstaling the Charts + +If you want to delete the operator from your Kubernetes cluster, the operator deployment +should be deleted. + +``` +$ helm delete casskop +``` +The command removes all the Kubernetes components associated with the chart and deletes the helm release. + +> The CRD created by the chart are not removed by default and should be manually cleaned up (if required) + +Manually delete the CRD: +``` +kubectl delete crd cassandraclusters.dfy.orange.com +``` + +> **!!!!!!!!WARNING!!!!!!!!** +> +> If you delete the CRD then **!!!!!!WAAAARRRRNNIIIIINNG!!!!!!** +> +> It will delete **ALL** Clusters that has been created using this CRD!!! +> +> Please never delete a CRD without very very good care + + +Helm always keeps records of what releases happened. Need to see the deleted releases? `helm list --deleted` +shows those, and `helm list --all` shows all of the releases (deleted and currently deployed, as well as releases that +failed): + +Because Helm keeps records of deleted releases, a release name cannot be re-used. (If you really need to re-use a +release name, you can use the `--replace` flag, but it will simply re-use the existing release and replace its +resources.) + +Note that because releases are preserved in this way, you can rollback a deleted resource, and have it re-activate. + + + +To purge a release +```console +$ helm delete --purge casskop +``` + + +## Troubleshooting + +### Install of the CRD + +By default, the chart will install via a helm hook the Casskop CRD, but this installation is global for the whole +cluster, and you may deploy a chart with an existing CRD already deployed. + +In that case you can get an error like : + + +``` +$ helm install --name casskop incubator/cassandra-operator +Error: customresourcedefinitions.apiextensions.k8s.io "cassandraclusters.db.orange.com" already exists +``` + +In this case there si a parameter to say to not uses the hook to install the CRD : + +``` +$ helm install --name casskop incubator/cassandra-operator --no-hooks +``` diff --git a/incubator/cassandra-operator/templates/NOTES.txt b/incubator/cassandra-operator/templates/NOTES.txt new file mode 100644 index 0000000000..c5ffc53034 --- /dev/null +++ b/incubator/cassandra-operator/templates/NOTES.txt @@ -0,0 +1,5 @@ +Congratulations. You have just deployed CassKop the Cassandra Operator. +Check its status by running: +kubectl --namespace {{ .Release.Namespace }} get pods -l "release={{ .Release.Name }}" + +Visit https://github.com/Orange-OpenSource/cassandra-k8s-operator for instructions on hot to create & configure Cassandra clusters using the operator. diff --git a/incubator/cassandra-operator/templates/_functions.tpl b/incubator/cassandra-operator/templates/_functions.tpl new file mode 100644 index 0000000000..ade27e9732 --- /dev/null +++ b/incubator/cassandra-operator/templates/_functions.tpl @@ -0,0 +1,33 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "cassandra-operator.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "cassandra-operator.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Return the appropriate apiVersion value to use for the capi-operator managed k8s resources +*/}} +{{- define "cassandra-operator.apiVersion" -}} +{{- printf "%s" "cassandraclusters.db.orange.com/v1alpha1" -}} +{{- end -}} + diff --git a/incubator/cassandra-operator/templates/db_v1alpha1_cassandracluster_crd.yaml b/incubator/cassandra-operator/templates/db_v1alpha1_cassandracluster_crd.yaml new file mode 100644 index 0000000000..e61fc35bf1 --- /dev/null +++ b/incubator/cassandra-operator/templates/db_v1alpha1_cassandracluster_crd.yaml @@ -0,0 +1,17 @@ +{{- if .Values.createCustomResource }} +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: cassandraclusters.db.orange.com + annotations: + "helm.sh/hook": crd-install +spec: + group: db.orange.com + names: + kind: CassandraCluster + listKind: CassandraClusterList + plural: cassandraclusters + singular: cassandracluster + scope: Namespaced + version: v1alpha1 +{{- end }} diff --git a/incubator/cassandra-operator/templates/deployment.yaml b/incubator/cassandra-operator/templates/deployment.yaml new file mode 100644 index 0000000000..daf591b96a --- /dev/null +++ b/incubator/cassandra-operator/templates/deployment.yaml @@ -0,0 +1,65 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "cassandra-operator.fullname" . }} + labels: + app: {{ template "cassandra-operator.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + heritage: {{ .Release.Service }} + operator: cassandra + release: {{ .Release.Name }} +spec: + replicas: 1 + selector: + matchLabels: + name: {{ template "cassandra-operator.name" . }} + template: + metadata: + labels: + name: {{ template "cassandra-operator.name" . }} + app: {{ template "cassandra-operator.name" . }} + operator: cassandra + release: {{ .Release.Name }} + spec: +{{- if .Values.image.imagePullSecrets.enabled }} + imagePullSecrets: + - name: {{ .Values.image.imagePullSecrets.name }} +{{- end }} +{{- if .Values.rbacEnable }} + serviceAccountName: {{ template "cassandra-operator.name" . }} +{{- end }} + securityContext: + runAsUser: 1000 + containers: + - name: {{ template "cassandra-operator.name" . }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: "{{ .Values.image.pullPolicy }}" + ports: + - containerPort: 60000 + name: metrics + command: + - cassandra-k8s-operator + readinessProbe: + exec: + command: + - /health + initialDelaySeconds: 4 + periodSeconds: 10 + failureThreshold: 1 + resources: +{{ toYaml .Values.resources | indent 10 }} + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: OPERATOR_NAME + value: "cassandra-operator" +{{- if .Values.debug }} + - name: LOG_LEVEL + value: Debug +{{- end }} diff --git a/incubator/cassandra-operator/templates/role.yaml b/incubator/cassandra-operator/templates/role.yaml new file mode 100644 index 0000000000..979c7f001a --- /dev/null +++ b/incubator/cassandra-operator/templates/role.yaml @@ -0,0 +1,59 @@ +{{- if .Values.rbacEnable }} +kind: Role +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + labels: + app: {{ template "cassandra-operator.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} + name: {{ template "cassandra-operator.name" . }} +rules: +- apiGroups: + - db.orange.com + resources: + - "*" + verbs: + - "*" +- apiGroups: + - "" + resources: + - pods + - pods/exec + - services + - endpoints + - persistentvolumeclaims + - events + - configmaps + - secrets + verbs: + - "*" +- apiGroups: + - "" + resources: + - namespaces + verbs: + - get +- apiGroups: + - apps + resources: + - deployments + - daemonsets + - replicasets + - statefulsets + verbs: + - "*" +- apiGroups: + - policy + resources: + - poddisruptionbudgets + verbs: + - "*" +- apiGroups: + - monitoring.coreos.com + resources: + - servicemonitors + verbs: + - "get" + - "create" +{{- end }} diff --git a/incubator/cassandra-operator/templates/rolebinding.yaml b/incubator/cassandra-operator/templates/rolebinding.yaml new file mode 100644 index 0000000000..c157a5591a --- /dev/null +++ b/incubator/cassandra-operator/templates/rolebinding.yaml @@ -0,0 +1,23 @@ +{{- if .Values.rbacEnable }} +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + labels: + app: {{ template "cassandra-operator.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} + name: {{ template "cassandra-operator.name" . }} +subjects: +- kind: ServiceAccount + labels: + app: {{ template "cassandra-operator.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} + name: {{ template "cassandra-operator.name" . }} +roleRef: + kind: Role + name: {{ template "cassandra-operator.name" . }} + apiGroup: rbac.authorization.k8s.io +{{- end }} diff --git a/incubator/cassandra-operator/templates/service.yaml b/incubator/cassandra-operator/templates/service.yaml new file mode 100644 index 0000000000..069db611dd --- /dev/null +++ b/incubator/cassandra-operator/templates/service.yaml @@ -0,0 +1,20 @@ +{{- if .Values.metricService }} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "cassandra-operator.name" . }}-metrics + labels: + component: app + labels: + app: {{ template "cassandra-operator.name" . }}-metrics + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} +spec: + selector: + app: {{ template "cassandra-operator.name" . }} + ports: + - name: metrics + port: 9710 + protocol: TCP +{{- end }} diff --git a/incubator/cassandra-operator/templates/service_account.yaml b/incubator/cassandra-operator/templates/service_account.yaml new file mode 100644 index 0000000000..bad22d227d --- /dev/null +++ b/incubator/cassandra-operator/templates/service_account.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app: {{ template "cassandra-operator.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} + name: {{ template "cassandra-operator.name" . }} diff --git a/incubator/cassandra-operator/values.yaml b/incubator/cassandra-operator/values.yaml new file mode 100644 index 0000000000..fda71967ad --- /dev/null +++ b/incubator/cassandra-operator/values.yaml @@ -0,0 +1,32 @@ +## Cassandra Operator Image +## +image: + repository: orangeopensource/cassandra-k8s-operator + tag: 0.3.1-master + pullPolicy: Always + imagePullSecrets: + enabled: false + # name: + +## Prometheus-operator resource limits & requests +## Ref: https://kubernetes.io/docs/user-guide/compute-resources/ +resources: + requests: + cpu: 10m + memory: 50Mi + limits: + cpu: 1 + memory: 512Mi + + +## If true, create & use RBAC resources +## +rbacEnable: true + +## if true deploy service for metrics access +metricService: false + +createCustomResource: false + +debug: + enabled: false