Repository: stolostron/cluster-api-installer
Pull request #56: add backplane-% as release branches for CAPOA
Author: login: rccrdpccl
Labels: name: approved
name: lgtm
Created: 2025-04-09T15:53:14Z | Merged: 2025-04-10T14:07:39Z

Add expected release branches for CAPOA.


Diff:
diff --git a/charts/Makefile b/charts/Makefile
index 32e706f8..57644e81 100644
--- a/charts/Makefile
+++ b/charts/Makefile
@@ -1,63 +1,100 @@
 OCP_VERSION ?= 4.19
-BRANCH ?= master
 SYNC2CHARTS ?= true
-ORGREPO ?= https://github.com/openshift
-PROJECTS = \
-	cluster-api \
-	cluster-api-provider-aws \
-	cluster-api-provider-openshift-assisted \
-	cluster-api-provider-metal3
 
-ifeq ($(filter $(BRANCH), master main),$(BRANCH))
-	TAG := latest
-else
-	TAG := $(patsubst release-%, %,$(BRANCH))
-endif
-CHART_VERSION = $(OCP_VERSION)
-CHART_APP_VERSION = $(OCP_VERSION)
-CHART_VALUES_IMAGE_TAG = $(OCP_VERSION)
-CHART_VALUES_IMAGE_TAG_PREFIX = "v"
+DEFAULT_BRANCH ?= master
+DEFAULT_ORGREPO ?= https://github.com/openshift
+# needs overridable branch, as the non-master branch will differ
+OPENSHIFT_ASSISTED_BRANCH ?= master
+METAL3_BRANCH ?= main
 
-# Define specific overrides
-ORGREPO_cluster-api-provider-openshift-assisted = https://github.com/openshift-assisted
-KUSTOMIZE_CONFIG_DIRS_cluster-api-provider-openshift-assisted = "bootstrap" "controlplane"
-CHART_VERSION_cluster-api-provider-openshift-assisted = "1.0.0"
-CHART_APP_VERSION_cluster-api-provider-openshift-assisted = $(TAG)
-CHART_VALUES_IMAGE_TAG_cluster-api-provider-openshift-assisted = $(TAG)
-CHART_VALUES_IMAGE_TAG_PREFIX_cluster-api-provider-openshift-assisted = ""
+OPENSHIFT_ASSISTED_ORGREPO ?= https://github.com/openshift-assisted
 
-BRANCH_cluster-api-provider-metal3 = main
-CHART_VALUES_IMAGE_TAG_cluster-api-provider-metal3 = $(TAG)
-CHART_VALUES_IMAGE_TAG_PREFIX_cluster-api-provider-metal3 = ""
+get-tag-from-branch = \
+	$(strip $(if $(filter $(1),master main),latest, \
+	$(if $(findstring release-,$(1)),$(patsubst release-%,%,$(1)), \
+		$(if $(findstring backplane-,$(1)),$(patsubst backplane-%,%,$(1)),$(1)))))
+
+get-version-from-branch = \
+	$(strip $(if $(filter $(1),master main),"0.0.0-dev", \
+	$(if $(findstring release-,$(1)),$(patsubst release-%,%,$(1)), \
+		$(if $(findstring backplane-,$(1)),$(patsubst backplane-%,%,$(1)),$(1)))))
 
 WKDIR ?= ../out
 
-.PHONY: build-cluster-api-chart build-cluster-api-provider-aws-chart build-cluster-api-provider-azure-chart build-cluster-api-provider-openshift-assisted-chart
+.PHONY: build-cluster-api-chart
+build-cluster-api-chart:
+	@echo "Building cluster-api chart"
+	WKDIR="$(WKDIR)" \
+	ORGREPO="$(DEFAULT_ORGREPO)" \
+	PROJECT="cluster-api" \
+	BRANCH="$(DEFAULT_BRANCH)" \
+	../scripts/build.sh
+	BUILTDIR="$(WKDIR)/cluster-api/config/tmp" \
+	CHART_VERSION="$(OCP_VERSION)" \
+	CHART_APP_VERSION="$(OCP_VERSION)" \
+	CHART_VALUES_IMAGE_TAG="$(OCP_VERSION)" \
+	CHART_VALUES_IMAGE_TAG_PREFIX="v" \
+	SYNC2CHARTS="$(SYNC2CHARTS)" \
+	PROJECT="cluster-api" \
+	../scripts/sync2chart.sh
+
+.PHONY: build-cluster-api-provider-aws-chart
+build-cluster-api-provider-aws-chart:
+	@echo "Building cluster-api-provider-aws chart"
+	WKDIR="$(WKDIR)" \
+	ORGREPO="$(DEFAULT_ORGREPO)" \
+	PROJECT="cluster-api-provider-aws" \
+	BRANCH="$(DEFAULT_BRANCH)" \
+	../scripts/build.sh
+	BUILTDIR="$(WKDIR)/cluster-api-provider-aws/config/tmp" \
+	CHART_VERSION="$(OCP_VERSION)" \
+	CHART_APP_VERSION="$(OCP_VERSION)" \
+	CHART_VALUES_IMAGE_TAG="$(OCP_VERSION)" \
+	CHART_VALUES_IMAGE_TAG_PREFIX="v" \
+	SYNC2CHARTS="$(SYNC2CHARTS)" \
+	PROJECT="cluster-api-provider-aws" \
+	../scripts/sync2chart.sh
 
-# Define the build target for each project
-define make-chart-target
-build-$(1)-chart:
-	@echo "Building $(1) chart"
+.PHONY: build-cluster-api-provider-openshift-assisted-chart
+build-cluster-api-provider-openshift-assisted-chart:
+	$(eval TAG=$(call get-tag-from-branch, $(OPENSHIFT_ASSISTED_BRANCH)))
+	$(eval VERSION=$(call get-version-from-branch, $(OPENSHIFT_ASSISTED_BRANCH)))
+	@echo "Building cluster-api-provider-openshift-assisted-chart"
 	WKDIR="$(WKDIR)" \
-	ORGREPO="$(if $(ORGREPO_$(1)),$(ORGREPO_$(1)),$(ORGREPO))" \
-	KUSTOMIZE_CONFIG_DIRS="$(if $(KUSTOMIZE_CONFIG_DIRS_$(1)),$(KUSTOMIZE_CONFIG_DIRS_$(1)),)" \
-	PROJECT="$(1)" \
-	BRANCH="$(if $(BRANCH_$(1)),$(BRANCH_$(1)),$(BRANCH))" \
+	ORGREPO="$(OPENSHIFT_ASSISTED_ORGREPO)" \
+	KUSTOMIZE_CONFIG_DIRS="bootstrap controlplane" \
+	PROJECT="cluster-api-provider-openshift-assisted" \
+	BRANCH="$(DEFAULT_BRANCH)" \
 	../scripts/build.sh
-	BUILTDIR="$(WKDIR)/$(1)/config/tmp" \
-	CHART_VERSION="$(if $(CHART_VERSION_$(1)),$(CHART_VERSION_$(1)),$(CHART_VERSION))" \
-	CHART_APP_VERSION="$(if $(CHART_APP_VERSION_$(1)),$(CHART_APP_VERSION_$(1)),$(CHART_APP_VERSION))" \
-	CHART_VALUES_IMAGE_TAG="$(if $(CHART_VALUES_IMAGE_TAG_$(1)),$(CHART_VALUES_IMAGE_TAG_$(1)),$(CHART_VALUES_IMAGE_TAG))" \
-	CHART_VALUES_IMAGE_TAG_PREFIX="$(if $(CHART_VALUES_IMAGE_TAG_PREFIX_$(1)),$(CHART_VALUES_IMAGE_TAG_PREFIX_$(1)),$(CHART_VALUES_IMAGE_TAG_PREFIX))" \
+	BUILTDIR="$(WKDIR)/cluster-api-provider-openshift-assisted/config/tmp" \
+	CHART_VERSION="$(VERSION)" \
+	CHART_APP_VERSION="$(VERSION)" \
+	CHART_VALUES_IMAGE_TAG="$(TAG)" \
+	CHART_VALUES_IMAGE_TAG_PREFIX="" \
 	SYNC2CHARTS="$(SYNC2CHARTS)" \
-	PROJECT="$(1)" \
+	PROJECT="cluster-api-provider-openshift-assisted" \
 	../scripts/sync2chart.sh
-endef
 
-$(foreach proj,$(PROJECTS),$(eval $(call make-chart-target,$(proj))))
+.PHONY: build-cluster-api-provider-metal3-chart
+build-cluster-api-provider-metal3-chart:
+	$(eval TAG=$(call get-tag-from-branch, $(METAL3_BRANCH)))
+	@echo "Building cluster-api-provider-metal3 chart"
+	WKDIR="$(WKDIR)" \
+	ORGREPO="$(DEFAULT_ORGREPO)" \
+	PROJECT="cluster-api-provider-metal3" \
+	BRANCH="$(METAL3_BRANCH)" \
+	../scripts/build.sh
+	BUILTDIR="$(WKDIR)/cluster-api-provider-metal3/config/tmp" \
+	CHART_VERSION="$(OCP_VERSION)" \
+	CHART_APP_VERSION="$(OCP_VERSION)" \
+	CHART_VALUES_IMAGE_TAG="$(TAG)" \
+	CHART_VALUES_IMAGE_TAG_PREFIX="" \
+	SYNC2CHARTS="$(SYNC2CHARTS)" \
+	PROJECT="cluster-api-provider-metal3" \
+	../scripts/sync2chart.sh
 
 .PHONY: build
-build: $(addprefix build-,$(addsuffix -chart, $(PROJECTS)))
+build: build-cluster-api-chart build-cluster-api-provider-aws-chart build-cluster-api-azure-chart build-cluster-api-provider-metal3-chart build-cluster-api-provider-openshift-assisted-chart
 
 .PHONY: test-chart-crc
 test-chart-crc:
diff --git a/charts/cluster-api-provider-openshift-assisted/Chart.yaml b/charts/cluster-api-provider-openshift-assisted/Chart.yaml
index 1b2e5f0c..412c7599 100644
--- a/charts/cluster-api-provider-openshift-assisted/Chart.yaml
+++ b/charts/cluster-api-provider-openshift-assisted/Chart.yaml
@@ -2,5 +2,5 @@ apiVersion: v2
 name: cluster-api-provider-openshift-assisted
 description: Cluster API Bootstrap and Controlplane providers for OpenShift Assisted Installer
 type: application
-version: "1.0.0"
-appVersion: "latest"
+version: "0.0.0-dev"
+appVersion: "0.0.0-dev"


Reviews:
user: login: rccrdpccl
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-09T15:56:02Z
user: login: serngawy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-09T18:09:39Z
user: login: rccrdpccl
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-10T09:58:43Z
user: login: rccrdpccl
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-10T09:58:59Z
user: login: serngawy
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-10T13:56:46Z
user: login: serngawy
body: Looks good to me, thanks @rccrdpccl for refactoring the make file 
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-10T14:04:47Z

Review comments:
diff_hunk: @@ -37,6 +32,15 @@ WKDIR ?= ../out
 # Define the build target for each project
 define make-chart-target
 build-$(1)-chart:
+	$(eval BRANCH := $(if $(BRANCH_$(1)),$(BRANCH_$(1)),$(BRANCH)))
path: charts/Makefile
user: login: rccrdpccl
body: I think we've outgrown the Makefile approach.
This is starting to rely on Makefile quirks, which makes it very difficult to read and maintain. We have introduced two components that do not comply with the assumptions taken so far.

I guess this normally will be run with BRANCH=release-2.9 or BRANCH=master, however now it cannot be the case any longer. Overrides are supported only in-makefile, to override specific components from ENV we should improve the current solution.

For now this should work but I believe we should consider changing approach.
created_at: 2025-04-09T15:56:01Z
author_association: COLLABORATOR
diff_hunk: @@ -8,27 +8,22 @@ PROJECTS = \
 	cluster-api-provider-openshift-assisted \
 	cluster-api-provider-metal3
 
-ifeq ($(filter $(BRANCH), master main),$(BRANCH))
-	TAG := latest
-else
-	TAG := $(patsubst release-%, %,$(BRANCH))
-endif
+get-tag-from-branch = \
+  $(strip $(if $(filter $(1),master main),latest, \
+    $(if $(findstring release-,$(1)),$(patsubst release-%,%,$(1)), \
+      $(if $(findstring backplane-,$(1)),$(patsubst backplane-%,%,$(1)),$(1)))))
+
 CHART_VERSION = $(OCP_VERSION)
 CHART_APP_VERSION = $(OCP_VERSION)
 CHART_VALUES_IMAGE_TAG = $(OCP_VERSION)
 CHART_VALUES_IMAGE_TAG_PREFIX = "v"
 
-# Define specific overrides
+# define branch, repo and kustomize overrides
+BRANCH_cluster-api-provider-metal3 = main
+BRANCH_cluster-api-provider-openshift-assisted=backplane-2.9
path: charts/Makefile
user: login: serngawy
body: this will go to  cluster-api-installer main branch, so the CAPOA branch should be main/master and for  cluster-api-installer release-2.9 branch we set the CAPOA branch to backplane-2.9
created_at: 2025-04-09T17:51:41Z
author_association: COLLABORATOR
diff_hunk: @@ -37,6 +32,15 @@ WKDIR ?= ../out
 # Define the build target for each project
 define make-chart-target
 build-$(1)-chart:
+	$(eval BRANCH := $(if $(BRANCH_$(1)),$(BRANCH_$(1)),$(BRANCH)))
path: charts/Makefile
user: login: serngawy
body: In fact, I was doubting make those changes for CAPOA first PR. The work in this [PR](https://github.com/stolostron/cluster-api-installer/pull/47/files) to avoid repeating the charts make tags end up more code to write and becomes hard to follow. Can we have make tag for every chart (as it was before) and simply pass the env varaible based on the chart tag. 
created_at: 2025-04-09T18:07:29Z
author_association: COLLABORATOR
diff_hunk: @@ -37,6 +32,15 @@ WKDIR ?= ../out
 # Define the build target for each project
 define make-chart-target
 build-$(1)-chart:
+	$(eval BRANCH := $(if $(BRANCH_$(1)),$(BRANCH_$(1)),$(BRANCH)))
path: charts/Makefile
user: login: rccrdpccl
body: Reverted to a similar format of the original.
It's still an issue, as this approach it's extremely error prone, however it's now more understandable.

@serngawy how is this makefile being run? Do we expect to be able to override from env vars? Or is it always executed as "make build-helm-charts"?
created_at: 2025-04-10T09:58:42Z
author_association: COLLABORATOR
diff_hunk: @@ -8,27 +8,22 @@ PROJECTS = \
 	cluster-api-provider-openshift-assisted \
 	cluster-api-provider-metal3
 
-ifeq ($(filter $(BRANCH), master main),$(BRANCH))
-	TAG := latest
-else
-	TAG := $(patsubst release-%, %,$(BRANCH))
-endif
+get-tag-from-branch = \
+  $(strip $(if $(filter $(1),master main),latest, \
+    $(if $(findstring release-,$(1)),$(patsubst release-%,%,$(1)), \
+      $(if $(findstring backplane-,$(1)),$(patsubst backplane-%,%,$(1)),$(1)))))
+
 CHART_VERSION = $(OCP_VERSION)
 CHART_APP_VERSION = $(OCP_VERSION)
 CHART_VALUES_IMAGE_TAG = $(OCP_VERSION)
 CHART_VALUES_IMAGE_TAG_PREFIX = "v"
 
-# Define specific overrides
+# define branch, repo and kustomize overrides
+BRANCH_cluster-api-provider-metal3 = main
+BRANCH_cluster-api-provider-openshift-assisted=backplane-2.9
path: charts/Makefile
user: login: rccrdpccl
body: Gotcha. I've reverted to master, once merged, I'll patch the 2.9 branch to set the default branch for CAPOA.
created_at: 2025-04-10T09:58:58Z
author_association: COLLABORATOR
diff_hunk: @@ -37,6 +32,15 @@ WKDIR ?= ../out
 # Define the build target for each project
 define make-chart-target
 build-$(1)-chart:
+	$(eval BRANCH := $(if $(BRANCH_$(1)),$(BRANCH_$(1)),$(BRANCH)))
path: charts/Makefile
user: login: serngawy
body: Usually we run it as "make build-helm-charts" for ex; the sync job [here](https://github.com/stolostron/cluster-api-installer/blob/main/.github/workflows/sync-providers.yaml#L38) run weekly to catch any changes happen in origin repo. 
created_at: 2025-04-10T13:56:46Z
author_association: COLLABORATOR

PR comments:
user: login: rccrdpccl
created_at: 2025-04-09T16:19:33Z
body: /cc @serngawy @carbonin 
author_association: COLLABORATOR
user: login: openshift-ci[bot]
created_at: 2025-04-10T14:04:54Z
body: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/stolostron/cluster-api-installer/pull/56#" title="Author self-approved">rccrdpccl</a>*, *<a href="https://github.com/stolostron/cluster-api-installer/pull/56#pullrequestreview-2756981157" title="Approved">serngawy</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=stolostron%2Fcluster-api-installer).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/stolostron/cluster-api-installer/blob/main/OWNERS)~~ [serngawy]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
author_association: NONE