1+ # ==============================================================================
2+ # Percona Server MongoDB Operator - OLM Bundle Generation
3+ # ==============================================================================
4+
5+ # Default target
6+ .DEFAULT_GOAL := help
7+ .SUFFIXES :
8+ SHELL := /bin/bash
9+
10+ # ==============================================================================
11+ # Configuration Variables
12+ # ==============================================================================
13+
14+ # Project configuration
115NAME ?= percona-server-mongodb-operator
216IMAGE_TAG_OWNER ?= perconalab
317IMAGE_TAG_BASE ?= $(IMAGE_TAG_OWNER ) /$(NAME )
4- SED := $(shell which gsed || which sed)
5- VERSION ?= $(shell git rev-parse --abbrev-ref HEAD | $(SED ) -e 's^/^-^g; s^[.]^-^g;' | tr '[:upper:]' '[:lower:]')
6- IMAGE ?= $(IMAGE_TAG_BASE ) :$(VERSION )
718MODE ?= namespace
8- DEPLOYDIR = ./deploy
9-
10- BUNDLEDIR = $(DEPLOYDIR ) /csv/redhat
11- BUNDLE_CHANNELS := --channels=stable
12- BUNDLE_DEFAULT_CHANNEL := --default-channel=stable
13- BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS ) $(BUNDLE_DEFAULT_CHANNEL )
1419
15- # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
16- ENVTEST_K8S_VERSION = 1.23
17- .DEFAULT_GOAL := help
18- .SUFFIXES :
20+ # Version detection
21+ SED := $( shell which gsed || which sed)
22+ VERSION ?= $( shell git rev-parse --abbrev-ref HEAD | $( SED ) -e 's^/^-^g; s^[.]^-^g;' | tr '[:upper:]' '[:lower:]')
23+ IMAGE := $( IMAGE_TAG_BASE ) : $( VERSION )
1924
20- CONTAINER ?= docker
21- OPENSHIFT_VERSIONS ?= v4.13 -v4.16
25+ # Bundle configuration
26+ OPENSHIFT_VERSIONS ?= v4.16 -v4.19
2227PACKAGE_CHANNEL ?= stable
23- MIN_KUBE_VERSION ?= 1.24.0
28+ MIN_KUBE_VERSION ?= ""
2429DOCKER_DEFAULT_PLATFORM ?= linux/amd64
25- SHELL := /bin/bash
26- REPO_ROOT = $(shell git rev-parse --show-toplevel)
2730
31+ # Paths
32+ REPO_ROOT := $(shell git rev-parse --show-toplevel)
33+ KUSTOMIZE := $(REPO_ROOT ) /bin/kustomize
34+
35+ # Tool versions
36+ OPERATOR_SDK_VERSION := v1.41.1
37+
38+ # Bundle image configuration
39+ BUNDLE_IMG ?= $(IMAGE_TAG_BASE ) :community-bundle-$(VERSION )
40+
41+ # System detection for tool downloads
42+ UNAME_S := $(shell uname -s)
43+ UNAME_M := $(shell uname -m)
44+ OS_KERNEL := $(shell echo "$(UNAME_S ) " | tr '[:upper:]' '[:lower:]')
45+ OS_MACHINE := $(UNAME_M )
46+
47+ # Display colors
2848GREEN := $(shell tput setaf 2)
2949RESET := $(shell tput sgr0)
3050
31- export VERSION
32- export BUNDLE_REPO
33- export OPENSHIFT_VERSIONS
34- export PACKAGE_CHANNEL
35- export MIN_KUBE_VERSION
36- export DOCKER_DEFAULT_PLATFORM
37- export MODE
51+ # Export variables for generate.sh
52+ export VERSION OPENSHIFT_VERSIONS PACKAGE_CHANNEL MIN_KUBE_VERSION DOCKER_DEFAULT_PLATFORM MODE
53+
54+ # ==============================================================================
55+ # Bundle Targets
56+ # ==============================================================================
3857
39- REPO_ROOT = $( shell git rev-parse --show-toplevel)
58+ DISTROS := community redhat marketplace
4059
41- distros = community redhat marketplace
60+ .PHONY : bundles
61+ bundles : # # Build all OLM bundles (community, redhat, marketplace)
62+ bundles : check-prereqs $(DISTROS:%=bundles/% )
4263
64+ .PHONY : $(DISTROS:%=bundles/% )
65+ $(DISTROS:% =bundles/%): bundles/%: tools/operator-sdk
66+ @echo "$(GREEN)Building $* bundle...$(RESET)"
67+ cd ../../config/manager/$(MODE)/ && $(KUSTOMIZE) edit set image psmdb-operator=$(IMAGE)
68+ ./generate.sh $*
69+ ./tools/operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
70+ $(if $(filter community,$*),./tools/operator-sdk bundle validate $@ --select-optional='name=community' --optional-values='index-path=$@/Dockerfile')
71+ @echo "$(GREEN)✓ Bundle stored in installers/olm/bundles/$*$(RESET)"
72+
73+ # ==============================================================================
74+ # Docker Build & Push Targets
75+ # ==============================================================================
76+
77+ .PHONY : build
78+ build : # # Build community bundle Docker image
79+ build :
80+ @echo " $( GREEN) Building bundle Docker image...$( RESET) "
81+ docker build -f bundles/community/Dockerfile -t $(BUNDLE_IMG ) --platform=linux/amd64 bundles/community
82+ @echo " $( GREEN) ✓ Bundle image built: $( BUNDLE_IMG) $( RESET) "
83+
84+ .PHONY : push
85+ push : # # Push bundle Docker image to registry
86+ @echo " $( GREEN) Pushing bundle image to registry...$( RESET) "
87+ docker push $(BUNDLE_IMG )
88+ @echo " $( GREEN) ✓ Bundle image pushed: $( BUNDLE_IMG) $( RESET) "
89+
90+ # ==============================================================================
91+ # Utility Targets
92+ # ==============================================================================
93+
94+ .PHONY : check-prereqs
95+ check-prereqs : check-version check-git check-tools
96+
97+ .PHONY : check-version
4398check-version :
4499ifndef VERSION
45100 $(error VERSION is not set)
46101endif
47102
48- KUSTOMIZE = $(REPO_ROOT ) /bin/kustomize
49- kustomize : # # Download kustomize locally if necessary.
50- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] ) 51-
52- .PHONY : bundles
53- bundles : # # Build OLM bundles
54- bundles : check-version $(distros:%=bundles/% )
55-
56- # https://olm.operatorframework.io/docs/tasks/creating-operator-bundle/#validating-your-bundle
57- # https://github.com/operator-framework/community-operators/blob/8a36a33/docs/packaging-required-criteria-ocp.md
58- .PHONY : bundles/community
59- bundles/community :
60- cd ../../config/manager/$(MODE ) / && $(KUSTOMIZE ) edit set image psmdb-operator=$(IMAGE )
61- ./generate.sh community
62-
63- env operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
64- env operator-sdk bundle validate $@ --select-optional='name=community' --optional-values='index-path=$@/Dockerfile'
65- @echo "$(GREEN)!!!!!!!!!!! Build stored in installers/olm/bundles/community !!!!!!!!!!!!!!!$(RESET)"
66-
67- .PHONY : bundles/redhat
68- bundles/redhat :
69- cd ../../config/manager/$(MODE ) / && $(KUSTOMIZE ) edit set image psmdb-operator=$(IMAGE )
70- ./generate.sh redhat
71- env operator-sdk bundle validate $@ --select-optional=' suite=operatorframework'
72- @echo " $( GREEN) !!!!!!!!!!! Build stored in installers/olm/bundles/redhat !!!!!!!!!!!!!!!$( RESET) "
103+ .PHONY : check-git
104+ check-git :
105+ @if ! git rev-parse --git-dir > /dev/null 2>&1 ; then \
106+ echo " Error: Not in a git repository" ; \
107+ exit 1; \
108+ fi
109+
110+ .PHONY : check-tools
111+ check-tools :
112+ @for cmd in gawk gcsplit yq; do \
113+ if ! command -v $$ cmd > /dev/null 2>&1 ; then \
114+ echo " Error: $$ cmd is required but not installed" ; \
115+ exit 1; \
116+ fi ; \
117+ done
73118
74- # The 'marketplace' configuration is currently identical to the 'redhat', so we just copy it here.
75- .PHONY : bundles/marketplace
76- bundles/marketplace :
77- cd ../../config/manager/$(MODE ) / && $(KUSTOMIZE ) edit set image psmdb-operator=$(IMAGE )
78- ./generate.sh marketplace
79- env operator-sdk bundle validate $@ --select-optional=' suite=operatorframework'
80- @echo " $( GREEN) !!!!!!!!!!! Build stored in installers/olm/bundles/marketplace !!!!!!!!!!!!!!!$( RESET) "
119+ .PHONY : install-olm
120+ install-olm : # # Install OLM in Kubernetes cluster
121+ install-olm : tools/operator-sdk
122+ ./tools/operator-sdk olm install
81123
82124.PHONY : clean
83- clean : clean-deprecated
84125clean : # # Remove generated files and downloaded tools
85126 rm -rf ./bundles ./projects ./tools
86127
87- .PHONY : clean-deprecated
88- clean-deprecated :
89- rm -rf ./package
90-
91128.PHONY : help
92- help : ALIGN=18
93- help : # # Print this message
94- @awk -F ' : ## ' -- " /^[^':]+: ## /" ' { printf "' $$(tput bold ) ' %-$(ALIGN)s' $$(tput sgr0 ) ' %s\n", $$1, $$2 }' $(MAKEFILE_LIST )
129+ help : # # Show this help message
130+ @awk ' BEGIN {FS = ": ## "; printf "\n$(GREEN)Usage:$(RESET)\n make [target]\n\n$(GREEN)Targets:$(RESET)\n"} /^[a-zA-Z_-]+: ## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST )
95131
96- .PHONY : install-olm
97- install-olm : # # Install OLM in Kubernetes
98- env operator-sdk olm install
132+ # ==============================================================================
133+ # Tool Management
134+ # ==============================================================================
99135
100136.PHONY : tools
101- tools : # # Download tools needed to build bundles
102-
103- tools : tools/$(SYSTEM ) /jq
104- tools/$(SYSTEM ) /jq :
105- install -d ' $(dir $@)'
106- curl -fSL -o ' $@' " https://github.com/stedolan/jq/releases/download/jq-1.7.1/jq-$$ (SYSTEM='$( SYSTEM) '; \
107- case " $$ SYSTEM" in \
108- (linux-* ) echo " $$ {SYSTEM/-amd/}" ;; (darwin-* ) echo " $$ {SYSTEM/darwin-*/osx-amd64}" ;; (* ) echo ' $(SYSTEM)' ;; \
109- esac)"
110- chmod u+x ' $@'
111-
112- tools : tools/$(SYSTEM ) /kubectl
113- tools/$(SYSTEM ) /kubectl :
114- install -d ' $(dir $@)'
115- curl -fSL -o ' $@' ' https://dl.k8s.io/release/$(shell curl -Ls https://dl.k8s.io/release/stable-1.31.txt)/bin/$(OS_KERNEL)/$(OS_MACHINE)/kubectl'
116- chmod u+x ' $@'
117-
118- # quay.io/operator-framework/operator-sdk
119- tools : tools/$(SYSTEM ) /operator-sdk
120- tools/$(SYSTEM ) /operator-sdk :
121- install -d ' $(dir $@)'
122- curl -fSL -o ' $@' ' https://github.com/operator-framework/operator-sdk/releases/download/v1.39.1/operator-sdk_$(OS_KERNEL)_$(OS_MACHINE)'
123- chmod u+x ' $@'
124-
125- tools : tools/$(SYSTEM ) /opm
126- tools/$(SYSTEM ) /opm :
127- install -d ' $(dir $@)'
128- curl -fSL -o ' $@' ' https://github.com/operator-framework/operator-registry/releases/download/v1.50.0/$(OS_KERNEL)-$(OS_MACHINE)-opm'
129- chmod u+x ' $@'
130-
131- tools/$(SYSTEM ) /venv :
132- install -d ' $(dir $@)'
133- python3 -m venv ' $@'
134-
135- tools : tools/$(SYSTEM ) /yq
136- tools/$(SYSTEM ) /yq : | tools/$(SYSTEM ) /venv
137- ' tools/$(SYSTEM)/venv/bin/python' -m pip install yq
138- cd ' $(dir $@)' && ln -s venv/bin/yq
137+ tools : # # Download required tools
138+ tools : tools/operator-sdk
139+
140+ # Download operator-sdk
141+ tools/operator-sdk :
142+ @echo " Downloading operator-sdk $( OPERATOR_SDK_VERSION) ..."
143+ @install -d tools
144+ @curl -fSL --fail -o ' $@' \
145+ ' https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(OS_KERNEL)_$(OS_MACHINE)' \
146+ || { rm -f ' $@' ; echo " Failed to download operator-sdk" ; exit 1; }
147+ @chmod +x ' $@'
148+ @echo " ✓ operator-sdk installed"
149+
150+ # ==============================================================================
151+ # Development Targets
152+ # ==============================================================================
153+
154+ .PHONY : validate
155+ validate : # # Validate existing bundles without rebuilding
156+ @for distro in $(DISTROS ) ; do \
157+ if [ -d " bundles/$$ distro" ]; then \
158+ echo " Validating $$ distro bundle..." ; \
159+ ./tools/operator-sdk bundle validate " bundles/$$ distro" --select-optional=' suite=operatorframework' || exit 1; \
160+ fi ; \
161+ done
162+ @echo " $( GREEN) ✓ All bundles validated$( RESET) "
163+
164+ .PHONY : list-versions
165+ list-versions : # # Show current version information
166+ @echo " Current configuration:"
167+ @echo " VERSION: $( VERSION) "
168+ @echo " IMAGE: $( IMAGE) "
169+ @echo " MODE: $( MODE) "
170+ @echo " OPENSHIFT_VERSIONS: $( OPENSHIFT_VERSIONS) "
171+ @echo " MIN_KUBE_VERSION: $( MIN_KUBE_VERSION) "
172+
173+ # ==============================================================================
174+ # Kustomize Integration (from root Makefile)
175+ # ==============================================================================
176+
177+ # Include go-get-tool function from root Makefile if kustomize target is needed
178+ ifneq (,$(findstring kustomize,$(MAKECMDGOALS ) ) )
179+ include ../../Makefile
180+ endif
139181
182+ .PHONY : kustomize
183+ kustomize : # # Download kustomize locally if necessary
184+ $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v4@latest)
0 commit comments