Skip to content

Commit a9b1b85

Browse files
committed
Generate postgresql CRD from go structs
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
1 parent 1b9307e commit a9b1b85

5 files changed

Lines changed: 590 additions & 164 deletions

File tree

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ GITSTATUS = $(shell git status --porcelain || echo "no changes")
2121
SOURCES = cmd/main.go
2222
VERSION ?= $(shell git describe --tags --always --dirty)
2323
CRD_SOURCES = $(shell find pkg/apis/zalando.org pkg/apis/acid.zalan.do -name '*.go' -not -name '*.deepcopy.go')
24-
GENERATED_CRDS = manifests/postgresteam.crd.yaml
24+
GENERATED_CRDS = manifests/postgresteam.crd.yaml manifests/postgresql.crd.yaml
2525
GENERATED = pkg/apis/zalando.org/v1/zz_generated.deepcopy.go pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go
2626
DIRS := cmd pkg
2727
PKG := `go list ./... | grep -v /vendor/`
@@ -54,6 +54,7 @@ default: local
5454

5555
clean:
5656
rm -rf build
57+
rm $(GENERATED)
5758

5859
verify:
5960
hack/verify-codegen.sh
@@ -63,9 +64,13 @@ $(GENERATED): go.mod $(CRD_SOURCES)
6364

6465
$(GENERATED_CRDS): $(GENERATED)
6566
go tool controller-gen crd:crdVersions=v1,allowDangerousTypes=true paths=./pkg/apis/acid.zalan.do/... output:crd:dir=manifests
66-
# only generate postgresteam.crd.yaml for now
67+
# only generate postgresteam.crd.yaml and postgresql.crd.yaml for now
6768
@rm manifests/acid.zalan.do_operatorconfigurations.yaml
68-
@rm manifests/acid.zalan.do_postgresqls.yaml
69+
@mv manifests/acid.zalan.do_postgresqls.yaml manifests/postgresql.crd.yaml
70+
@# hack to use lowercase kind and listKind
71+
@sed -i -e 's/kind: Postgresql/kind: postgresql/' manifests/postgresql.crd.yaml
72+
@sed -i -e 's/listKind: PostgresqlList/listKind: postgresqlList/' manifests/postgresql.crd.yaml
73+
@hack/adjust_postgresql_crd.sh
6974
@mv manifests/acid.zalan.do_postgresteams.yaml manifests/postgresteam.crd.yaml
7075

7176
local: ${SOURCES} $(GENERATED_CRDS)

hack/adjust_postgresql_crd.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# Hack to adjust the generated postgresql CRD YAML file and add missing field
4+
# settings which can not be expressed via kubebuilder markers.
5+
#
6+
# Injections:
7+
#
8+
# * oneOf: for the standby field to enforce that only one of s3_wal_path, gs_wal_path or standby_host is set.
9+
# * This can later be done with // +kubebuilder:validation:ExactlyOneOf marker, but this requires latest Kubernetes version. (Currently the operator depends on v1.32.9)
10+
# * type: string and pattern for the maintenanceWindows items.
11+
12+
file="${1:-"manifests/postgresql.crd.yaml"}"
13+
14+
sed -i '/^[[:space:]]*standby:$/{
15+
# Capture the indentation
16+
s/^\([[:space:]]*\)standby:$/\1standby:\n\1 oneOf:\n\1 - required:\n\1 - s3_wal_path\n\1 - required:\n\1 - gs_wal_path\n\1 - required:\n\1 - standby_host/
17+
}' "$file"
18+
19+
sed -i '/^[[:space:]]*maintenanceWindows:$/{
20+
# Capture the indentation
21+
s/^\([[:space:]]*\)maintenanceWindows:$/\1maintenanceWindows:\n\1 items:\n\1 pattern: '\''^\\ *((Mon|Tue|Wed|Thu|Fri|Sat|Sun):(2[0-3]|[01]?\\d):([0-5]?\\d)|(2[0-3]|[01]?\\d):([0-5]?\\d))-((2[0-3]|[01]?\\d):([0-5]?\\d)|(2[0-3]|[01]?\\d):([0-5]?\\d))\\ *$'\''\n\1 type: string/
22+
}' "$file"

0 commit comments

Comments
 (0)