Skip to content

Commit

Permalink
zuul - gerrit conn - let Zuul handles default values
Browse files Browse the repository at this point in the history
Change-Id: Ic794652b6464fa97f5acc22556f100e59b0076ea
  • Loading branch information
morucci committed Oct 27, 2023
1 parent 24d0cd7 commit 1555f58
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
7 changes: 3 additions & 4 deletions api/v1/softwarefactory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -359,24 +360,23 @@ 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)
parameter.
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.
Expand Down
17 changes: 13 additions & 4 deletions controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions doc/reference/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 1555f58

Please sign in to comment.