Skip to content

Commit bd1fe37

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

File tree

5 files changed

+597
-166
lines changed

5 files changed

+597
-166
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/add_oneof.sh
6772
@mv manifests/acid.zalan.do_postgresteams.yaml manifests/postgresteam.crd.yaml
6873

6974
local: ${SOURCES} $(GENERATED_CRDS)

hack/add_oneof.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
# Hack to add oneOf config for the standby field in the CRD which can't be done
4+
# automatically via kubebuilder markers
5+
6+
file="${1:-"manifests/postgresql.crd.yaml"}"
7+
8+
sed -i '/^[[:space:]]*standby:$/{
9+
# Capture the indentation
10+
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/
11+
}' "$file"

0 commit comments

Comments
 (0)