From 7731971306735b3848215a2bf5dab028a96fb33c Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Tue, 10 Sep 2024 10:21:58 -0400 Subject: [PATCH] config: add support for setting up a custom branch name This change enables loading config repository with a non default git branch. Default to 'main'. Change-Id: I4563f74b30060a515544b724cd64951eb0246e98 --- api/v1/softwarefactory_types.go | 2 ++ .../sf.softwarefactory-project.io_softwarefactories.yaml | 4 ++++ controllers/static/zuul/generate-tenant-config.sh | 5 +++-- controllers/zuul.go | 9 ++++++++- doc/reference/CHANGELOG.md | 1 + doc/reference/api/index.md | 1 + 6 files changed, 19 insertions(+), 3 deletions(-) mode change 100644 => 100755 controllers/static/zuul/generate-tenant-config.sh diff --git a/api/v1/softwarefactory_types.go b/api/v1/softwarefactory_types.go index 5d94332..fcde3b4 100644 --- a/api/v1/softwarefactory_types.go +++ b/api/v1/softwarefactory_types.go @@ -67,6 +67,8 @@ type ConfigRepositoryLocationSpec struct { // The name of the `config` repository. This value is appended to `base-url` to clone the repository // +kubebuilder:validation:MinLength:=1 Name string `json:"name"` + // The branch of the `config` repository. This value is set to the load-branch. + Branch string `json:"branch,omitempty"` // Name of the Zuul connection through which Zuul can handle git events on the config repository // +kubebuilder:validation:MinLength:=1 ZuulConnectionName string `json:"zuul-connection-name"` diff --git a/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml b/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml index c6fbe25..4fd72fc 100644 --- a/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml +++ b/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml @@ -84,6 +84,10 @@ spec: Base URL would be `https://github.com//` pattern: ^https?:\/\/.+$ type: string + branch: + description: The branch of the `config` repository. This value + is set to the load-branch. + type: string k8s-api-url: description: |- Public URL of the k8s cluster API. This is useful when running zuul executors outside diff --git a/controllers/static/zuul/generate-tenant-config.sh b/controllers/static/zuul/generate-tenant-config.sh old mode 100644 new mode 100755 index 16682b0..8f76ff7 --- a/controllers/static/zuul/generate-tenant-config.sh +++ b/controllers/static/zuul/generate-tenant-config.sh @@ -32,7 +32,8 @@ if [ "$CONFIG_REPO_SET" == "TRUE" ]; then cat << EOF >> ~/main.yaml ${CONFIG_REPO_CONNECTION_NAME}: config-projects: - - ${CONFIG_REPO_NAME} + - ${CONFIG_REPO_NAME}: + load-branch: ${CONFIG_REPO_BRANCH} EOF # Append the config repo provided tenant file to the default one @@ -44,4 +45,4 @@ fi echo "Generated tenants config:" echo -cat ~/main.yaml \ No newline at end of file +cat ~/main.yaml diff --git a/controllers/zuul.go b/controllers/zuul.go index c34d140..0d02044 100644 --- a/controllers/zuul.go +++ b/controllers/zuul.go @@ -335,11 +335,17 @@ func mkZuulVolumes(service string, r *SFController, corporateCMExists bool) []ap func (r *SFController) getTenantsEnvs() []apiv1.EnvVar { if r.isConfigRepoSet() { + branch := r.cr.Spec.ConfigRepositoryLocation.Branch + if branch == "" { + // Default to "main" when not set + branch = "main" + } return []apiv1.EnvVar{ base.MkEnvVar("CONFIG_REPO_SET", "TRUE"), base.MkEnvVar("CONFIG_REPO_BASE_URL", strings.TrimSuffix(r.cr.Spec.ConfigRepositoryLocation.BaseURL, "/")), base.MkEnvVar("CONFIG_REPO_NAME", r.cr.Spec.ConfigRepositoryLocation.Name), base.MkEnvVar("CONFIG_REPO_CONNECTION_NAME", r.cr.Spec.ConfigRepositoryLocation.ZuulConnectionName), + base.MkEnvVar("CONFIG_REPO_BRANCH", branch), } } else { return []apiv1.EnvVar{ @@ -442,7 +448,8 @@ func (r *SFController) EnsureZuulScheduler(cfg *ini.File) bool { if r.isConfigRepoSet() { annotations["config-repo-info-hash"] = r.cr.Spec.ConfigRepositoryLocation.ZuulConnectionName + ":" + r.cr.Spec.ConfigRepositoryLocation.BaseURL + - r.cr.Spec.ConfigRepositoryLocation.Name + r.cr.Spec.ConfigRepositoryLocation.Name + + r.cr.Spec.ConfigRepositoryLocation.Branch } var relayAddress *string diff --git a/doc/reference/CHANGELOG.md b/doc/reference/CHANGELOG.md index 08e2ad0..7b4796a 100644 --- a/doc/reference/CHANGELOG.md +++ b/doc/reference/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Added - zuul: add corporate certs to zuul-web +- crd: add new `branch` for the config location. ### Removed ### Changed diff --git a/doc/reference/api/index.md b/doc/reference/api/index.md index 0b1bb54..92469d5 100644 --- a/doc/reference/api/index.md +++ b/doc/reference/api/index.md @@ -47,6 +47,7 @@ _Appears in:_ | --- | --- | --- | | `base-url` _string_ | Base URL to use to perform git-related actions on the config repository. For example, if hosted on GitHub, the Base URL would be `https://github.com//` | -| | `name` _string_ | The name of the `config` repository. This value is appended to `base-url` to clone the repository | -| +| `branch` _string_ | The branch of the `config` repository. This value is set to the load-branch. | -| | `zuul-connection-name` _string_ | Name of the Zuul connection through which Zuul can handle git events on the config repository | -| | `k8s-api-url` _string_ | Public URL of the k8s cluster API. This is useful when running zuul executors outside

of the cluster. This is mainly used for config-update secret generation | -| | `logserver-host` _string_ | Public HOST of the default logserver. This is useful when running zuul executors outside

of the cluster. This is mainly used for config-update secret generation | -|