Skip to content

Commit

Permalink
zuul: support of smtp connections
Browse files Browse the repository at this point in the history
Change-Id: Ibeff483f9011e01c6c79e53fdfb51a36fae8b62e
  • Loading branch information
morucci committed Aug 16, 2024
1 parent 07ab53f commit b1609b0
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 4 deletions.
24 changes: 24 additions & 0 deletions api/v1/softwarefactory_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ type GitConnection struct {
PollDelay int32 `json:"pollDelay,omitempty"`
}

// Describes a Zuul connection using the [SMTP driver](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#connection-configuration).
// When an optional parameter is not specified then Zuul's defaults apply
type SMTPConnection struct {
// How the connection will be named in Zuul's configuration and appear in zuul-web
Name string `json:"name"`
// [server](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.server)
Server string `json:"server"`
// [port](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.port)
Port uint16 `json:"port,omitempty"`
// +kubebuilder:default:="openid profile"
// [default_from](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_from)
DefaultFrom string `json:"defaultFrom,omitempty"`
// [default_to](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_to)
DefaultTo string `json:"defaultTo,omitempty"`
// [user](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.user)
User string `json:"user,omitempty"`
// [password](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.password)
Password string `json:"password,omitempty"`
// [use_starttls](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.use_starttls)
TLS *bool `json:"tls,omitempty"`
}

// Describes a Zuul connection using the [ElasticSearch driver](https://zuul-ci.org/docs/zuul/latest/drivers/elasticsearch.html#connection-configuration).
// When an optional parameter is not specified then Zuul's defaults apply
type ElasticSearchConnection struct {
Expand Down Expand Up @@ -359,6 +381,8 @@ type ZuulSpec struct {
PagureConns []PagureConnection `json:"pagureconns,omitempty"`
// The list of ElasticSearch-based connections to add to Zuul's configuration
ElasticSearchConns []ElasticSearchConnection `json:"elasticsearchconns,omitempty"`
// The list of SMTP-based connections to add to Zuul's configuration
SMTPConns []SMTPConnection `json:"smtpconns,omitempty"`
// Configuration of the executor microservices
Executor ZuulExecutorSpec `json:"executor,omitempty"`
// Configuration of the scheduler microservice
Expand Down
27 changes: 27 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,45 @@ spec:
- size
type: object
type: object
smtpconns:
description: The list of SMTP-based connections to add to Zuul's
configuration
items:
description: |-
Describes a Zuul connection using the [SMTP driver](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#connection-configuration).
When an optional parameter is not specified then Zuul's defaults apply
properties:
defaultFrom:
default: openid profile
description: '[default_from](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_from)'
type: string
defaultTo:
description: '[default_to](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_to)'
type: string
name:
description: How the connection will be named in Zuul's
configuration and appear in zuul-web
type: string
password:
description: '[password](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.password)'
type: string
port:
description: '[port](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.port)'
type: integer
server:
description: '[server](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.server)'
type: string
tls:
description: '[use_starttls](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.use_starttls)'
type: boolean
user:
description: '[user](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.user)'
type: string
required:
- name
- server
type: object
type: array
web:
description: Configuration of the web microservice
properties:
Expand Down
30 changes: 30 additions & 0 deletions controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,10 @@ func (r *SFController) EnsureZuulConfigSecret(skipDBSettings bool, skipAuthSetti
r.AddElasticSearchConnection(cfgINI, conn)
}

for _, conn := range r.cr.Spec.Zuul.SMTPConns {
r.AddSMTPConnection(cfgINI, conn)
}

gitServerURL := "git://git-server/"
if r.IsExternalExecutorEnabled() {
gitServerURL = "git://" + r.cr.Spec.Zuul.Executor.Standalone.ControlPlanePublicGSHostname + "/"
Expand Down Expand Up @@ -1264,6 +1268,32 @@ func (r *SFController) AddElasticSearchConnection(cfg *ini.File, conn sfv1.Elast
}
}

func (r *SFController) AddSMTPConnection(cfg *ini.File, conn sfv1.SMTPConnection) {
section := "connection " + conn.Name
cfg.NewSection(section)
cfg.Section(section).NewKey("driver", "smtp")
cfg.Section(section).NewKey("server", conn.Server)
// Optional fields (set as omitempty in SMTPConnection struct definition)
if conn.Port > 0 {
cfg.Section(section).NewKey("port", strconv.Itoa(int(conn.Port)))
}
if conn.DefaultFrom != "" {
cfg.Section(section).NewKey("default_from", conn.DefaultFrom)
}
if conn.DefaultTo != "" {
cfg.Section(section).NewKey("default_to", conn.DefaultTo)
}
if conn.User != "" {
cfg.Section(section).NewKey("user", conn.User)
}
if conn.Password != "" {
cfg.Section(section).NewKey("password", conn.Password)
}
if conn.TLS != nil && !*conn.TLS {
cfg.Section(section).NewKey("use_starttls", "false")
}
}

func AddWebClientSection(cfg *ini.File) {
section := "webclient"
cfg.NewSection(section)
Expand Down
6 changes: 3 additions & 3 deletions doc/reference/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ All notable changes to this project will be documented in this file.
## [in development]

### Added

- zuul: support of the SMTP connection

### Changed
### Deprecated
### Removed
### Fixed

- zuul connections / elasticsearch - ensure ca_certs setting is set by default to system CA bundle

### Security

## [v0.0.36] - 2024-08-14
Expand Down
23 changes: 23 additions & 0 deletions doc/reference/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,28 @@ _Appears in:_
| `sourceWhitelist` _string_ | the [sourceWhitelist](https://zuul-ci.org/docs/zuul/latest/drivers/pagure.html#attr-<pagure connection>.source_whitelist) | -|


#### SMTPConnection



Describes a Zuul connection using the [SMTP driver](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#connection-configuration).
When an optional parameter is not specified then Zuul's defaults apply

_Appears in:_
- [ZuulSpec](#zuulspec)

| Field | Description | Default Value |
| --- | --- | --- |
| `name` _string_ | How the connection will be named in Zuul's configuration and appear in zuul-web | -|
| `server` _string_ | [server](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.server) | -|
| `port` _integer_ | [port](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.port) | -|
| `defaultFrom` _string_ | [default_from](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_from) | {openid profile}|
| `defaultTo` _string_ | [default_to](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_to) | -|
| `user` _string_ | [user](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.user) | -|
| `password` _string_ | [password](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.password) | -|
| `tls` _boolean_ | [use_starttls](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.use_starttls) | -|


#### Secret


Expand Down Expand Up @@ -563,6 +585,7 @@ _Appears in:_
| `gitconns` _[GitConnection](#gitconnection) array_ | The list of Git-based connections to add to Zuul's configuration | -|
| `pagureconns` _[PagureConnection](#pagureconnection) array_ | The list of Pagure-based connections to add to Zuul's configuration | -|
| `elasticsearchconns` _[ElasticSearchConnection](#elasticsearchconnection) array_ | The list of ElasticSearch-based connections to add to Zuul's configuration | -|
| `smtpconns` _[SMTPConnection](#smtpconnection) array_ | The list of SMTP-based connections to add to Zuul's configuration | -|
| `executor` _[ZuulExecutorSpec](#zuulexecutorspec)_ | Configuration of the executor microservices | -|
| `scheduler` _[ZuulSchedulerSpec](#zuulschedulerspec)_ | Configuration of the scheduler microservice | -|
| `web` _[ZuulWebSpec](#zuulwebspec)_ | Configuration of the web microservice | -|
Expand Down
9 changes: 8 additions & 1 deletion roles/health-check/zuul-connections/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
dummy_pagureconns:
- name: dummy-pagure-conn
secrets: pagureconnectionsecret
dummy_smtpconns:
- name: dummy-smtp-conn
server: smtp.domain.com

- name: Create Gerrit Connection Secret
kubernetes.core.k8s:
Expand Down Expand Up @@ -105,6 +108,7 @@
gitconns: "{{ dummy_gitconns }}"
elasticsearchconns: "{{ dummy_elasticsearchconns }}"
pagureconns: "{{ dummy_pagureconns }}"
smtpconns: "{{ dummy_smtpconns }}"

- name: Wait for the new Zuul connections to appear in the Zuul API
ansible.builtin.uri:
Expand All @@ -124,11 +128,12 @@
retries: "{{ zuul_api_retries }}"
delay: "{{ zuul_api_delay }}"

# For non SourceInterface connection such as elasticsearch (which does not appear in the Zuul API connections endpoint)
# For non SourceInterface connection such as elasticsearch and smtp (which does not appear in the Zuul API connections endpoint)
# we, at least, check zuul.conf to ensure the connection is defined in the Zuul config
- name: Ensure the new Zuul connections (non SourceInterface) exist in the scheduler's zuul.conf
ansible.builtin.shell: |
kubectl exec zuul-scheduler-0 -- grep "dummy-elasticsearch-conn" /etc/zuul/zuul.conf
kubectl exec zuul-scheduler-0 -- grep "dummy-smtp-conn" /etc/zuul/zuul.conf
- name: Ensure the new Zuul dummy gerrit secret exist in the scheduler's zuul.conf
ansible.builtin.shell: |
Expand All @@ -148,6 +153,7 @@
gitconns: []
elasticsearchconns: []
pagureconns: []
smtpconns: []

- name: Wait for the dummy Zuul connections to be removed from the API
ansible.builtin.uri:
Expand All @@ -172,6 +178,7 @@
- name: Ensure the new Zuul connections (non SourceInterface) no longer exist in the scheduler's zuul.conf
ansible.builtin.shell: |
kubectl exec zuul-scheduler-0 -- grep "dummy-elasticsearch-conn" /etc/zuul/zuul.conf
kubectl exec zuul-scheduler-0 -- grep "dummy-smtp-conn" /etc/zuul/zuul.conf
register: grep_result
failed_when: grep_result is success

Expand Down

0 comments on commit b1609b0

Please sign in to comment.