Skip to content

Commit a585b17

Browse files
authored
Generate postgresql CRD from go structs (#3007)
* Sort postgresql.crd.yaml * Generate postgresql CRD from go structs * Expand sidecars, env and initcontainers * Embed CRD to be submitted by the operator Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de> --------- Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
1 parent 0a44252 commit a585b17

8 files changed

Lines changed: 4059 additions & 1481 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ mocks
106106
ui/.npm/
107107

108108
.DS_Store
109+
110+
# temp build files
111+
pkg/apis/acid.zalan.do/v1/postgresql.crd.yaml

Makefile

Lines changed: 11 additions & 4 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,8 @@ default: local
5454

5555
clean:
5656
rm -rf build
57+
rm $(GENERATED)
58+
rm pkg/apis/acid.zalan.do/v1/postgresql.crd.yaml
5759

5860
verify:
5961
hack/verify-codegen.sh
@@ -63,10 +65,15 @@ $(GENERATED): go.mod $(CRD_SOURCES)
6365

6466
$(GENERATED_CRDS): $(GENERATED)
6567
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
68+
# only generate postgresteam.crd.yaml and postgresql.crd.yaml for now
6769
@rm manifests/acid.zalan.do_operatorconfigurations.yaml
68-
@rm manifests/acid.zalan.do_postgresqls.yaml
70+
@mv manifests/acid.zalan.do_postgresqls.yaml manifests/postgresql.crd.yaml
71+
@# hack to use lowercase kind and listKind
72+
@sed -i -e 's/kind: Postgresql/kind: postgresql/' manifests/postgresql.crd.yaml
73+
@sed -i -e 's/listKind: PostgresqlList/listKind: postgresqlList/' manifests/postgresql.crd.yaml
74+
@hack/adjust_postgresql_crd.sh
6975
@mv manifests/acid.zalan.do_postgresteams.yaml manifests/postgresteam.crd.yaml
76+
@cp manifests/postgresql.crd.yaml pkg/apis/acid.zalan.do/v1/postgresql.crd.yaml
7077

7178
local: ${SOURCES} $(GENERATED_CRDS)
7279
CGO_ENABLED=${CGO_ENABLED} go build -o build/${BINARY} $(LOCAL_BUILD_FLAGS) -ldflags "$(LDFLAGS)" $(SOURCES)
@@ -98,7 +105,7 @@ vet:
98105
@go vet $(PKG)
99106
@staticcheck $(PKG)
100107

101-
test: mocks $(GENERATED)
108+
test: mocks $(GENERATED) $(GENERATED_CRDS)
102109
GO111MODULE=on go test ./...
103110

104111
codegen: $(GENERATED)

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)