1+ # ==============================================================================
2+ # Percona PostgreSQL Operator - OLM Bundle Generation
3+ # ==============================================================================
4+
5+ # Default target
16.DEFAULT_GOAL := help
27.SUFFIXES :
8+ SHELL := /bin/bash
9+
10+ # ==============================================================================
11+ # Configuration Variables
12+ # ==============================================================================
313
14+ # Project configuration
15+ NAME ?= percona-postgresql-operator
16+ COMMUNITY_REGISTRY ?= docker.io
17+ IMAGE_TAG_OWNER ?= percona
18+ IMAGE_TAG_BASE ?= $(IMAGE_TAG_OWNER ) /$(NAME )
419CONTAINER ?= docker
5- OPENSHIFT_VERSIONS ?= v4.10-v4.12
6- PACKAGE_CHANNEL ?= preview
7- MIN_KUBE_VERSION ?= 1.23.0
20+
21+ # Bundle configuration
22+ OPENSHIFT_VERSIONS ?= v4.18-v4.21
823DOCKER_DEFAULT_PLATFORM ?= linux/amd64
9- SHELL := /bin/bash
1024
11- IMAGE_TAG_BASE ?= perconalab/percona-postgresql-operator
25+ # Image configuration
26+ IMAGE ?= $(COMMUNITY_REGISTRY ) /$(IMAGE_TAG_BASE ) :$(VERSION )
1227BUNDLE_REPO ?= $(IMAGE_TAG_BASE )
28+ BUNDLE_DISTRO ?= community
29+ BUNDLE_IMG ?= $(BUNDLE_REPO ) :$(VERSION ) -$(BUNDLE_DISTRO ) -bundle
30+ REDHAT_OPERATOR_IMAGE ?= registry.connect.redhat.com/percona/percona-postgresql-operator:$(VERSION )
1331
14- IMAGE ?= $(IMAGE_TAG_BASE ) :$(VERSION )
32+ # Paths
33+ REPO_ROOT := $(shell git rev-parse --show-toplevel)
34+ KUSTOMIZE := $(REPO_ROOT ) /bin/kustomize
1535
16- ifeq ( $( shell bash -c 'echo $$BASH_VERSION | cut -d "." -f1') , 5)
17- else
18- $(error You need to use bash 5.x+ for this Makefile)
19- endif
36+ # Tool versions
37+ JQ_VERSION := 1.7.1
38+ OPERATOR_SDK_VERSION := v1.42.2
39+ OPM_VERSION := v1.66.0
2040
21- OS_KERNEL ?= $(shell bash -c 'echo $${1,,}' - `uname -s`)
22- OS_MACHINE ?= $(shell bash -c 'echo $${1/x86_/amd}' - `uname -m`)
23- SYSTEM = $(OS_KERNEL ) -$(OS_MACHINE )
2441
25- export PATH := $(CURDIR ) /tools/$(SYSTEM ) :$(PATH )
42+ OS_KERNEL ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
43+ OS_MACHINE ?= $(shell uname -m | sed 's/^x86_/amd/')
44+ SYSTEM := $(OS_KERNEL ) -$(OS_MACHINE )
2645
27- export VERSION
28- export BUNDLE_REPO
29- export OPENSHIFT_VERSIONS
30- export PACKAGE_CHANNEL
31- export MIN_KUBE_VERSION
32- export DOCKER_DEFAULT_PLATFORM
46+ export PATH := $(CURDIR ) /tools/$(SYSTEM ) :$(PATH )
3347
34- REPO_ROOT = $(shell git rev-parse --show-toplevel)
48+ # Display colors
49+ GREEN := $(shell tput setaf 2)
50+ RESET := $(shell tput sgr0)
3551
36- distros = community redhat marketplace
52+ # Export variables for generate.sh
53+ export VERSION IMAGE REDHAT_OPERATOR_IMAGE BUNDLE_REPO OPENSHIFT_VERSIONS DOCKER_DEFAULT_PLATFORM
3754
38- check-version :
39- ifndef VERSION
40- $(error VERSION is not set)
41- endif
55+ # ==============================================================================
56+ # Bundle Targets
57+ # ==============================================================================
4258
43- KUSTOMIZE = $(REPO_ROOT ) /bin/kustomize
44- kustomize : # # Download kustomize locally if necessary.
45- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v4@v4.5.3)
59+ DISTROS := community redhat
4660
4761.PHONY : bundles
48- bundles : # # Build OLM bundles
49- bundles : check-version $(distros :%=bundles/% )
62+ bundles : # # Build all OLM bundles (community, redhat)
63+ bundles : check-prereqs $(DISTROS :%=bundles/% )
5064
5165# https://olm.operatorframework.io/docs/tasks/creating-operator-bundle/#validating-your-bundle
52- # https://github.com/operator-framework/community-operators/blob/8a36a33/docs/packaging-required-criteria-ocp.md
5366.PHONY : bundles/community
54- bundles/community :
55- cd ../../config/manager/default/ && $(KUSTOMIZE ) edit set image postgres-operator=$(IMAGE )
67+ bundles/community : tools $(KUSTOMIZE )
68+ @echo " $( GREEN) Building community bundle...$( RESET) "
69+ cd ../../config/manager/default/ && $(KUSTOMIZE ) edit set image ' postgres-operator=$(IMAGE)'
5670 ./generate.sh community
57- env operator-sdk bundle validate $@ --select-optional=' suite=operatorframework'
58- env operator-sdk bundle validate $@ --select-optional= ' name= community' --optional-values= ' index-path=$@/Dockerfile '
71+ operator-sdk bundle validate $@ --select-optional=' suite=operatorframework'
72+ @echo " $( GREEN ) Bundle stored in installers/olm/bundles/ community$( RESET ) "
5973
6074# https://redhat-connect.gitbook.io/certified-operator-guide/ocp-deployment/operator-metadata/reviewing-your-metadata-bundle
6175.PHONY : bundles/redhat
62- bundles/redhat :
63- cd ../../config/manager/default/ && $(KUSTOMIZE ) edit set image postgres-operator=$(IMAGE )
76+ bundles/redhat : tools $(KUSTOMIZE )
77+ @echo " $( GREEN) Building redhat bundle...$( RESET) "
78+ cd ../../config/manager/default/ && $(KUSTOMIZE ) edit set image ' postgres-operator=$(REDHAT_OPERATOR_IMAGE)'
6479 ./generate.sh redhat
65- env operator-sdk bundle validate $@ --select-optional=' suite=operatorframework'
80+ operator-sdk bundle validate $@ --select-optional=' suite=operatorframework'
81+ @echo " $( GREEN) Bundle stored in installers/olm/bundles/redhat$( RESET) "
82+
83+ # ==============================================================================
84+ # Docker Build & Push Targets
85+ # ==============================================================================
86+
87+ .PHONY : build
88+ build : # # Build bundle image (set BUNDLE_DISTRO=community|redhat)
89+ build : check-version bundles/$(BUNDLE_DISTRO )
90+ @echo " $( GREEN) Building bundle image...$( RESET) "
91+ $(CONTAINER ) build -t $(BUNDLE_IMG ) --platform=$(DOCKER_DEFAULT_PLATFORM ) bundles/$(BUNDLE_DISTRO )
92+ @echo " $( GREEN) Bundle image built: $( BUNDLE_IMG) $( RESET) "
93+
94+ .PHONY : push
95+ push : # # Push bundle image to registry
96+ push : check-version
97+ @echo " $( GREEN) Pushing bundle image to registry...$( RESET) "
98+ $(CONTAINER ) push $(BUNDLE_IMG )
99+ @echo " $( GREEN) Bundle image pushed: $( BUNDLE_IMG) $( RESET) "
100+
101+ # ==============================================================================
102+ # Utility Targets
103+ # ==============================================================================
104+
105+ .PHONY : check-prereqs
106+ check-prereqs : check-version tools $(KUSTOMIZE )
107+
108+ .PHONY : check-version
109+ check-version :
110+ ifndef VERSION
111+ $(error VERSION is not set)
112+ endif
113+
114+ $(KUSTOMIZE ) :
115+ $(MAKE ) -C ' $(REPO_ROOT)' kustomize
66116
67- # The 'marketplace' configuration is currently identical to the 'redhat', so we just copy it here.
68- .PHONY : bundles/marketplace
69- bundles/marketplace :
70- cd ../../config/manager/default/ && $(KUSTOMIZE ) edit set image postgres-operator=$(IMAGE )
71- cp -r ./config/redhat/ ./config/marketplace
72- ./generate.sh marketplace
73- env operator-sdk bundle validate $@ --select-optional=' suite=operatorframework'
117+ .PHONY : install-olm
118+ install-olm : # # Install OLM in Kubernetes
119+ install-olm : tools
120+ operator-sdk olm install
74121
75122.PHONY : clean
76- clean : clean-deprecated
77123clean : # # Remove generated files and downloaded tools
78- rm -rf ./bundles ./projects ./tools ./config/marketplace
79-
80- .PHONY : clean-deprecated
81- clean-deprecated :
82- rm -rf ./package
124+ rm -rf ./bundles ./projects ./tools
83125
84126.PHONY : help
85- help : ALIGN=18
86- help : # # Print this message
87- @awk -F ' : ## ' -- " /^[^':]+: ## /" ' { printf "' $$(tput bold ) ' %-$(ALIGN)s' $$(tput sgr0 ) ' %s\n", $$1, $$2 }' $(MAKEFILE_LIST )
127+ help : # # Show this help message
128+ @awk ' BEGIN {FS = ": ## "; printf "\n$(GREEN)Usage:$(RESET)\n make [target]\n\n$(GREEN)Targets:$(RESET)\n"} /^[a-zA-Z_-]+: ## / {printf " %-24s %s\n", $$1, $$2}' $(MAKEFILE_LIST )
88129
89- .PHONY : install-olm
90- install-olm : # # Install OLM in Kubernetes
91- env operator-sdk olm install
130+ # ==============================================================================
131+ # Tool Management
132+ # ==============================================================================
92133
93134.PHONY : tools
94- tools : # # Download tools needed to build bundles
95-
135+ tools : # # Download required tools
96136tools : tools/$(SYSTEM ) /jq
97137tools/$(SYSTEM ) /jq :
98138 install -d ' $(dir $@)'
99- curl -fSL -o ' $@' " https://github.com/stedolan/jq/releases/download/jq-1.7.1 /jq-$$ (SYSTEM='$( SYSTEM) '; \
139+ curl -fSL -o ' $@' " https://github.com/stedolan/jq/releases/download/jq-$( JQ_VERSION ) /jq-$$ (SYSTEM='$( SYSTEM) '; \
100140 case " $$ SYSTEM" in \
101141 (linux-* ) echo " $$ {SYSTEM/-amd/}" ;; (darwin-* ) echo " $$ {SYSTEM/darwin-*/osx-amd64}" ;; (* ) echo ' $(SYSTEM)' ;; \
102142 esac)"
@@ -105,20 +145,20 @@ tools/$(SYSTEM)/jq:
105145tools : tools/$(SYSTEM ) /kubectl
106146tools/$(SYSTEM ) /kubectl :
107147 install -d ' $(dir $@)'
108- curl -fSL -o ' $@' ' https://dl.k8s.io/release/$(shell curl -Ls https://dl.k8s.io/release/stable-1.21 .txt)/bin/$(OS_KERNEL)/$(OS_MACHINE)/kubectl'
148+ curl -fSL -o ' $@' ' https://dl.k8s.io/release/$(shell curl -Ls https://dl.k8s.io/release/stable.txt)/bin/$(OS_KERNEL)/$(OS_MACHINE)/kubectl'
109149 chmod u+x ' $@'
110150
111151# quay.io/operator-framework/operator-sdk
112152tools : tools/$(SYSTEM ) /operator-sdk
113153tools/$(SYSTEM ) /operator-sdk :
114154 install -d ' $(dir $@)'
115- curl -fSL -o ' $@' ' https://github.com/operator-framework/operator-sdk/releases/download/v1.19.1 /operator-sdk_$(OS_KERNEL)_$(OS_MACHINE)'
155+ curl -fSL -o ' $@' ' https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION) /operator-sdk_$(OS_KERNEL)_$(OS_MACHINE)'
116156 chmod u+x ' $@'
117157
118158tools : tools/$(SYSTEM ) /opm
119159tools/$(SYSTEM ) /opm :
120160 install -d ' $(dir $@)'
121- curl -fSL -o ' $@' ' https://github.com/operator-framework/operator-registry/releases/download/v1.33.0 /$(OS_KERNEL)-$(OS_MACHINE)-opm'
161+ curl -fSL -o ' $@' ' https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION) /$(OS_KERNEL)-$(OS_MACHINE)-opm'
122162 chmod u+x ' $@'
123163
124164tools/$(SYSTEM ) /venv :
@@ -130,10 +170,15 @@ tools/$(SYSTEM)/yq: | tools/$(SYSTEM)/venv
130170 ' tools/$(SYSTEM)/venv/bin/python' -m pip install yq
131171 cd ' $(dir $@)' && ln -s venv/bin/yq
132172
173+ # ==============================================================================
174+ # Development Targets
175+ # ==============================================================================
176+
133177.PHONY : validate-bundles
134178validate-bundles : # # Build temporary bundle images and run scorecard tests in Kubernetes
135- validate-bundles : $(distros:%=validate-%-image )
136- validate-bundles : $(distros:%=validate-%-directory )
179+ validate-bundles : tools
180+ validate-bundles : $(DISTROS:%=validate-%-image )
181+ validate-bundles : $(DISTROS:%=validate-%-directory )
137182
138183validate-% -directory :
139184 ./validate-directory.sh ' bundles/$*'
@@ -142,7 +187,7 @@ validate-%-image:
142187 ./validate-image.sh ' $(CONTAINER)' ' bundles/$*'
143188
144189.PHONY : build-bundle-images
145- build-bundle-images : check-version $(distros :%=build-%-image )
190+ build-bundle-images : check-version $(DISTROS :%=build-%-image )
146191
147192build-% -image :
148193 ./build-image.sh ' $(CONTAINER)' ' bundles/$*' ' $*' ' $(VERSION)'
0 commit comments