Skip to content

Commit 0529408

Browse files
brunsgaardFxKu
authored andcommitted
Introduce crds directory for compatibility with Helm v3 (zalando#738)
* Introduce crds directory for compatibility with Helm v3 This commit introduce a crd directory for the helm chart which has all custom resource definitions. The files in the crd directory is plain YAML. The crds got the label `app.kubernetes.io/name: postgres-operator` and removes all the templating. Helm v3 ignores the objects from the `templates` directory which have a `crd-install` hook. This commit addes templates/crds.yaml which generates YAMLs for CRDs. The hooks from these CRDs are detected by Helm v2 as well as v3. Helm v2 executes the hook and Helm v3 ignores the hook (YAML files are not applied) The approach is inspired by the prometheus-operator chart helm/charts@89b233e
1 parent 5f87384 commit 0529408

File tree

5 files changed

+111
-114
lines changed

5 files changed

+111
-114
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: operatorconfigurations.acid.zalan.do
5+
labels:
6+
app.kubernetes.io/name: postgres-operator
7+
annotations:
8+
"helm.sh/hook": crd-install
9+
spec:
10+
group: acid.zalan.do
11+
names:
12+
kind: OperatorConfiguration
13+
listKind: OperatorConfigurationList
14+
plural: operatorconfigurations
15+
singular: operatorconfiguration
16+
shortNames:
17+
- opconfig
18+
additionalPrinterColumns:
19+
- name: Image
20+
type: string
21+
description: Spilo image to be used for Pods
22+
JSONPath: .configuration.docker_image
23+
- name: Cluster-Label
24+
type: string
25+
description: Label for K8s resources created by operator
26+
JSONPath: .configuration.kubernetes.cluster_name_label
27+
- name: Service-Account
28+
type: string
29+
description: Name of service account to be used
30+
JSONPath: .configuration.kubernetes.pod_service_account_name
31+
- name: Min-Instances
32+
type: integer
33+
description: Minimum number of instances per Postgres cluster
34+
JSONPath: .configuration.min_instances
35+
- name: Age
36+
type: date
37+
JSONPath: .metadata.creationTimestamp
38+
scope: Namespaced
39+
subresources:
40+
status: {}
41+
version: v1
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: postgresqls.acid.zalan.do
5+
labels:
6+
app.kubernetes.io/name: postgres-operator
7+
annotations:
8+
"helm.sh/hook": crd-install
9+
spec:
10+
group: acid.zalan.do
11+
names:
12+
kind: postgresql
13+
listKind: postgresqlList
14+
plural: postgresqls
15+
singular: postgresql
16+
shortNames:
17+
- pg
18+
additionalPrinterColumns:
19+
- name: Team
20+
type: string
21+
description: Team responsible for Postgres CLuster
22+
JSONPath: .spec.teamId
23+
- name: Version
24+
type: string
25+
description: PostgreSQL version
26+
JSONPath: .spec.postgresql.version
27+
- name: Pods
28+
type: integer
29+
description: Number of Pods per Postgres cluster
30+
JSONPath: .spec.numberOfInstances
31+
- name: Volume
32+
type: string
33+
description: Size of the bound volume
34+
JSONPath: .spec.volume.size
35+
- name: CPU-Request
36+
type: string
37+
description: Requested CPU for Postgres containers
38+
JSONPath: .spec.resources.requests.cpu
39+
- name: Memory-Request
40+
type: string
41+
description: Requested memory for Postgres containers
42+
JSONPath: .spec.resources.requests.memory
43+
- name: Age
44+
type: date
45+
JSONPath: .metadata.creationTimestamp
46+
- name: Status
47+
type: string
48+
description: Current sync status of postgresql resource
49+
JSONPath: .status.PostgresClusterStatus
50+
scope: Namespaced
51+
subresources:
52+
status: {}
53+
version: v1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{ if .Values.crd.create }}
2+
{{- range $path, $bytes := .Files.Glob "crds/*.yaml" }}
3+
{{ $.Files.Get $path }}
4+
---
5+
{{- end }}
6+
{{- end }}

charts/postgres-operator/templates/customrresourcedefinition.yaml

Lines changed: 0 additions & 103 deletions
This file was deleted.

docs/quickstart.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ manifest.
7373
### Helm chart
7474

7575
Alternatively, the operator can be installed by using the provided [Helm](https://helm.sh/)
76-
chart which saves you the manual steps. Therefore, install the helm CLI on your
77-
machine. After initializing helm (and its server component Tiller) in your local
78-
cluster you can install the operator chart. You can define a release name that
79-
is prepended to the operator resource's names.
76+
chart which saves you the manual steps. Clone this repo and change directory to
77+
the repo root. With Helm v3 installed you should be able to run:
8078

81-
Use `--name zalando` to match with the default service account name as older
82-
operator versions do not support custom names for service accounts. To use
83-
CRD-based configuration you need to specify the [values-crd yaml file](../charts/postgres-operator/values-crd.yaml).
79+
```bash
80+
helm install postgres-operator ./charts/postgres-operator
81+
```
82+
83+
To use CRD-based configuration you need to specify the [values-crd yaml file](../charts/postgres-operator/values-crd.yaml).
8484

8585
```bash
86-
# 1) initialize helm
87-
helm init
88-
# 2) install postgres-operator chart
89-
helm install --name zalando ./charts/postgres-operator
86+
helm install postgres-operator ./charts/postgres-operator -f ./charts/postgres-operator/values-crd.yaml
9087
```
9188

89+
The chart works with both Helm 2 and Helm 3. Documentation for installing
90+
applications with helm2 can be found in the [helm2 docs](https://v2.helm.sh/docs/).
91+
9292
### Operator Lifecycle Manager (OLM)
9393

9494
The [Operator Lifecycle Manager (OLM)](https://github.com/operator-framework/operator-lifecycle-manager)

0 commit comments

Comments
 (0)