From 0cb60fe0c66a2e20492fc4873f3e643c38af953a Mon Sep 17 00:00:00 2001 From: Gaurav Mehta Date: Tue, 24 Jan 2023 15:42:23 +1100 Subject: [PATCH] initial commit for harvester-seeder helm chart add default for embedded mode in seeder chart update image to main-head for master branch fix rbac for hardware drop node selector for beta.kubernetes.io/os changes based on feedback on PR fix chart linting errors --- charts/harvester-seeder/.helmignore | 23 ++++ charts/harvester-seeder/Chart.yaml | 27 ++++ .../harvester-seeder/templates/_helpers.tpl | 62 +++++++++ .../templates/deployment.yaml | 78 +++++++++++ charts/harvester-seeder/templates/rbac.yaml | 121 ++++++++++++++++++ .../templates/role-binding.yaml | 25 ++++ .../harvester-seeder/templates/service.yaml | 15 +++ .../templates/serviceaccount.yaml | 12 ++ charts/harvester-seeder/values.yaml | 74 +++++++++++ 9 files changed, 437 insertions(+) create mode 100644 charts/harvester-seeder/.helmignore create mode 100644 charts/harvester-seeder/Chart.yaml create mode 100644 charts/harvester-seeder/templates/_helpers.tpl create mode 100644 charts/harvester-seeder/templates/deployment.yaml create mode 100644 charts/harvester-seeder/templates/rbac.yaml create mode 100644 charts/harvester-seeder/templates/role-binding.yaml create mode 100644 charts/harvester-seeder/templates/service.yaml create mode 100644 charts/harvester-seeder/templates/serviceaccount.yaml create mode 100644 charts/harvester-seeder/values.yaml diff --git a/charts/harvester-seeder/.helmignore b/charts/harvester-seeder/.helmignore new file mode 100644 index 000000000..0e8a0eb3 --- /dev/null +++ b/charts/harvester-seeder/.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/harvester-seeder/Chart.yaml b/charts/harvester-seeder/Chart.yaml new file mode 100644 index 000000000..b916f9b2 --- /dev/null +++ b/charts/harvester-seeder/Chart.yaml @@ -0,0 +1,27 @@ +apiVersion: v2 +name: harvester-seeder +description: A Helm chart for Harvester Seeder + +# 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: 0.0.0-dev + +# 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: v0.1.0 + +maintainers: +- name: harvester diff --git a/charts/harvester-seeder/templates/_helpers.tpl b/charts/harvester-seeder/templates/_helpers.tpl new file mode 100644 index 000000000..5cc87734 --- /dev/null +++ b/charts/harvester-seeder/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "seeder.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 "seeder.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 "seeder.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "seeder.labels" -}} +helm.sh/chart: {{ include "seeder.chart" . }} +{{ include "seeder.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "seeder.selectorLabels" -}} +app.kubernetes.io/name: {{ include "seeder.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "seeder.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "seeder.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/harvester-seeder/templates/deployment.yaml b/charts/harvester-seeder/templates/deployment.yaml new file mode 100644 index 000000000..c8b84077 --- /dev/null +++ b/charts/harvester-seeder/templates/deployment.yaml @@ -0,0 +1,78 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "seeder.fullname" . }} + labels: + {{- include "seeder.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + strategy: +{{ toYaml .Values.strategy | indent 4 }} + selector: + matchLabels: + {{- include "seeder.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "seeder.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "seeder.serviceAccountName" . }} + affinity: + {{- toYaml .Values.apiAffinity | nindent 8 }} + 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 }} + env: + {{ if .Values.embeddedMode -}} + - name: SEEDER_EMBEDDED_MODE + value: "true" + {{ end -}} + - name: LEADER_ELECTION_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + ports: + - name: http + containerPort: 8080 + protocol: TCP + - name: probe + containerPort: 8081 + protocol: TCP + - name: leader + containerPort: 9443 + protocol: TCP + livenessProbe: + httpGet: + path: /metrics + port: http + readinessProbe: + httpGet: + path: /metrics + 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 }} \ No newline at end of file diff --git a/charts/harvester-seeder/templates/rbac.yaml b/charts/harvester-seeder/templates/rbac.yaml new file mode 100644 index 000000000..85d91dc7 --- /dev/null +++ b/charts/harvester-seeder/templates/rbac.yaml @@ -0,0 +1,121 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "seeder.fullname" . }}-manager-role +rules: +- apiGroups: + - apiextensions.k8s.io + resources: + - customresourcedefinitions + verbs: + - get + - list + - update + - watch + - create + - patch +- apiGroups: + - "" + resources: + - secrets + verbs: + - get + - list + - watch +- apiGroups: + - bmc.tinkerbell.org + resources: + - machines + - jobs + - tasks + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - bmc.tinkerbell.org + resources: + - machines/status + - jobs/status + - tasks/status + verbs: + - get + - create + - patch + - update +- apiGroups: + - metal.harvesterhci.io + resources: + - "*" + verbs: + - "*" +- apiGroups: + - tinkerbell.org + resources: + - hardware + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + resources: + - nodes + verbs: + - get + - list + - watch + - update + - patch +- apiGroups: + - "" + resources: + - events + verbs: + - create +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "seeder.fullname" . }}-leader-election-role +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch diff --git a/charts/harvester-seeder/templates/role-binding.yaml b/charts/harvester-seeder/templates/role-binding.yaml new file mode 100644 index 000000000..78ff3659 --- /dev/null +++ b/charts/harvester-seeder/templates/role-binding.yaml @@ -0,0 +1,25 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "seeder.fullname" . }}-manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "seeder.fullname" . }}-manager-role +subjects: +- kind: ServiceAccount + name: {{ include "seeder.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ include "seeder.fullname" . }}-leader-election-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ include "seeder.fullname" . }}-leader-election-role +subjects: +- kind: ServiceAccount + name: {{ include "seeder.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} diff --git a/charts/harvester-seeder/templates/service.yaml b/charts/harvester-seeder/templates/service.yaml new file mode 100644 index 000000000..7f4fc205 --- /dev/null +++ b/charts/harvester-seeder/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "seeder.fullname" . }} + labels: + {{- include "seeder.labels" . | nindent 4 }} +spec: + type: ClusterIP + ports: + - port: 9443 + targetPort: http + protocol: TCP + name: http + selector: + {{- include "seeder.selectorLabels" . | nindent 4 }} diff --git a/charts/harvester-seeder/templates/serviceaccount.yaml b/charts/harvester-seeder/templates/serviceaccount.yaml new file mode 100644 index 000000000..f929df05 --- /dev/null +++ b/charts/harvester-seeder/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "seeder.serviceAccountName" . }} + labels: + {{- include "seeder.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/harvester-seeder/values.yaml b/charts/harvester-seeder/values.yaml new file mode 100644 index 000000000..a10ff869 --- /dev/null +++ b/charts/harvester-seeder/values.yaml @@ -0,0 +1,74 @@ +# Default values for seeder. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 3 + +image: + repository: rancher/harvester-seeder + tag: main-head + pullPolicy: Always + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +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 + +resources: + requests: + cpu: "0.25" + memory: "250Mi" + limits: + cpu: "0.50" + memory: "500Mi" + +strategy: + rollingUpdate: + maxSurge: 2 + maxUnavailable: 2 + type: RollingUpdate + +# set to true for use in harvester-addon +embeddedMode: true + +apiAffinity: + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app.kubernetes.io/name + operator: In + values: + - seeder + topologyKey: kubernetes.io/hostname + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/os + operator: In + values: + - linux