Skip to content

Commit b1609b0

Browse files
committed
zuul: support of smtp connections
Change-Id: Ibeff483f9011e01c6c79e53fdfb51a36fae8b62e
1 parent 07ab53f commit b1609b0

File tree

7 files changed

+154
-4
lines changed

7 files changed

+154
-4
lines changed

api/v1/softwarefactory_types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ type GitConnection struct {
184184
PollDelay int32 `json:"pollDelay,omitempty"`
185185
}
186186

187+
// Describes a Zuul connection using the [SMTP driver](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#connection-configuration).
188+
// When an optional parameter is not specified then Zuul's defaults apply
189+
type SMTPConnection struct {
190+
// How the connection will be named in Zuul's configuration and appear in zuul-web
191+
Name string `json:"name"`
192+
// [server](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.server)
193+
Server string `json:"server"`
194+
// [port](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.port)
195+
Port uint16 `json:"port,omitempty"`
196+
// +kubebuilder:default:="openid profile"
197+
// [default_from](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_from)
198+
DefaultFrom string `json:"defaultFrom,omitempty"`
199+
// [default_to](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_to)
200+
DefaultTo string `json:"defaultTo,omitempty"`
201+
// [user](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.user)
202+
User string `json:"user,omitempty"`
203+
// [password](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.password)
204+
Password string `json:"password,omitempty"`
205+
// [use_starttls](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.use_starttls)
206+
TLS *bool `json:"tls,omitempty"`
207+
}
208+
187209
// Describes a Zuul connection using the [ElasticSearch driver](https://zuul-ci.org/docs/zuul/latest/drivers/elasticsearch.html#connection-configuration).
188210
// When an optional parameter is not specified then Zuul's defaults apply
189211
type ElasticSearchConnection struct {
@@ -359,6 +381,8 @@ type ZuulSpec struct {
359381
PagureConns []PagureConnection `json:"pagureconns,omitempty"`
360382
// The list of ElasticSearch-based connections to add to Zuul's configuration
361383
ElasticSearchConns []ElasticSearchConnection `json:"elasticsearchconns,omitempty"`
384+
// The list of SMTP-based connections to add to Zuul's configuration
385+
SMTPConns []SMTPConnection `json:"smtpconns,omitempty"`
362386
// Configuration of the executor microservices
363387
Executor ZuulExecutorSpec `json:"executor,omitempty"`
364388
// Configuration of the scheduler microservice

api/v1/zz_generated.deepcopy.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/sf.softwarefactory-project.io_softwarefactories.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,45 @@ spec:
990990
- size
991991
type: object
992992
type: object
993+
smtpconns:
994+
description: The list of SMTP-based connections to add to Zuul's
995+
configuration
996+
items:
997+
description: |-
998+
Describes a Zuul connection using the [SMTP driver](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#connection-configuration).
999+
When an optional parameter is not specified then Zuul's defaults apply
1000+
properties:
1001+
defaultFrom:
1002+
default: openid profile
1003+
description: '[default_from](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_from)'
1004+
type: string
1005+
defaultTo:
1006+
description: '[default_to](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_to)'
1007+
type: string
1008+
name:
1009+
description: How the connection will be named in Zuul's
1010+
configuration and appear in zuul-web
1011+
type: string
1012+
password:
1013+
description: '[password](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.password)'
1014+
type: string
1015+
port:
1016+
description: '[port](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.port)'
1017+
type: integer
1018+
server:
1019+
description: '[server](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.server)'
1020+
type: string
1021+
tls:
1022+
description: '[use_starttls](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.use_starttls)'
1023+
type: boolean
1024+
user:
1025+
description: '[user](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.user)'
1026+
type: string
1027+
required:
1028+
- name
1029+
- server
1030+
type: object
1031+
type: array
9931032
web:
9941033
description: Configuration of the web microservice
9951034
properties:

controllers/zuul.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,10 @@ func (r *SFController) EnsureZuulConfigSecret(skipDBSettings bool, skipAuthSetti
940940
r.AddElasticSearchConnection(cfgINI, conn)
941941
}
942942

943+
for _, conn := range r.cr.Spec.Zuul.SMTPConns {
944+
r.AddSMTPConnection(cfgINI, conn)
945+
}
946+
943947
gitServerURL := "git://git-server/"
944948
if r.IsExternalExecutorEnabled() {
945949
gitServerURL = "git://" + r.cr.Spec.Zuul.Executor.Standalone.ControlPlanePublicGSHostname + "/"
@@ -1264,6 +1268,32 @@ func (r *SFController) AddElasticSearchConnection(cfg *ini.File, conn sfv1.Elast
12641268
}
12651269
}
12661270

1271+
func (r *SFController) AddSMTPConnection(cfg *ini.File, conn sfv1.SMTPConnection) {
1272+
section := "connection " + conn.Name
1273+
cfg.NewSection(section)
1274+
cfg.Section(section).NewKey("driver", "smtp")
1275+
cfg.Section(section).NewKey("server", conn.Server)
1276+
// Optional fields (set as omitempty in SMTPConnection struct definition)
1277+
if conn.Port > 0 {
1278+
cfg.Section(section).NewKey("port", strconv.Itoa(int(conn.Port)))
1279+
}
1280+
if conn.DefaultFrom != "" {
1281+
cfg.Section(section).NewKey("default_from", conn.DefaultFrom)
1282+
}
1283+
if conn.DefaultTo != "" {
1284+
cfg.Section(section).NewKey("default_to", conn.DefaultTo)
1285+
}
1286+
if conn.User != "" {
1287+
cfg.Section(section).NewKey("user", conn.User)
1288+
}
1289+
if conn.Password != "" {
1290+
cfg.Section(section).NewKey("password", conn.Password)
1291+
}
1292+
if conn.TLS != nil && !*conn.TLS {
1293+
cfg.Section(section).NewKey("use_starttls", "false")
1294+
}
1295+
}
1296+
12671297
func AddWebClientSection(cfg *ini.File) {
12681298
section := "webclient"
12691299
cfg.NewSection(section)

doc/reference/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ All notable changes to this project will be documented in this file.
44
## [in development]
55

66
### Added
7+
8+
- zuul: support of the SMTP connection
9+
710
### Changed
811
### Deprecated
912
### Removed
1013
### Fixed
11-
12-
- zuul connections / elasticsearch - ensure ca_certs setting is set by default to system CA bundle
13-
1414
### Security
1515

1616
## [v0.0.36] - 2024-08-14

doc/reference/api/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,28 @@ _Appears in:_
333333
| `sourceWhitelist` _string_ | the [sourceWhitelist](https://zuul-ci.org/docs/zuul/latest/drivers/pagure.html#attr-<pagure connection>.source_whitelist) | -|
334334

335335

336+
#### SMTPConnection
337+
338+
339+
340+
Describes a Zuul connection using the [SMTP driver](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#connection-configuration).
341+
When an optional parameter is not specified then Zuul's defaults apply
342+
343+
_Appears in:_
344+
- [ZuulSpec](#zuulspec)
345+
346+
| Field | Description | Default Value |
347+
| --- | --- | --- |
348+
| `name` _string_ | How the connection will be named in Zuul's configuration and appear in zuul-web | -|
349+
| `server` _string_ | [server](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.server) | -|
350+
| `port` _integer_ | [port](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.port) | -|
351+
| `defaultFrom` _string_ | [default_from](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_from) | {openid profile}|
352+
| `defaultTo` _string_ | [default_to](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.default_to) | -|
353+
| `user` _string_ | [user](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.user) | -|
354+
| `password` _string_ | [password](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.password) | -|
355+
| `tls` _boolean_ | [use_starttls](https://zuul-ci.org/docs/zuul/latest/drivers/smtp.html#attr-%3Csmtp%20connection%3E.use_starttls) | -|
356+
357+
336358
#### Secret
337359

338360

@@ -563,6 +585,7 @@ _Appears in:_
563585
| `gitconns` _[GitConnection](#gitconnection) array_ | The list of Git-based connections to add to Zuul's configuration | -|
564586
| `pagureconns` _[PagureConnection](#pagureconnection) array_ | The list of Pagure-based connections to add to Zuul's configuration | -|
565587
| `elasticsearchconns` _[ElasticSearchConnection](#elasticsearchconnection) array_ | The list of ElasticSearch-based connections to add to Zuul's configuration | -|
588+
| `smtpconns` _[SMTPConnection](#smtpconnection) array_ | The list of SMTP-based connections to add to Zuul's configuration | -|
566589
| `executor` _[ZuulExecutorSpec](#zuulexecutorspec)_ | Configuration of the executor microservices | -|
567590
| `scheduler` _[ZuulSchedulerSpec](#zuulschedulerspec)_ | Configuration of the scheduler microservice | -|
568591
| `web` _[ZuulWebSpec](#zuulwebspec)_ | Configuration of the web microservice | -|

roles/health-check/zuul-connections/tasks/main.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
dummy_pagureconns:
2828
- name: dummy-pagure-conn
2929
secrets: pagureconnectionsecret
30+
dummy_smtpconns:
31+
- name: dummy-smtp-conn
32+
server: smtp.domain.com
3033

3134
- name: Create Gerrit Connection Secret
3235
kubernetes.core.k8s:
@@ -105,6 +108,7 @@
105108
gitconns: "{{ dummy_gitconns }}"
106109
elasticsearchconns: "{{ dummy_elasticsearchconns }}"
107110
pagureconns: "{{ dummy_pagureconns }}"
111+
smtpconns: "{{ dummy_smtpconns }}"
108112

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

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

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

0 commit comments

Comments
 (0)