From 8a84b471333ba6a81c42c577216a845a0ecc23af Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 22 Jan 2021 13:26:31 +0100 Subject: [PATCH 01/26] Initial commit of postgreslet-support chart --- charts/postgreslet-support/Chart.yaml | 24 ++++ charts/postgreslet-support/crds/postgres.yaml | 128 +++++++++++++++++ .../crds/postgresprofiles.yaml | 136 ++++++++++++++++++ 3 files changed, 288 insertions(+) create mode 100644 charts/postgreslet-support/Chart.yaml create mode 100644 charts/postgreslet-support/crds/postgres.yaml create mode 100644 charts/postgreslet-support/crds/postgresprofiles.yaml diff --git a/charts/postgreslet-support/Chart.yaml b/charts/postgreslet-support/Chart.yaml new file mode 100644 index 00000000..e3559321 --- /dev/null +++ b/charts/postgreslet-support/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: postgreslet-support +description: A Helm chart for installing support for postgres resources, which can be used by the Postgreslet + +# 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.1.0 + +# 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: "v1" diff --git a/charts/postgreslet-support/crds/postgres.yaml b/charts/postgreslet-support/crds/postgres.yaml new file mode 100644 index 00000000..85943a47 --- /dev/null +++ b/charts/postgreslet-support/crds/postgres.yaml @@ -0,0 +1,128 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.2.5 + creationTimestamp: null + name: postgres.database.fits.cloud +spec: + additionalPrinterColumns: + - JSONPath: .spec.version + name: Version + type: string + - JSONPath: .status.description + name: Status + type: string + group: database.fits.cloud + names: + kind: Postgres + listKind: PostgresList + plural: postgres + singular: postgres + scope: Namespaced + subresources: + status: {} + validation: + openAPIV3Schema: + description: Postgres is the Schema for the postgres API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: PostgresSpec defines the desired state of Postgres + properties: + accessList: + description: AccessList defines access restrictions + properties: + sourceRanges: + description: SourceRanges defines a list of prefixes in CIDR Notation e.g. 1.2.3.0/24 FIXME implement validation if source is a parsable CIDR + items: + type: string + type: array + type: object + backup: + description: Backup parametes of the database backup + properties: + retention: + description: Retention defines how many days a backup will persist + format: int32 + type: integer + schedule: + description: Schedule defines how often a backup should be made, in cron format + type: string + type: object + description: + description: Description + type: string + maintenance: + description: Maintenance defines automatic maintenance of the database + properties: + timeWindow: + description: TimeWindow defines when the maintenance should happen + properties: + end: + format: date-time + type: string + start: + format: date-time + type: string + type: object + weekday: + description: Weekday defines when the operator is allowed to do maintenance + type: integer + type: object + numberOfInstances: + description: NumberOfInstances number of replicas + format: int32 + type: integer + partitionID: + description: PartitionID the partition where the database is created + type: string + projectID: + description: ProjectID metal project ID + type: string + size: + description: Size of the database + properties: + cpu: + description: CPU is in the format as pod.spec.resource.request.cpu + type: string + sharedBuffer: + description: SharedBuffer of the database + type: string + storageSize: + description: StorageSize the amount of Storage this database will get + type: string + type: object + tenant: + description: Tenant metal tenant + type: string + version: + description: Version is the version of Postgre-as-a-Service + type: string + type: object + status: + description: PostgresStatus defines the observed state of Postgres + properties: + description: + description: 'INSERT ADDITIONAL STATUS FIELD - define observed state of cluster Important: Run "make" to regenerate code after modifying this file' + type: string + type: object + type: object + version: v1 + versions: + - name: v1 + served: true + storage: true +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/charts/postgreslet-support/crds/postgresprofiles.yaml b/charts/postgreslet-support/crds/postgresprofiles.yaml new file mode 100644 index 00000000..f2f65d34 --- /dev/null +++ b/charts/postgreslet-support/crds/postgresprofiles.yaml @@ -0,0 +1,136 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.2.5 + creationTimestamp: null + name: postgresprofiles.database.fits.cloud +spec: + group: database.fits.cloud + names: + kind: PostgresProfile + listKind: PostgresProfileList + plural: postgresprofiles + singular: postgresprofile + scope: Namespaced + validation: + openAPIV3Schema: + description: PostgresProfile is the Schema for the postgresprofiles API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: PostgresProfileSpec defines the desired state of PostgresProfile + properties: + defaultBackup: + description: Backup configure parametes of the database backup + properties: + retention: + description: Retention defines how many days a backup will persist + format: int32 + type: integer + schedule: + description: Schedule defines how often a backup should be made, in cron format + type: string + type: object + defaultMaintenance: + description: Maintenance configures database maintenance + properties: + timeWindow: + description: TimeWindow defines when the maintenance should happen + properties: + end: + format: date-time + type: string + start: + format: date-time + type: string + type: object + weekday: + description: Weekday defines when the operator is allowed to do maintenance + type: integer + type: object + defaultNumberOfInstances: + type: integer + defaultOperator: + description: Operator defines which provider of the operator should be used and its version + properties: + provider: + type: string + version: + items: + type: string + type: array + type: object + defaultSize: + description: Size defines the size aspects of the database + properties: + cpu: + description: CPU is in the format as pod.spec.resource.request.cpu + type: string + sharedBuffer: + description: SharedBuffer of the database + type: string + storageSize: + description: StorageSize the amount of Storage this database will get + type: string + type: object + defaultVersion: + type: string + numberOfInstances: + items: + type: integer + type: array + operators: + items: + description: Operator defines which provider of the operator should be used and its version + properties: + provider: + type: string + version: + items: + type: string + type: array + type: object + type: array + sizes: + items: + description: Size defines the size aspects of the database + properties: + cpu: + description: CPU is in the format as pod.spec.resource.request.cpu + type: string + sharedBuffer: + description: SharedBuffer of the database + type: string + storageSize: + description: StorageSize the amount of Storage this database will get + type: string + type: object + type: array + versions: + items: + type: string + type: array + type: object + status: + description: PostgresProfileStatus defines the observed state of PostgresProfile + type: object + type: object + version: v1 + versions: + - name: v1 + served: true + storage: true +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] From 0874a5f2a89d037b5b7ee26e8269c49c8ee703e7 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 22 Jan 2021 13:26:50 +0100 Subject: [PATCH 02/26] Initial commit of postgreslet-support chart --- charts/postgreslet-support/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/postgreslet-support/Chart.yaml b/charts/postgreslet-support/Chart.yaml index e3559321..b6499f72 100644 --- a/charts/postgreslet-support/Chart.yaml +++ b/charts/postgreslet-support/Chart.yaml @@ -21,4 +21,4 @@ version: 0.1.0 # 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: "v1" +appVersion: "v0" From 02964c86ed1b2add61abc098a6ea0b5e5fc19a26 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 22 Jan 2021 13:28:31 +0100 Subject: [PATCH 03/26] Initial commit of postgreslet chart --- charts/postgreslet/Chart.yaml | 30 +++++++ charts/postgreslet/templates/NOTES.txt | 22 +++++ charts/postgreslet/templates/_helpers.tpl | 62 ++++++++++++++ charts/postgreslet/templates/clusterrole.yaml | 74 +++++++++++++++++ .../templates/clusterrolebinding.yaml | 38 +++++++++ charts/postgreslet/templates/deployment.yaml | 58 +++++++++++++ charts/postgreslet/templates/role.yaml | 32 ++++++++ charts/postgreslet/templates/rolebinding.yaml | 13 +++ charts/postgreslet/templates/secret.yaml | 8 ++ charts/postgreslet/templates/service.yaml | 14 ++++ charts/postgreslet/values.yaml | 81 +++++++++++++++++++ 11 files changed, 432 insertions(+) create mode 100644 charts/postgreslet/Chart.yaml create mode 100644 charts/postgreslet/templates/NOTES.txt create mode 100644 charts/postgreslet/templates/_helpers.tpl create mode 100644 charts/postgreslet/templates/clusterrole.yaml create mode 100644 charts/postgreslet/templates/clusterrolebinding.yaml create mode 100644 charts/postgreslet/templates/deployment.yaml create mode 100644 charts/postgreslet/templates/role.yaml create mode 100644 charts/postgreslet/templates/rolebinding.yaml create mode 100644 charts/postgreslet/templates/secret.yaml create mode 100644 charts/postgreslet/templates/service.yaml create mode 100644 charts/postgreslet/values.yaml diff --git a/charts/postgreslet/Chart.yaml b/charts/postgreslet/Chart.yaml new file mode 100644 index 00000000..7c2762d0 --- /dev/null +++ b/charts/postgreslet/Chart.yaml @@ -0,0 +1,30 @@ +apiVersion: v2 +name: postgreslet +description: A Helm chart for deploying the Postgres Controller aka Postgreslet + +# 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.1.0 + +# 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: "0.0.1" + +dependencies: + - name: postgreslet-support + version: 0.1.0 + # TODO define repo + repository: file://../postgreslet-support diff --git a/charts/postgreslet/templates/NOTES.txt b/charts/postgreslet/templates/NOTES.txt new file mode 100644 index 00000000..a8783a11 --- /dev/null +++ b/charts/postgreslet/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "postgreslet.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "postgreslet.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "postgreslet.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "postgreslet.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/postgreslet/templates/_helpers.tpl b/charts/postgreslet/templates/_helpers.tpl new file mode 100644 index 00000000..4a38cec5 --- /dev/null +++ b/charts/postgreslet/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "postgreslet.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 "postgreslet.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 "postgreslet.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "postgreslet.labels" -}} +helm.sh/chart: {{ include "postgreslet.chart" . }} +{{ include "postgreslet.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "postgreslet.selectorLabels" -}} +app.kubernetes.io/name: {{ include "postgreslet.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "postgreslet.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "postgreslet.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/postgreslet/templates/clusterrole.yaml b/charts/postgreslet/templates/clusterrole.yaml new file mode 100644 index 00000000..03d7cf8f --- /dev/null +++ b/charts/postgreslet/templates/clusterrole.yaml @@ -0,0 +1,74 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + creationTimestamp: null + name: postgres-controller-manager-role +rules: +- apiGroups: + - acid.zalan.do + resources: + - postgresqls + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - acid.zalan.do + resources: + - postgresqls/status + verbs: + - get + - list + - watch +- apiGroups: + - database.fits.cloud + resources: + - postgres + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - database.fits.cloud + resources: + - postgres/status + verbs: + - get + - patch + - update +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: postgres-controller-proxy-role +rules: +- apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create +- apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create +--- +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRole +metadata: + name: postgres-controller-metrics-reader +rules: +- nonResourceURLs: + - /metrics + verbs: + - get diff --git a/charts/postgreslet/templates/clusterrolebinding.yaml b/charts/postgreslet/templates/clusterrolebinding.yaml new file mode 100644 index 00000000..7738caa0 --- /dev/null +++ b/charts/postgreslet/templates/clusterrolebinding.yaml @@ -0,0 +1,38 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: postgres-controller-cluster-admin-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +subjects: +- kind: ServiceAccount + name: default + namespace: postgres-controller-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: postgres-controller-manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: postgres-controller-manager-role +subjects: +- kind: ServiceAccount + name: default + namespace: postgres-controller-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: postgres-controller-proxy-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: postgres-controller-proxy-role +subjects: +- kind: ServiceAccount + name: default + namespace: postgres-controller-system diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml new file mode 100644 index 00000000..b74acd56 --- /dev/null +++ b/charts/postgreslet/templates/deployment.yaml @@ -0,0 +1,58 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + control-plane: controller-manager + name: postgres-controller-controller-manager + namespace: postgres-controller-system +spec: + replicas: 1 + selector: + matchLabels: + control-plane: controller-manager + template: + metadata: + labels: + control-plane: controller-manager + annotations: + controlplane-kubeconfig-hash: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} + spec: + containers: + - args: + - --secure-listen-address=0.0.0.0:8443 + - --upstream=http://127.0.0.1:8080/ + - --logtostderr=true + - --v=10 + image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 + name: kube-rbac-proxy + ports: + - containerPort: 8443 + name: https + - args: + - --enable-leader-election=false + - --partition-id=sample-partition + - --tenant=sample-tenant + command: + - /manager + image: r.metal-stack.io/extensions/postgreslet:latest + imagePullPolicy: IfNotPresent + name: manager + resources: + limits: + cpu: 100m + memory: 30Mi + requests: + cpu: 100m + memory: 20Mi + volumeMounts: + - mountPath: /var/run/secrets/postgreslet + name: controlplane-kubeconfig + readOnly: true + terminationGracePeriodSeconds: 10 + volumes: + - name: controlplane-kubeconfig + secret: + items: + - key: controlplane-kubeconfig + path: kube/config + secretName: postgreslet diff --git a/charts/postgreslet/templates/role.yaml b/charts/postgreslet/templates/role.yaml new file mode 100644 index 00000000..8cf4605c --- /dev/null +++ b/charts/postgreslet/templates/role.yaml @@ -0,0 +1,32 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: postgres-controller-leader-election-role + namespace: postgres-controller-system +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - configmaps/status + verbs: + - get + - update + - patch +- apiGroups: + - "" + resources: + - events + verbs: + - create diff --git a/charts/postgreslet/templates/rolebinding.yaml b/charts/postgreslet/templates/rolebinding.yaml new file mode 100644 index 00000000..43a072f5 --- /dev/null +++ b/charts/postgreslet/templates/rolebinding.yaml @@ -0,0 +1,13 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: postgres-controller-leader-election-rolebinding + namespace: postgres-controller-system +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: postgres-controller-leader-election-role +subjects: +- kind: ServiceAccount + name: default + namespace: postgres-controller-system diff --git a/charts/postgreslet/templates/secret.yaml b/charts/postgreslet/templates/secret.yaml new file mode 100644 index 00000000..50a95ca4 --- /dev/null +++ b/charts/postgreslet/templates/secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +data: + controlplane-kubeconfig: {{ b64enc .Values.controlplaneKubeconfig }} +kind: Secret +metadata: + name: postgreslet + annotations: + controlplane-kubeconfig-hash: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} diff --git a/charts/postgreslet/templates/service.yaml b/charts/postgreslet/templates/service.yaml new file mode 100644 index 00000000..27e26aa3 --- /dev/null +++ b/charts/postgreslet/templates/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + control-plane: controller-manager + name: postgres-controller-controller-manager-metrics-service + namespace: postgres-controller-system +spec: + ports: + - name: https + port: 8443 + targetPort: https + selector: + control-plane: controller-manager diff --git a/charts/postgreslet/values.yaml b/charts/postgreslet/values.yaml new file mode 100644 index 00000000..b37defbd --- /dev/null +++ b/charts/postgreslet/values.yaml @@ -0,0 +1,81 @@ +# Default values for postgreslet. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +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 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +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: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +controlplaneKubeconfig: "" From 97bca370f6530403fbc09004b20b700d12bdcffa Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 22 Jan 2021 13:28:53 +0100 Subject: [PATCH 04/26] Update README --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index baff7358..f93869fc 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,38 @@ make kind-load-image make secret make deploy ``` + +# Local Helm Development + +Delete and recreate all existing kind clusters (optional) + +```sh +kind delete cluster --name ctrl +kind delete cluster +kind create cluster --name ctrl --kubeconfig ./kubeconfig --config ctrl-cluster-config +kind create cluster +``` + +Build the charts + +```sh +helm package charts/postgreslet-support/ +helm dependency build charts/postgreslet/ +helm package charts/postgreslet/ +``` + +Prepare the control cluster + +```sh +helm --kubeconfig kubeconfig upgrade --install postgreslet-support postgreslet-support-0.1.0.tgz +kubectl --kubeconfig kubeconfig get postgres -A +``` + +Install the Postgreslet to the service cluster + +```sh +make kind-load-image +kubectl create namespace postgres-controller-system +helm upgrade --install postgreslet postgreslet-0.1.0.tgz --namespace postgres-controller-system --set-file controlplaneKubeconfig=kubeconfig +kubectl get po -A --watch +``` \ No newline at end of file From 1e48a5a732562b23257b54b8592fc8567fe4b31d Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 22 Jan 2021 13:30:01 +0100 Subject: [PATCH 05/26] Added missing .helmignore files --- charts/postgreslet-support/.helmignore | 23 +++++++++++++++++++++++ charts/postgreslet/.helmignore | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 charts/postgreslet-support/.helmignore create mode 100644 charts/postgreslet/.helmignore diff --git a/charts/postgreslet-support/.helmignore b/charts/postgreslet-support/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/charts/postgreslet-support/.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/postgreslet/.helmignore b/charts/postgreslet/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/charts/postgreslet/.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/ From 50370f0b2db7833bfc77adfc0ad769d187abd43c Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 22 Jan 2021 13:35:30 +0100 Subject: [PATCH 06/26] Update .gitignore --- .gitignore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 23789ac3..39e6026c 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,9 @@ bin *~ # control-plane kubeconfig file -*kubeconfig \ No newline at end of file +*kubeconfig + +# helm files +charts/postgreslet/Chart.lock +charts/postgreslet/charts/* + From 4b0344ea72265e11ce7551df2fa9a24f4ede63fb Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 22 Jan 2021 13:41:55 +0100 Subject: [PATCH 07/26] Moved helm build to Makefile --- Makefile | 11 ++++++++++- README.md | 5 ++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index add3e4ee..612ab3b5 100644 --- a/Makefile +++ b/Makefile @@ -107,4 +107,13 @@ secret: mkdir $$SECRET_DIR ;\ cp kubeconfig $$SECRET_DIR/controlplane-kubeconfig ;\ kubectl create secret generic postgreslet -n $$NS --from-file $$SECRET_DIR/ --dry-run=client -o yaml | kubectl apply -f - ;\ - } \ No newline at end of file + } + +helm-clean: + rm -f charts/postgreslet/Chart.lock + rm -f charts/postgreslet/charts/* + +helm: + helm package charts/postgreslet-support/ + helm dependency build charts/postgreslet/ + helm package charts/postgreslet/ \ No newline at end of file diff --git a/README.md b/README.md index f93869fc..304bea8f 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,8 @@ kind create cluster Build the charts ```sh -helm package charts/postgreslet-support/ -helm dependency build charts/postgreslet/ -helm package charts/postgreslet/ +make helm-clean +make helm ``` Prepare the control cluster From e9fe140663a7302521c7907fafdf61628778ddcf Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 20:17:16 +0100 Subject: [PATCH 08/26] Update CRDs --- charts/postgreslet-support/crds/postgres.yaml | 3 +++ charts/postgreslet-support/crds/postgresprofiles.yaml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/charts/postgreslet-support/crds/postgres.yaml b/charts/postgreslet-support/crds/postgres.yaml index 85943a47..697b32a7 100644 --- a/charts/postgreslet-support/crds/postgres.yaml +++ b/charts/postgreslet-support/crds/postgres.yaml @@ -53,6 +53,9 @@ spec: description: Retention defines how many days a backup will persist format: int32 type: integer + s3BucketURL: + description: S3BucketURL defines the URL of the S3 bucket for backup + type: string schedule: description: Schedule defines how often a backup should be made, in cron format type: string diff --git a/charts/postgreslet-support/crds/postgresprofiles.yaml b/charts/postgreslet-support/crds/postgresprofiles.yaml index f2f65d34..01b6178c 100644 --- a/charts/postgreslet-support/crds/postgresprofiles.yaml +++ b/charts/postgreslet-support/crds/postgresprofiles.yaml @@ -35,6 +35,9 @@ spec: description: Retention defines how many days a backup will persist format: int32 type: integer + s3BucketURL: + description: S3BucketURL defines the URL of the S3 bucket for backup + type: string schedule: description: Schedule defines how often a backup should be made, in cron format type: string From be511127627f2239973df1fb76b11c5c17063456 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 20:17:31 +0100 Subject: [PATCH 09/26] Linter --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9dd830f..be71c68b 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Delete _postgres_ on control-cluster and all the local corresponding resources. make delete-postgres ``` -# Local Helm Development +## Local Helm Development Delete and recreate all existing kind clusters (optional) @@ -104,4 +104,4 @@ make kind-load-image kubectl create namespace postgres-controller-system helm upgrade --install postgreslet postgreslet-0.1.0.tgz --namespace postgres-controller-system --set-file controlplaneKubeconfig=kubeconfig kubectl get po -A --watch -``` \ No newline at end of file +``` From b8e6f0f576f29a867c42d21f22f90367fb47494a Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 20:25:54 +0100 Subject: [PATCH 10/26] Remove kube-rbac-proxy --- charts/postgreslet/templates/deployment.yaml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index b74acd56..ba70e546 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -18,16 +18,6 @@ spec: controlplane-kubeconfig-hash: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} spec: containers: - - args: - - --secure-listen-address=0.0.0.0:8443 - - --upstream=http://127.0.0.1:8080/ - - --logtostderr=true - - --v=10 - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 - name: kube-rbac-proxy - ports: - - containerPort: 8443 - name: https - args: - --enable-leader-election=false - --partition-id=sample-partition From 46e58117a0419aad6552f760d40c8c134d7ecec7 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 20:46:32 +0100 Subject: [PATCH 11/26] Removed unused roles --- charts/postgreslet/templates/clusterrole.yaml | 29 ------------------- .../templates/clusterrolebinding.yaml | 13 --------- 2 files changed, 42 deletions(-) diff --git a/charts/postgreslet/templates/clusterrole.yaml b/charts/postgreslet/templates/clusterrole.yaml index 03d7cf8f..600291c8 100644 --- a/charts/postgreslet/templates/clusterrole.yaml +++ b/charts/postgreslet/templates/clusterrole.yaml @@ -1,7 +1,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - creationTimestamp: null name: postgres-controller-manager-role rules: - apiGroups: @@ -44,31 +43,3 @@ rules: - get - patch - update ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: postgres-controller-proxy-role -rules: -- apiGroups: - - authentication.k8s.io - resources: - - tokenreviews - verbs: - - create -- apiGroups: - - authorization.k8s.io - resources: - - subjectaccessreviews - verbs: - - create ---- -apiVersion: rbac.authorization.k8s.io/v1beta1 -kind: ClusterRole -metadata: - name: postgres-controller-metrics-reader -rules: -- nonResourceURLs: - - /metrics - verbs: - - get diff --git a/charts/postgreslet/templates/clusterrolebinding.yaml b/charts/postgreslet/templates/clusterrolebinding.yaml index 7738caa0..bcaec326 100644 --- a/charts/postgreslet/templates/clusterrolebinding.yaml +++ b/charts/postgreslet/templates/clusterrolebinding.yaml @@ -23,16 +23,3 @@ subjects: - kind: ServiceAccount name: default namespace: postgres-controller-system ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: postgres-controller-proxy-rolebinding -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: postgres-controller-proxy-role -subjects: -- kind: ServiceAccount - name: default - namespace: postgres-controller-system From 3cd972ebe75c66b799af4ff23046b036395fb74b Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 20:47:04 +0100 Subject: [PATCH 12/26] Removed unused service --- charts/postgreslet/templates/service.yaml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 charts/postgreslet/templates/service.yaml diff --git a/charts/postgreslet/templates/service.yaml b/charts/postgreslet/templates/service.yaml deleted file mode 100644 index 27e26aa3..00000000 --- a/charts/postgreslet/templates/service.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - labels: - control-plane: controller-manager - name: postgres-controller-controller-manager-metrics-service - namespace: postgres-controller-system -spec: - ports: - - name: https - port: 8443 - targetPort: https - selector: - control-plane: controller-manager From e81da1eb82e6efa03e38214da849b2d14b2ebf28 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 21:31:41 +0100 Subject: [PATCH 13/26] Introduce some variables and own serviceaccount --- README.md | 2 +- charts/postgreslet/templates/NOTES.txt | 22 ----- .../templates/clusterrolebinding.yaml | 4 +- charts/postgreslet/templates/deployment.yaml | 80 ++++++++++++------- charts/postgreslet/templates/rolebinding.yaml | 2 +- charts/postgreslet/templates/secret.yaml | 2 +- .../postgreslet/templates/serviceaccount.yaml | 12 +++ charts/postgreslet/values.yaml | 46 +++-------- 8 files changed, 77 insertions(+), 93 deletions(-) delete mode 100644 charts/postgreslet/templates/NOTES.txt create mode 100644 charts/postgreslet/templates/serviceaccount.yaml diff --git a/README.md b/README.md index be71c68b..38d67454 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,6 @@ Install the Postgreslet to the service cluster ```sh make kind-load-image kubectl create namespace postgres-controller-system -helm upgrade --install postgreslet postgreslet-0.1.0.tgz --namespace postgres-controller-system --set-file controlplaneKubeconfig=kubeconfig +helm upgrade --install postgreslet postgreslet-0.1.0.tgz --namespace postgres-controller-system --set-file controlplaneKubeconfig=kubeconfig --set image.tag=latest kubectl get po -A --watch ``` diff --git a/charts/postgreslet/templates/NOTES.txt b/charts/postgreslet/templates/NOTES.txt deleted file mode 100644 index a8783a11..00000000 --- a/charts/postgreslet/templates/NOTES.txt +++ /dev/null @@ -1,22 +0,0 @@ -1. Get the application URL by running these commands: -{{- if .Values.ingress.enabled }} -{{- range $host := .Values.ingress.hosts }} - {{- range .paths }} - http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} - {{- end }} -{{- end }} -{{- else if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "postgreslet.fullname" . }}) - export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") - echo http://$NODE_IP:$NODE_PORT -{{- else if contains "LoadBalancer" .Values.service.type }} - NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "postgreslet.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "postgreslet.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") - echo http://$SERVICE_IP:{{ .Values.service.port }} -{{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "postgreslet.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") - export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") - echo "Visit http://127.0.0.1:8080 to use your application" - kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT -{{- end }} diff --git a/charts/postgreslet/templates/clusterrolebinding.yaml b/charts/postgreslet/templates/clusterrolebinding.yaml index bcaec326..bffccebb 100644 --- a/charts/postgreslet/templates/clusterrolebinding.yaml +++ b/charts/postgreslet/templates/clusterrolebinding.yaml @@ -8,7 +8,7 @@ roleRef: name: cluster-admin subjects: - kind: ServiceAccount - name: default + name: {{ include "postgreslet.serviceAccountName" . }} namespace: postgres-controller-system --- apiVersion: rbac.authorization.k8s.io/v1 @@ -21,5 +21,5 @@ roleRef: name: postgres-controller-manager-role subjects: - kind: ServiceAccount - name: default + name: {{ include "postgreslet.serviceAccountName" . }} namespace: postgres-controller-system diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index ba70e546..e08acab4 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -3,46 +3,66 @@ kind: Deployment metadata: labels: control-plane: controller-manager + {{- include "postgreslet.labels" . | nindent 4 }} name: postgres-controller-controller-manager namespace: postgres-controller-system spec: - replicas: 1 + replicas: {{ .Values.replicaCount }} selector: matchLabels: control-plane: controller-manager + {{- include "postgreslet.selectorLabels" . | nindent 6 }} template: metadata: - labels: - control-plane: controller-manager annotations: controlplane-kubeconfig-hash: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + control-plane: controller-manager + {{- include "postgreslet.selectorLabels" . | nindent 8 }} spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "postgreslet.serviceAccountName" . }} containers: - - args: - - --enable-leader-election=false - - --partition-id=sample-partition - - --tenant=sample-tenant - command: - - /manager - image: r.metal-stack.io/extensions/postgreslet:latest - imagePullPolicy: IfNotPresent - name: manager - resources: - limits: - cpu: 100m - memory: 30Mi - requests: - cpu: 100m - memory: 20Mi - volumeMounts: - - mountPath: /var/run/secrets/postgreslet - name: controlplane-kubeconfig - readOnly: true - terminationGracePeriodSeconds: 10 + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - /manager + args: + - --enable-leader-election=false + - --partition-id=sample-partition + - --tenant=sample-tenant + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - mountPath: /var/run/secrets/postgreslet + name: controlplane-kubeconfig + readOnly: true + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} volumes: - - name: controlplane-kubeconfig - secret: - items: - - key: controlplane-kubeconfig - path: kube/config - secretName: postgreslet + - name: controlplane-kubeconfig + secret: + items: + - key: controlplane-kubeconfig + path: kube/config + secretName: {{ include "postgreslet.fullname" . }} + {{- 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/postgreslet/templates/rolebinding.yaml b/charts/postgreslet/templates/rolebinding.yaml index 43a072f5..8cb2d505 100644 --- a/charts/postgreslet/templates/rolebinding.yaml +++ b/charts/postgreslet/templates/rolebinding.yaml @@ -9,5 +9,5 @@ roleRef: name: postgres-controller-leader-election-role subjects: - kind: ServiceAccount - name: default + name: {{ include "postgreslet.serviceAccountName" . }} namespace: postgres-controller-system diff --git a/charts/postgreslet/templates/secret.yaml b/charts/postgreslet/templates/secret.yaml index 50a95ca4..a766030a 100644 --- a/charts/postgreslet/templates/secret.yaml +++ b/charts/postgreslet/templates/secret.yaml @@ -3,6 +3,6 @@ data: controlplane-kubeconfig: {{ b64enc .Values.controlplaneKubeconfig }} kind: Secret metadata: - name: postgreslet + name: {{ include "postgreslet.fullname" . }} annotations: controlplane-kubeconfig-hash: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} diff --git a/charts/postgreslet/templates/serviceaccount.yaml b/charts/postgreslet/templates/serviceaccount.yaml new file mode 100644 index 00000000..1b05e670 --- /dev/null +++ b/charts/postgreslet/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "postgreslet.serviceAccountName" . }} + labels: + {{- include "postgreslet.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/postgreslet/values.yaml b/charts/postgreslet/values.yaml index b37defbd..18e38607 100644 --- a/charts/postgreslet/values.yaml +++ b/charts/postgreslet/values.yaml @@ -5,7 +5,7 @@ replicaCount: 1 image: - repository: nginx + repository: r.metal-stack.io/extensions/postgreslet pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: "" @@ -36,41 +36,13 @@ securityContext: {} # runAsNonRoot: true # runAsUser: 1000 -service: - type: ClusterIP - port: 80 - -ingress: - enabled: false - annotations: {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - -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: - enabled: false - minReplicas: 1 - maxReplicas: 100 - targetCPUUtilizationPercentage: 80 - # targetMemoryUtilizationPercentage: 80 +resources: + limits: + cpu: 100m + memory: 30Mi + requests: + cpu: 100m + memory: 20Mi nodeSelector: {} @@ -79,3 +51,5 @@ tolerations: [] affinity: {} controlplaneKubeconfig: "" + +terminationGracePeriodSeconds: 10 From fa9a6b492fe2796771a6b0456b5efd0a87c2555d Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 21:39:27 +0100 Subject: [PATCH 14/26] Add missing podSecurityContext --- charts/postgreslet/templates/deployment.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index e08acab4..a4d4b90b 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -28,6 +28,8 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "postgreslet.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: {{ .Chart.Name }} securityContext: From f5f174756b1a43e923d4960a1fcf1e639719c695 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 21:46:53 +0100 Subject: [PATCH 15/26] Make namespace dynamic --- README.md | 4 ++-- charts/postgreslet/templates/clusterrolebinding.yaml | 4 ++-- charts/postgreslet/templates/deployment.yaml | 1 - charts/postgreslet/templates/role.yaml | 1 - charts/postgreslet/templates/rolebinding.yaml | 3 +-- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 38d67454..5379a1d0 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Install the Postgreslet to the service cluster ```sh make kind-load-image -kubectl create namespace postgres-controller-system -helm upgrade --install postgreslet postgreslet-0.1.0.tgz --namespace postgres-controller-system --set-file controlplaneKubeconfig=kubeconfig --set image.tag=latest +kubectl create namespace postgreslet-system +helm upgrade --install postgreslet postgreslet-0.1.0.tgz --namespace postgreslet-system --set-file controlplaneKubeconfig=kubeconfig --set image.tag=latest kubectl get po -A --watch ``` diff --git a/charts/postgreslet/templates/clusterrolebinding.yaml b/charts/postgreslet/templates/clusterrolebinding.yaml index bffccebb..7580744d 100644 --- a/charts/postgreslet/templates/clusterrolebinding.yaml +++ b/charts/postgreslet/templates/clusterrolebinding.yaml @@ -9,7 +9,7 @@ roleRef: subjects: - kind: ServiceAccount name: {{ include "postgreslet.serviceAccountName" . }} - namespace: postgres-controller-system + namespace: {{ .Release.Namespace }} --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding @@ -22,4 +22,4 @@ roleRef: subjects: - kind: ServiceAccount name: {{ include "postgreslet.serviceAccountName" . }} - namespace: postgres-controller-system + namespace: {{ .Release.Namespace }} diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index a4d4b90b..ee48b43e 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -5,7 +5,6 @@ metadata: control-plane: controller-manager {{- include "postgreslet.labels" . | nindent 4 }} name: postgres-controller-controller-manager - namespace: postgres-controller-system spec: replicas: {{ .Values.replicaCount }} selector: diff --git a/charts/postgreslet/templates/role.yaml b/charts/postgreslet/templates/role.yaml index 8cf4605c..b3d67ff7 100644 --- a/charts/postgreslet/templates/role.yaml +++ b/charts/postgreslet/templates/role.yaml @@ -2,7 +2,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: postgres-controller-leader-election-role - namespace: postgres-controller-system rules: - apiGroups: - "" diff --git a/charts/postgreslet/templates/rolebinding.yaml b/charts/postgreslet/templates/rolebinding.yaml index 8cb2d505..d33ff4ff 100644 --- a/charts/postgreslet/templates/rolebinding.yaml +++ b/charts/postgreslet/templates/rolebinding.yaml @@ -2,7 +2,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: postgres-controller-leader-election-rolebinding - namespace: postgres-controller-system roleRef: apiGroup: rbac.authorization.k8s.io kind: Role @@ -10,4 +9,4 @@ roleRef: subjects: - kind: ServiceAccount name: {{ include "postgreslet.serviceAccountName" . }} - namespace: postgres-controller-system + namespace: {{ .Release.Namespace }} \ No newline at end of file From c8c44466f58af3d50c4234411bdc7e34d92900d7 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 21:49:00 +0100 Subject: [PATCH 16/26] Update pod name --- charts/postgreslet/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index ee48b43e..04cffae8 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -4,7 +4,7 @@ metadata: labels: control-plane: controller-manager {{- include "postgreslet.labels" . | nindent 4 }} - name: postgres-controller-controller-manager + name: {{ include "postgreslet.fullname" . }} spec: replicas: {{ .Values.replicaCount }} selector: From d36c2a5e42c31e280c12c89e79b7139734c75e8d Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 21:54:41 +0100 Subject: [PATCH 17/26] Indentation --- charts/postgreslet/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index 04cffae8..117b4019 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -20,7 +20,7 @@ spec: {{- end }} labels: control-plane: controller-manager - {{- include "postgreslet.selectorLabels" . | nindent 8 }} + {{- include "postgreslet.selectorLabels" . | nindent 8 }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: From be6ed9310c5cdccde355b57bd980c04e59ed0c1b Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Mon, 25 Jan 2021 22:04:24 +0100 Subject: [PATCH 18/26] Make args configurable --- charts/postgreslet/templates/deployment.yaml | 6 +++--- charts/postgreslet/values.yaml | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index 117b4019..e58e70b5 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -38,9 +38,9 @@ spec: command: - /manager args: - - --enable-leader-election=false - - --partition-id=sample-partition - - --tenant=sample-tenant + - --enable-leader-election={{ .Values.postgreslet.enableLeaderElection }} + - --partition-id={{ .Values.postgreslet.partitionId }} + - --tenant={{ .Values.postgreslet.tenant }} resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: diff --git a/charts/postgreslet/values.yaml b/charts/postgreslet/values.yaml index 18e38607..0851db84 100644 --- a/charts/postgreslet/values.yaml +++ b/charts/postgreslet/values.yaml @@ -53,3 +53,8 @@ affinity: {} controlplaneKubeconfig: "" terminationGracePeriodSeconds: 10 + +postgreslet: + enableLeaderElection: false + partitionId: sample-partition + tenant: sample-tenant \ No newline at end of file From 0c5fab8b1506d23a2e5ba618b866af7d24fc184b Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Feb 2021 11:02:35 +0100 Subject: [PATCH 19/26] Use configmap --- charts/postgreslet/templates/configmap.yaml | 17 +++++++++++++++++ charts/postgreslet/templates/deployment.yaml | 14 ++++++++++---- charts/postgreslet/templates/secret.yaml | 5 +++++ charts/postgreslet/values.yaml | 3 ++- 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 charts/postgreslet/templates/configmap.yaml diff --git a/charts/postgreslet/templates/configmap.yaml b/charts/postgreslet/templates/configmap.yaml new file mode 100644 index 00000000..11138fba --- /dev/null +++ b/charts/postgreslet/templates/configmap.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +data: + ENABLE_LEADER_ELECTION: {{ .Values.postgreslet.enableLeaderElection | quote }} + METRICS_ADDR_CTRL_MGR: "0" + METRICS_ADDR_SVC_MGR: {{ .Values.postgreslet.metricsAddr | quote }} + PARTITION_ID: {{ .Values.postgreslet.partitionId | quote }} + TENANT: {{ .Values.postgreslet.tenant | quote }} +kind: ConfigMap +metadata: + name: {{ include "postgreslet.fullname" . }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} +{{- with .Values.podAnnotations }} + {{- toYaml . | nindent 4 }} +{{- end }} + labels: + {{- include "postgreslet.labels" . | nindent 4 }} diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index e58e70b5..8f1faca9 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -14,7 +14,8 @@ spec: template: metadata: annotations: - controlplane-kubeconfig-hash: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} + checksum/controlplane-kubeconfig: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} {{- with .Values.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} @@ -38,9 +39,14 @@ spec: command: - /manager args: - - --enable-leader-election={{ .Values.postgreslet.enableLeaderElection }} - - --partition-id={{ .Values.postgreslet.partitionId }} - - --tenant={{ .Values.postgreslet.tenant }} + - --metrics-addr-svc-mgr=$(METRICS_ADDR_CTRL_MGR) + - --metrics-addr-ctrl-mgr=$(METRICS_ADDR_SVC_MGR) + - --enable-leader-election=$(ENABLE_LEADER_ELECTION) + - --partition-id=$(PARTITION_ID) + - --tenant=$(TENANT) + envFrom: + - configMapRef: + name: {{ include "postgreslet.fullname" . }} resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: diff --git a/charts/postgreslet/templates/secret.yaml b/charts/postgreslet/templates/secret.yaml index a766030a..c3dd6c26 100644 --- a/charts/postgreslet/templates/secret.yaml +++ b/charts/postgreslet/templates/secret.yaml @@ -6,3 +6,8 @@ metadata: name: {{ include "postgreslet.fullname" . }} annotations: controlplane-kubeconfig-hash: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} +{{- with .Values.podAnnotations }} + {{- toYaml . | nindent 4 }} +{{- end }} + labels: + {{- include "postgreslet.labels" . | nindent 4 }} diff --git a/charts/postgreslet/values.yaml b/charts/postgreslet/values.yaml index 0851db84..544b0170 100644 --- a/charts/postgreslet/values.yaml +++ b/charts/postgreslet/values.yaml @@ -57,4 +57,5 @@ terminationGracePeriodSeconds: 10 postgreslet: enableLeaderElection: false partitionId: sample-partition - tenant: sample-tenant \ No newline at end of file + tenant: sample-tenant + metricsAddr: ":8080" \ No newline at end of file From 6148b0c7c8ed10449ec0c8afe599c939254543b0 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Feb 2021 11:04:13 +0100 Subject: [PATCH 20/26] Update CRDs --- charts/postgreslet-support/crds/postgres.yaml | 223 +++++++++--------- .../crds/postgresprofiles.yaml | 139 ----------- 2 files changed, 114 insertions(+), 248 deletions(-) delete mode 100644 charts/postgreslet-support/crds/postgresprofiles.yaml diff --git a/charts/postgreslet-support/crds/postgres.yaml b/charts/postgreslet-support/crds/postgres.yaml index 697b32a7..e4722b1e 100644 --- a/charts/postgreslet-support/crds/postgres.yaml +++ b/charts/postgreslet-support/crds/postgres.yaml @@ -1,18 +1,10 @@ -apiVersion: apiextensions.k8s.io/v1beta1 +apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.2.5 - creationTimestamp: null name: postgres.database.fits.cloud spec: - additionalPrinterColumns: - - JSONPath: .spec.version - name: Version - type: string - - JSONPath: .status.description - name: Status - type: string group: database.fits.cloud names: kind: Postgres @@ -20,109 +12,122 @@ spec: plural: postgres singular: postgres scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - description: Postgres is the Schema for the postgres API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: PostgresSpec defines the desired state of Postgres - properties: - accessList: - description: AccessList defines access restrictions - properties: - sourceRanges: - description: SourceRanges defines a list of prefixes in CIDR Notation e.g. 1.2.3.0/24 FIXME implement validation if source is a parsable CIDR - items: - type: string - type: array - type: object - backup: - description: Backup parametes of the database backup - properties: - retention: - description: Retention defines how many days a backup will persist - format: int32 - type: integer - s3BucketURL: - description: S3BucketURL defines the URL of the S3 bucket for backup - type: string - schedule: - description: Schedule defines how often a backup should be made, in cron format - type: string - type: object - description: - description: Description - type: string - maintenance: - description: Maintenance defines automatic maintenance of the database - properties: - timeWindow: - description: TimeWindow defines when the maintenance should happen - properties: - end: - format: date-time - type: string - start: - format: date-time - type: string - type: object - weekday: - description: Weekday defines when the operator is allowed to do maintenance - type: integer - type: object - numberOfInstances: - description: NumberOfInstances number of replicas - format: int32 - type: integer - partitionID: - description: PartitionID the partition where the database is created - type: string - projectID: - description: ProjectID metal project ID - type: string - size: - description: Size of the database - properties: - cpu: - description: CPU is in the format as pod.spec.resource.request.cpu - type: string - sharedBuffer: - description: SharedBuffer of the database - type: string - storageSize: - description: StorageSize the amount of Storage this database will get - type: string - type: object - tenant: - description: Tenant metal tenant - type: string - version: - description: Version is the version of Postgre-as-a-Service - type: string - type: object - status: - description: PostgresStatus defines the observed state of Postgres - properties: - description: - description: 'INSERT ADDITIONAL STATUS FIELD - define observed state of cluster Important: Run "make" to regenerate code after modifying this file' - type: string - type: object - type: object - version: v1 versions: - - name: v1 + - additionalPrinterColumns: + - jsonPath: .spec.version + name: Version + type: string + - jsonPath: .status.description + name: Status + type: string + name: v1 + schema: + openAPIV3Schema: + description: Postgres is the Schema for the postgres API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: PostgresSpec defines the desired state of Postgres + properties: + accessList: + description: AccessList defines access restrictions + properties: + sourceRanges: + description: SourceRanges defines a list of prefixes in CIDR Notation e.g. 1.2.3.0/24 FIXME implement validation if source is a parsable CIDR + items: + type: string + type: array + type: object + backup: + description: 'todo: add default Backup parametes of the database backup' + properties: + retention: + description: Retention defines how many days a backup will persist + format: int32 + type: integer + s3BucketURL: + description: S3BucketURL defines the URL of the S3 bucket for backup + type: string + schedule: + description: Schedule defines how often a backup should be made, in cron format + type: string + type: object + description: + description: Description + type: string + maintenance: + description: 'todo: add default Maintenance defines automatic maintenance of the database' + properties: + timeWindow: + description: TimeWindow defines when the maintenance should happen + properties: + end: + format: date-time + type: string + start: + format: date-time + type: string + type: object + weekday: + description: Weekday defines when the operator is allowed to do maintenance + type: integer + type: object + numberOfInstances: + default: 1 + description: NumberOfInstances number of replicas + format: int32 + minimum: 1 + type: integer + partitionID: + description: PartitionID the partition where the database is created + type: string + projectID: + description: ProjectID metal project ID + type: string + size: + description: Size of the database + properties: + cpu: + description: CPU is in the format as pod.spec.resource.request.cpu + type: string + sharedBuffer: + description: SharedBuffer of the database + type: string + storageSize: + default: 1Gi + description: StorageSize the amount of Storage this database will get + pattern: ^[1-9][0-9]*Gi + type: string + type: object + tenant: + description: Tenant metal tenant + type: string + version: + default: "12" + description: Version is the version of Postgre-as-a-Service + enum: + - "12" + type: string + type: object + status: + description: PostgresStatus defines the observed state of Postgres + properties: + description: + description: 'INSERT ADDITIONAL STATUS FIELD - define observed state of cluster Important: Run "make" to regenerate code after modifying this file' + type: string + type: object + type: object served: true storage: true + subresources: + status: {} status: acceptedNames: kind: "" diff --git a/charts/postgreslet-support/crds/postgresprofiles.yaml b/charts/postgreslet-support/crds/postgresprofiles.yaml deleted file mode 100644 index 01b6178c..00000000 --- a/charts/postgreslet-support/crds/postgresprofiles.yaml +++ /dev/null @@ -1,139 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.2.5 - creationTimestamp: null - name: postgresprofiles.database.fits.cloud -spec: - group: database.fits.cloud - names: - kind: PostgresProfile - listKind: PostgresProfileList - plural: postgresprofiles - singular: postgresprofile - scope: Namespaced - validation: - openAPIV3Schema: - description: PostgresProfile is the Schema for the postgresprofiles API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: PostgresProfileSpec defines the desired state of PostgresProfile - properties: - defaultBackup: - description: Backup configure parametes of the database backup - properties: - retention: - description: Retention defines how many days a backup will persist - format: int32 - type: integer - s3BucketURL: - description: S3BucketURL defines the URL of the S3 bucket for backup - type: string - schedule: - description: Schedule defines how often a backup should be made, in cron format - type: string - type: object - defaultMaintenance: - description: Maintenance configures database maintenance - properties: - timeWindow: - description: TimeWindow defines when the maintenance should happen - properties: - end: - format: date-time - type: string - start: - format: date-time - type: string - type: object - weekday: - description: Weekday defines when the operator is allowed to do maintenance - type: integer - type: object - defaultNumberOfInstances: - type: integer - defaultOperator: - description: Operator defines which provider of the operator should be used and its version - properties: - provider: - type: string - version: - items: - type: string - type: array - type: object - defaultSize: - description: Size defines the size aspects of the database - properties: - cpu: - description: CPU is in the format as pod.spec.resource.request.cpu - type: string - sharedBuffer: - description: SharedBuffer of the database - type: string - storageSize: - description: StorageSize the amount of Storage this database will get - type: string - type: object - defaultVersion: - type: string - numberOfInstances: - items: - type: integer - type: array - operators: - items: - description: Operator defines which provider of the operator should be used and its version - properties: - provider: - type: string - version: - items: - type: string - type: array - type: object - type: array - sizes: - items: - description: Size defines the size aspects of the database - properties: - cpu: - description: CPU is in the format as pod.spec.resource.request.cpu - type: string - sharedBuffer: - description: SharedBuffer of the database - type: string - storageSize: - description: StorageSize the amount of Storage this database will get - type: string - type: object - type: array - versions: - items: - type: string - type: array - type: object - status: - description: PostgresProfileStatus defines the observed state of PostgresProfile - type: object - type: object - version: v1 - versions: - - name: v1 - served: true - storage: true -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] From 4712a05656b9726b9ea275d3061bc02b6452b9ae Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Feb 2021 11:13:09 +0100 Subject: [PATCH 21/26] Remove infinite rendering loop --- charts/postgreslet/templates/configmap.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/charts/postgreslet/templates/configmap.yaml b/charts/postgreslet/templates/configmap.yaml index 11138fba..26ca552a 100644 --- a/charts/postgreslet/templates/configmap.yaml +++ b/charts/postgreslet/templates/configmap.yaml @@ -8,8 +8,10 @@ data: kind: ConfigMap metadata: name: {{ include "postgreslet.fullname" . }} +{{- with .Values.podAnnotations }} annotations: - checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + {{- toYaml . | nindent 4 }} +{{- end }} {{- with .Values.podAnnotations }} {{- toYaml . | nindent 4 }} {{- end }} From 0a51f9a073596dd64a73d67fcf51b22a4d6e4e23 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Feb 2021 11:13:30 +0100 Subject: [PATCH 22/26] Remove checksum from secret as well --- charts/postgreslet/templates/secret.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/charts/postgreslet/templates/secret.yaml b/charts/postgreslet/templates/secret.yaml index c3dd6c26..26680a4f 100644 --- a/charts/postgreslet/templates/secret.yaml +++ b/charts/postgreslet/templates/secret.yaml @@ -4,9 +4,8 @@ data: kind: Secret metadata: name: {{ include "postgreslet.fullname" . }} - annotations: - controlplane-kubeconfig-hash: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} {{- with .Values.podAnnotations }} + annotations: {{- toYaml . | nindent 4 }} {{- end }} labels: From dd50c982999ba29e0fbb9a12c37d9d2f7700b237 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Feb 2021 11:24:03 +0100 Subject: [PATCH 23/26] Generalize secret hash / adopt to config hash --- charts/postgreslet/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index 8f1faca9..d188d4c6 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -14,7 +14,7 @@ spec: template: metadata: annotations: - checksum/controlplane-kubeconfig: {{ sha256sum .Values.controlplaneKubeconfig | trunc 63 | trimSuffix "-" }} + checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} {{- with .Values.podAnnotations }} {{- toYaml . | nindent 8 }} From ec92d89833d5e40549cae18d94f1e82484e00a90 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Feb 2021 11:24:23 +0100 Subject: [PATCH 24/26] Fix variable swap --- charts/postgreslet/templates/deployment.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/postgreslet/templates/deployment.yaml b/charts/postgreslet/templates/deployment.yaml index d188d4c6..4b61d86c 100644 --- a/charts/postgreslet/templates/deployment.yaml +++ b/charts/postgreslet/templates/deployment.yaml @@ -39,8 +39,8 @@ spec: command: - /manager args: - - --metrics-addr-svc-mgr=$(METRICS_ADDR_CTRL_MGR) - - --metrics-addr-ctrl-mgr=$(METRICS_ADDR_SVC_MGR) + - --metrics-addr-svc-mgr=$(METRICS_ADDR_SVC_MGR) + - --metrics-addr-ctrl-mgr=$(METRICS_ADDR_CTRL_MGR) - --enable-leader-election=$(ENABLE_LEADER_ELECTION) - --partition-id=$(PARTITION_ID) - --tenant=$(TENANT) From 8cf9d647d65f49c9e408ea5bac15e13f788c47ac Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Feb 2021 13:26:05 +0100 Subject: [PATCH 25/26] Make (cluster)role names configurable --- charts/postgreslet/templates/_helpers.tpl | 11 +++++++++++ charts/postgreslet/templates/clusterrole.yaml | 2 +- charts/postgreslet/templates/clusterrolebinding.yaml | 6 +++--- charts/postgreslet/templates/role.yaml | 2 +- charts/postgreslet/templates/rolebinding.yaml | 4 ++-- charts/postgreslet/values.yaml | 3 +++ 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/charts/postgreslet/templates/_helpers.tpl b/charts/postgreslet/templates/_helpers.tpl index 4a38cec5..362e8b03 100644 --- a/charts/postgreslet/templates/_helpers.tpl +++ b/charts/postgreslet/templates/_helpers.tpl @@ -50,6 +50,17 @@ app.kubernetes.io/name: {{ include "postgreslet.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} +{{/* +Create the prefix to use in (cluster)role names and bindings +*/}} +{{- define "postgreslet.roleNamePrefix" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "postgreslet.fullname" .) .Values.serviceAccount.roleNamePrefix }} +{{- else }} +{{- default "postgreslet" .Values.serviceAccount.roleNamePrefix }} +{{- end }} +{{- end }} + {{/* Create the name of the service account to use */}} diff --git a/charts/postgreslet/templates/clusterrole.yaml b/charts/postgreslet/templates/clusterrole.yaml index 600291c8..1099889e 100644 --- a/charts/postgreslet/templates/clusterrole.yaml +++ b/charts/postgreslet/templates/clusterrole.yaml @@ -1,7 +1,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: postgres-controller-manager-role + name: {{ include "postgreslet.roleNamePrefix" . }}-manager-role rules: - apiGroups: - acid.zalan.do diff --git a/charts/postgreslet/templates/clusterrolebinding.yaml b/charts/postgreslet/templates/clusterrolebinding.yaml index 7580744d..f81957ea 100644 --- a/charts/postgreslet/templates/clusterrolebinding.yaml +++ b/charts/postgreslet/templates/clusterrolebinding.yaml @@ -1,7 +1,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: postgres-controller-cluster-admin-rolebinding + name: {{ include "postgreslet.roleNamePrefix" . }}-cluster-admin-rolebinding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -14,11 +14,11 @@ subjects: apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: postgres-controller-manager-rolebinding + name: {{ include "postgreslet.roleNamePrefix" . }}-manager-rolebinding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: postgres-controller-manager-role + name: {{ include "postgreslet.roleNamePrefix" . }}-manager-role subjects: - kind: ServiceAccount name: {{ include "postgreslet.serviceAccountName" . }} diff --git a/charts/postgreslet/templates/role.yaml b/charts/postgreslet/templates/role.yaml index b3d67ff7..21a36497 100644 --- a/charts/postgreslet/templates/role.yaml +++ b/charts/postgreslet/templates/role.yaml @@ -1,7 +1,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: - name: postgres-controller-leader-election-role + name: {{ include "postgreslet.roleNamePrefix" . }}-leader-election-role rules: - apiGroups: - "" diff --git a/charts/postgreslet/templates/rolebinding.yaml b/charts/postgreslet/templates/rolebinding.yaml index d33ff4ff..8468b09e 100644 --- a/charts/postgreslet/templates/rolebinding.yaml +++ b/charts/postgreslet/templates/rolebinding.yaml @@ -1,11 +1,11 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: - name: postgres-controller-leader-election-rolebinding + name: {{ include "postgreslet.roleNamePrefix" . }}-leader-election-rolebinding roleRef: apiGroup: rbac.authorization.k8s.io kind: Role - name: postgres-controller-leader-election-role + name: {{ include "postgreslet.roleNamePrefix" . }}-leader-election-role subjects: - kind: ServiceAccount name: {{ include "postgreslet.serviceAccountName" . }} diff --git a/charts/postgreslet/values.yaml b/charts/postgreslet/values.yaml index 544b0170..a2f0d5eb 100644 --- a/charts/postgreslet/values.yaml +++ b/charts/postgreslet/values.yaml @@ -22,6 +22,9 @@ serviceAccount: # The name of the service account to use. # If not set and create is true, a name is generated using the fullname template name: "" + # A prefix to use in all the (Cluster)Roles that are being created for this service account. + # If not set and create is true, a name is generated using the fullname template + roleNamePrefix: "" podAnnotations: {} From 12643e5fc64a9beecd201d022a4cef5248b949cd Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 2 Feb 2021 13:30:19 +0100 Subject: [PATCH 26/26] Add comments/docs to values.yaml --- charts/postgreslet/values.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/charts/postgreslet/values.yaml b/charts/postgreslet/values.yaml index a2f0d5eb..4b26b3de 100644 --- a/charts/postgreslet/values.yaml +++ b/charts/postgreslet/values.yaml @@ -58,7 +58,11 @@ controlplaneKubeconfig: "" terminationGracePeriodSeconds: 10 postgreslet: + # enableLeaderElection specifies weather leader election should be performed enableLeaderElection: false + # partitionId specifies which partition this postgreslet is responsable for, postgres resources from other partitions will be ignored partitionId: sample-partition + # tenant specifies which tenant this postgreslet is responsable for, postgres resources from other tenants will be ignored tenant: sample-tenant + # metricsAddr defines the listen address of the metrics endpoint metricsAddr: ":8080" \ No newline at end of file