Skip to content

Commit f1a933c

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

File tree

5 files changed

+589
-164
lines changed

5 files changed

+589
-164
lines changed

Makefile

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

5353
clean:
5454
rm -rf build
55+
rm $(GENERATED)
5556

5657
verify:
5758
hack/verify-codegen.sh
@@ -61,9 +62,13 @@ $(GENERATED): go.mod $(CRD_SOURCES)
6162

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

6974
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)