From 1555f58092f32616649c2c937f74485d7498cf86 Mon Sep 17 00:00:00 2001 From: Fabien Boucher Date: Thu, 26 Oct 2023 16:24:59 +0000 Subject: [PATCH] zuul - gerrit conn - let Zuul handles default values Change-Id: Ic794652b6464fa97f5acc22556f100e59b0076ea --- api/v1/softwarefactory_types.go | 7 +++---- ...arefactory-project.io_softwarefactories.yaml | 8 ++++---- controllers/zuul.go | 17 +++++++++++++---- doc/reference/api/index.md | 10 +++++----- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/api/v1/softwarefactory_types.go b/api/v1/softwarefactory_types.go index 652cc475..e97b05d4 100644 --- a/api/v1/softwarefactory_types.go +++ b/api/v1/softwarefactory_types.go @@ -81,29 +81,28 @@ type GitHubConnection struct { } // Describes a Zuul connection using the [gerrit driver](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#connection-configuration) +// When an optional parameter is not specified then Zuul's defaults apply type GerritConnection struct { // How the connection will be named in Zuul's configuration and appear in zuul-web Name string `json:"name"` // The gerrit server hostname. Equivalent to the [server](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.server) parameter. Hostname string `json:"hostname"` // SSH port number to the Gerrit instance. Equivalent to the [port](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.port) parameter. - // +kubebuilder:default:=29418 + // +kubebuilder:validation:Minimum:=1024 + // +kubebuilder:validation:Maximum:=65535 Port uint16 `json:"port,omitempty"` // URL to Gerrit's web interface. the [baseurl](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.baseurl) parameter. // +kubebuilder:validation:Pattern:=`^https?:\/\/.+$` Puburl string `json:"puburl,omitempty"` // Username that Zuul will use to authenticate on the Gerrit instance. Equivalent to the [user](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.user) parameter. - // +kubebuilder:default:=zuul Username string `json:"username,omitempty"` // The canonical hostname associated with the git repositories on the Gerrit server. Equivalent to the [canonical_hostname](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.canonical_hostname) parameter. Canonicalhostname string `json:"canonicalhostname,omitempty"` // The name of a Kubernetes secret holding the Gerrit user's API Password. The secret's data must have a key called "password". Equivalent to the [password](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.password) parameter. Password string `json:"password,omitempty"` // Set to true to force git operations over SSH even if the password attribute is set. Equivalent to the [git_over_ssh](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.git_over_ssh) parameter. - // +kubebuilder:default:=false GitOverSSH bool `json:"git-over-ssh,omitempty"` // Disable SSL certificate verification with the Gerrit instance when set to false. Equivalent to the [verify_ssl](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.verify_ssl) parameter. - // +kubebuilder:default:=true VerifySSL bool `json:"verifyssl,omitempty"` } diff --git a/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml b/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml index 7d2d574a..d9ed7bd5 100644 --- a/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml +++ b/config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml @@ -329,6 +329,8 @@ spec: configuration items: description: Describes a Zuul connection using the [gerrit driver](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#connection-configuration) + When an optional parameter is not specified then Zuul's defaults + apply properties: canonicalhostname: description: The canonical hostname associated with the @@ -337,7 +339,6 @@ spec: parameter. type: string git-over-ssh: - default: false description: Set to true to force git operations over SSH even if the password attribute is set. Equivalent to the [git_over_ssh](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.git_over_ssh) @@ -359,10 +360,11 @@ spec: parameter. type: string port: - default: 29418 description: SSH port number to the Gerrit instance. Equivalent to the [port](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.port) parameter. + maximum: 65535 + minimum: 1024 type: integer puburl: description: URL to Gerrit's web interface. the [baseurl](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.baseurl) @@ -370,13 +372,11 @@ spec: pattern: ^https?:\/\/.+$ type: string username: - default: zuul description: Username that Zuul will use to authenticate on the Gerrit instance. Equivalent to the [user](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.user) parameter. type: string verifyssl: - default: true description: Disable SSL certificate verification with the Gerrit instance when set to false. Equivalent to the [verify_ssl](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.verify_ssl) parameter. diff --git a/controllers/zuul.go b/controllers/zuul.go index a1eadeae..b2faa0ce 100644 --- a/controllers/zuul.go +++ b/controllers/zuul.go @@ -704,8 +704,12 @@ func (r *SFController) AddGerritConnection(cfg *ini.File, conn sfv1.GerritConnec cfg.Section(section).NewKey("sshkey", "/var/lib/zuul-ssh/..data/priv") cfg.Section(section).NewKey("gitweb_url_template", "{baseurl}/plugins/gitiles/{project.name}/+/{sha}^!/") // Optional fields (set as omitempty in GerritConnection struct definition) - cfg.Section(section).NewKey("user", conn.Username) - cfg.Section(section).NewKey("port", strconv.Itoa(int(conn.Port))) + if conn.Username != "" { + cfg.Section(section).NewKey("user", conn.Username) + } + if conn.Port > 0 { + cfg.Section(section).NewKey("port", strconv.Itoa(int(conn.Port))) + } if conn.Puburl != "" { cfg.Section(section).NewKey("baseurl", conn.Puburl) } @@ -716,8 +720,13 @@ func (r *SFController) AddGerritConnection(cfg *ini.File, conn sfv1.GerritConnec if conn.Canonicalhostname != "" { cfg.Section(section).NewKey("canonical_hostname", conn.Canonicalhostname) } - cfg.Section(section).NewKey("verify_ssl", strconv.FormatBool(conn.VerifySSL)) - cfg.Section(section).NewKey("git_over_ssh", strconv.FormatBool(conn.GitOverSSH)) + if !conn.VerifySSL { + // Zuul default is true, so set that setting only when VerifySSL is disabled + cfg.Section(section).NewKey("verify_ssl", "false") + } + if conn.GitOverSSH { + cfg.Section(section).NewKey("git_over_ssh", "true") + } } func (r *SFController) AddGitHubConnection(cfg *ini.File, conn sfv1.GitHubConnection) error { diff --git a/doc/reference/api/index.md b/doc/reference/api/index.md index cd75e65e..2996e517 100644 --- a/doc/reference/api/index.md +++ b/doc/reference/api/index.md @@ -38,7 +38,7 @@ _Appears in:_ -Describes a Zuul connection using the [gerrit driver](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#connection-configuration) +Describes a Zuul connection using the [gerrit driver](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#connection-configuration) When an optional parameter is not specified then Zuul's defaults apply _Appears in:_ - [ZuulSpec](#zuulspec) @@ -47,13 +47,13 @@ _Appears in:_ | --- | --- | --- | | `name` _string_ | How the connection will be named in Zuul's configuration and appear in zuul-web | -| | `hostname` _string_ | The gerrit server hostname. Equivalent to the [server](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.server) parameter. | -| -| `port` _integer_ | SSH port number to the Gerrit instance. Equivalent to the [port](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.port) parameter. | {29418}| +| `port` _integer_ | SSH port number to the Gerrit instance. Equivalent to the [port](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.port) parameter. | -| | `puburl` _string_ | URL to Gerrit's web interface. the [baseurl](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.baseurl) parameter. | -| -| `username` _string_ | Username that Zuul will use to authenticate on the Gerrit instance. Equivalent to the [user](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.user) parameter. | {zuul}| +| `username` _string_ | Username that Zuul will use to authenticate on the Gerrit instance. Equivalent to the [user](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.user) parameter. | -| | `canonicalhostname` _string_ | The canonical hostname associated with the git repositories on the Gerrit server. Equivalent to the [canonical_hostname](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20connection%3E.canonical_hostname) parameter. | -| | `password` _string_ | The name of a Kubernetes secret holding the Gerrit user's API Password. The secret's data must have a key called "password". Equivalent to the [password](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.password) parameter. | -| -| `git-over-ssh` _boolean_ | Set to true to force git operations over SSH even if the password attribute is set. Equivalent to the [git_over_ssh](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.git_over_ssh) parameter. | {false}| -| `verifyssl` _boolean_ | Disable SSL certificate verification with the Gerrit instance when set to false. Equivalent to the [verify_ssl](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.verify_ssl) parameter. | {true}| +| `git-over-ssh` _boolean_ | Set to true to force git operations over SSH even if the password attribute is set. Equivalent to the [git_over_ssh](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.git_over_ssh) parameter. | -| +| `verifyssl` _boolean_ | Disable SSL certificate verification with the Gerrit instance when set to false. Equivalent to the [verify_ssl](https://zuul-ci.org/docs/zuul/latest/drivers/gerrit.html#attr-%3Cgerrit%20ssh%20connection%3E.verify_ssl) parameter. | -| #### GitHubConnection