diff --git a/.github/cr.yaml b/.github/cr.yaml new file mode 100644 index 000000000..9f7b9ab93 --- /dev/null +++ b/.github/cr.yaml @@ -0,0 +1 @@ +release-name-template: "helm-chart-{{ .Name }}-{{ .Version }}" \ No newline at end of file diff --git a/.github/workflows/helm-chart-release.yaml b/.github/workflows/helm-chart-release.yaml new file mode 100644 index 000000000..daadccf7a --- /dev/null +++ b/.github/workflows/helm-chart-release.yaml @@ -0,0 +1,27 @@ +name: Release Helm Charts + +on: + push: + branches: + - master + paths: + - "charts/**" + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.2.1 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + with: + config: .github/cr.yaml \ No newline at end of file diff --git a/README.md b/README.md index a6aff1ae5..cbc8565ee 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,20 @@ Install Common Snapshot Controller: * kubectl -n kube-system kustomize deploy/kubernetes/snapshot-controller | kubectl create -f - * Do this once per cluster +Alternatively, you could also install the snapshot-controller using Helm: + +Add the snapshot-controller Helm repository: +```sh +helm repo add snapshot-controller https://github.com/kubernetes-csi/external-snapshotter +helm repo update +``` +Then install a release of the snapshot-controller using the chart +```sh +helm upgrade --install snapshot-controller \ + --namespace kube-system \ + https://github.com/kubernetes-csi/external-snapshotter/releases/download/helm-chart-snapshot-controller-4.2.1/snapshot-controller-4.2.1.tgz +``` + Install CSI Driver: * Follow instructions provided by your CSI Driver vendor. * Here is an example to install the sample hostpath CSI driver diff --git a/charts/snapshot-controller/.helmignore b/charts/snapshot-controller/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/charts/snapshot-controller/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/snapshot-controller/Chart.yaml b/charts/snapshot-controller/Chart.yaml new file mode 100644 index 000000000..8b8646eae --- /dev/null +++ b/charts/snapshot-controller/Chart.yaml @@ -0,0 +1,28 @@ +apiVersion: v2 +name: snapshot-controller +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 4.2.3 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "4.2.1" + +maintainers: + - name: kaskol10 + url: https://github.com/kaskol10 \ No newline at end of file diff --git a/charts/snapshot-controller/README.md b/charts/snapshot-controller/README.md new file mode 100644 index 000000000..5a52564d9 --- /dev/null +++ b/charts/snapshot-controller/README.md @@ -0,0 +1,48 @@ +# snapshot-controller + +![Version: 4.2.1](https://img.shields.io/badge/Version-4.2.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 4.2.1](https://img.shields.io/badge/AppVersion-4.2.1-informational?style=flat-square) + +A Helm chart for Kubernetes + +## Maintainers + +| Name | Email | Url | +| ---- | ------ | --- | +| kaskol10 | | https://github.com/kaskol10 | + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| affinity | object | `{}` | Node Affinity and inter-pod affinity/anti-affinity | +| args | list | `["--v=5","--leader-election=true","--http-endpoint=:8080"]` | Possible arguments can be found in the [Snapshot Controller command-line options](https://github.com/kubernetes-csi/external-snapshotter#snapshot-controller-command-line-options) | +| autoscaling.enabled | bool | `false` | | +| autoscaling.maxReplicas | int | `100` | HPA Max Replicas | +| autoscaling.minReplicas | int | `1` | | +| autoscaling.targetCPUUtilizationPercentage | int | `80` | | +| fullnameOverride | string | `""` | Full name override | +| image.pullPolicy | string | `"IfNotPresent"` | Image pull policy strategy when the kubelet attempts to pull(download) the specified image | +| image.repository | string | `"gcr.io/k8s-staging-sig-storage/snapshot-controller"` | Image to use for deploying | +| image.tag | string | `"v5.0.0-rc1"` | Overrides the image tag whose default is the chart appVersion. | +| imagePullSecrets | list | `[]` | Add image pull secrets if requires | +| minReadySeconds | int | `15` | The snapshot controller won't be marked as ready if the v1 CRDs are unavailable in [#504](https://github.com/kubernetes-csi/external-snapshotter/pull/504) the snapshot-controller will exit after around 7.5 seconds if it can't find the v1 CRDs so this value should be greater than that | +| nameOverride | string | `""` | Naming override | +| nodeSelector | object | `{}` | Node selection constraint | +| podAnnotations | object | `{}` | | +| podSecurityContext | object | `{}` | | +| rbac.create | bool | `true` | Create all the RBAC resources needed | +| replicaCount | int | `2` | Number of replicas in the deployment | +| resources | object | `{}` | | +| rollingUpdate | object | `{"enabled":true,"maxSurge":0,"maxUnavailable":1}` | Rolling update configuration | +| rollingUpdate.enabled | bool | `true` | Enable/disable rolling updates (default: true) | +| rollingUpdate.maxSurge | int | `0` | Max number of pods that can be created above the desired number of replicas | +| securityContext | object | `{}` | | +| service.port | int | `8080` | | +| service.type | string | `"ClusterIP"` | | +| serviceAccount.annotations | object | `{}` | Annotations to add to the service account | +| serviceAccount.create | bool | `true` | Specifies whether a service account should be created | +| serviceAccount.name | string | `""` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template | +| tolerations | list | `[]` | Allow the pods to schedule onto nodes with matching taints | + +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.5.0](https://github.com/norwoodj/helm-docs/releases/v1.5.0) diff --git a/charts/snapshot-controller/templates/NOTES.txt b/charts/snapshot-controller/templates/NOTES.txt new file mode 100644 index 000000000..7fff02ef9 --- /dev/null +++ b/charts/snapshot-controller/templates/NOTES.txt @@ -0,0 +1,5 @@ + + +To verify that snapshot-controller has started, run: + + kubectl get pod -n {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "snapshot-controller.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" \ No newline at end of file diff --git a/charts/snapshot-controller/templates/_helpers.tpl b/charts/snapshot-controller/templates/_helpers.tpl new file mode 100644 index 000000000..46f88cbb8 --- /dev/null +++ b/charts/snapshot-controller/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "snapshot-controller.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 "snapshot-controller.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 }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "snapshot-controller.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "snapshot-controller.labels" -}} +helm.sh/chart: {{ include "snapshot-controller.chart" . }} +{{ include "snapshot-controller.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "snapshot-controller.selectorLabels" -}} +app.kubernetes.io/name: {{ include "snapshot-controller.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "snapshot-controller.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "snapshot-controller.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/snapshot-controller/templates/deployment.yaml b/charts/snapshot-controller/templates/deployment.yaml new file mode 100644 index 000000000..e0f2ef7a6 --- /dev/null +++ b/charts/snapshot-controller/templates/deployment.yaml @@ -0,0 +1,81 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "snapshot-controller.fullname" . }} + labels: + {{- include "snapshot-controller.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + minReadySeconds: {{ .Values.minReadySeconds | default 15 }} + strategy: + {{- if $.Values.rollingUpdate }} + {{- if $.Values.rollingUpdate.enabled }} + type: RollingUpdate + rollingUpdate: + maxSurge: {{ $.Values.rollingUpdate.maxSurge | default 0 }} + maxUnavailable: {{ $.Values.rollingUpdate.maxUnavailable | default 1 }} + {{- else }} + type: Recreate + {{- end }} + {{- else }} + type: Recreate + {{- end }} + selector: + matchLabels: + {{- include "snapshot-controller.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "snapshot-controller.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "snapshot-controller.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- with .Values.args }} + args: + {{- range . }} + - {{ . | quote }} + {{- end }} + {{- end }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: healthz/leader-election + port: http + readinessProbe: + httpGet: + path: healthz/leader-election + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/snapshot-controller/templates/hpa.yaml b/charts/snapshot-controller/templates/hpa.yaml new file mode 100644 index 000000000..52eef4627 --- /dev/null +++ b/charts/snapshot-controller/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "snapshot-controller.fullname" . }} + labels: + {{- include "snapshot-controller.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "snapshot-controller.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/snapshot-controller/templates/rbac.yaml b/charts/snapshot-controller/templates/rbac.yaml new file mode 100644 index 000000000..6fcad6d06 --- /dev/null +++ b/charts/snapshot-controller/templates/rbac.yaml @@ -0,0 +1,81 @@ +{{ if .Values.rbac.create }} +{{- $serviceName := include "snapshot-controller.fullname" . -}} + +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ $serviceName }}-runner + labels: + {{- include "snapshot-controller.labels" . | nindent 4 }} +rules: + - apiGroups: [""] + resources: ["persistentvolumes"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["persistentvolumeclaims"] + verbs: ["get", "list", "watch", "update"] + - apiGroups: ["storage.k8s.io"] + resources: ["storageclasses"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["events"] + verbs: ["list", "watch", "create", "update", "patch"] + - apiGroups: ["snapshot.storage.k8s.io"] + resources: ["volumesnapshotclasses"] + verbs: ["get", "list", "watch"] + - apiGroups: ["snapshot.storage.k8s.io"] + resources: ["volumesnapshotcontents"] + verbs: ["create", "get", "list", "watch", "update", "delete", "patch"] + - apiGroups: ["snapshot.storage.k8s.io"] + resources: ["volumesnapshots"] + verbs: ["get", "list", "watch", "update", "patch"] + - apiGroups: ["snapshot.storage.k8s.io"] + resources: ["volumesnapshots/status"] + verbs: ["update"] + +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ $serviceName }}-role + labels: + {{- include "snapshot-controller.labels" . | nindent 4 }} +subjects: + - kind: ServiceAccount + name: {{ include "snapshot-controller.serviceAccountName" . }} + namespace: {{ .Release.Namespace}} +roleRef: + kind: ClusterRole + name: {{ $serviceName }}-runner + apiGroup: rbac.authorization.k8s.io + +--- +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ $serviceName }}-leaderelection + namespace: {{ .Release.Namespace}} + labels: + {{- include "snapshot-controller.labels" . | nindent 4 }} +rules: +- apiGroups: ["coordination.k8s.io"] + resources: ["leases"] + verbs: ["get", "watch", "list", "delete", "update", "create"] + +--- +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ $serviceName }}-leaderelection + labels: + {{- include "snapshot-controller.labels" . | nindent 4 }} +subjects: + - kind: ServiceAccount + name: {{ include "snapshot-controller.serviceAccountName" . }} +roleRef: + kind: Role + name: {{ $serviceName }}-leaderelection + apiGroup: rbac.authorization.k8s.io + + +{{ end }} \ No newline at end of file diff --git a/charts/snapshot-controller/templates/service.yaml b/charts/snapshot-controller/templates/service.yaml new file mode 100644 index 000000000..f3fbfab67 --- /dev/null +++ b/charts/snapshot-controller/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "snapshot-controller.fullname" . }} + labels: + {{- include "snapshot-controller.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "snapshot-controller.selectorLabels" . | nindent 4 }} diff --git a/charts/snapshot-controller/templates/serviceaccount.yaml b/charts/snapshot-controller/templates/serviceaccount.yaml new file mode 100644 index 000000000..4aa466c20 --- /dev/null +++ b/charts/snapshot-controller/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "snapshot-controller.serviceAccountName" . }} + labels: + {{- include "snapshot-controller.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/snapshot-controller/values.yaml b/charts/snapshot-controller/values.yaml new file mode 100644 index 000000000..2c660e442 --- /dev/null +++ b/charts/snapshot-controller/values.yaml @@ -0,0 +1,108 @@ +# Default values for snapshot-controller. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# -- Number of replicas in the deployment +replicaCount: 2 + +image: + # -- Image to use for deploying + repository: gcr.io/k8s-staging-sig-storage/snapshot-controller + # -- Image pull policy strategy when the kubelet attempts to pull(download) the specified image + pullPolicy: IfNotPresent + # -- Overrides the image tag whose default is the chart appVersion. + tag: "v5.0.0-rc1" + +# -- Add image pull secrets if requires +imagePullSecrets: [] +# -- Naming override +nameOverride: "" +# -- Full name override +fullnameOverride: "" + +# -- Possible arguments can be found in the [Snapshot Controller command-line options](https://github.com/kubernetes-csi/external-snapshotter#snapshot-controller-command-line-options) +args: + - "--v=5" + - "--leader-election=true" + - "--http-endpoint=:8080" + +# -- The snapshot controller won't be marked as ready +# if the v1 CRDs are unavailable in [#504](https://github.com/kubernetes-csi/external-snapshotter/pull/504) +# the snapshot-controller will exit after around 7.5 seconds if it can't find the v1 CRDs +# so this value should be greater than that +minReadySeconds: 15 + +serviceAccount: + # -- Specifies whether a service account should be created + create: true + # -- Annotations to add to the service account + annotations: {} + # -- The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 8080 + + + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + # -- Enabling if requires + enabled: false + # -- HPA Min Replicas + minReplicas: 1 + # -- HPA Max Replicas + maxReplicas: 100 + # -- HPA action + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# -- Rolling update configuration +rollingUpdate: + # -- Enable/disable rolling updates (default: true) + enabled: true + # -- Max number of pods that can be created above the desired number of replicas + maxSurge: 0 + # -- Max number of pods that can be unavailable during rolling update + maxUnavailable: 1 + +# -- Node selection constraint + +nodeSelector: {} + +# -- Allow the pods to schedule onto nodes with matching taints +tolerations: [] + +# -- Node Affinity and inter-pod affinity/anti-affinity + +affinity: {} + +rbac: + # -- Create all the RBAC resources needed + create: true \ No newline at end of file