Skip to content

Commit

Permalink
config: add support for setting up a custom branch name
Browse files Browse the repository at this point in the history
This change enables loading config repository with a non default
git branch. Default to 'main'.

Change-Id: I4563f74b30060a515544b724cd64951eb0246e98
  • Loading branch information
TristanCacqueray authored and morucci committed Sep 11, 2024
1 parent 05499d0 commit 7731971
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api/v1/softwarefactory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ spec:
Base URL would be `https://github.com/<username>/`
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
Expand Down
5 changes: 3 additions & 2 deletions controllers/static/zuul/generate-tenant-config.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,4 +45,4 @@ fi

echo "Generated tenants config:"
echo
cat ~/main.yaml
cat ~/main.yaml
9 changes: 8 additions & 1 deletion controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions doc/reference/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions doc/reference/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<username>/` | -|
| `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<br /><br />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<br /><br />of the cluster. This is mainly used for config-update secret generation | -|
Expand Down

0 comments on commit 7731971

Please sign in to comment.