Skip to content

Commit 2408d13

Browse files
authored
Merge pull request #90 from cybertec-postgresql/multisite-certs
Add certificate secret capability for multisite etcd configuration
2 parents 509ebff + 3189c1d commit 2408d13

File tree

13 files changed

+149
-25
lines changed

13 files changed

+149
-25
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@ spec:
698698
type: string
699699
protocol:
700700
type: string
701+
certSecretName:
702+
type: string
701703
ttl:
702704
type: integer
703705
retry_timeout:

charts/postgres-operator/crds/postgresqls.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ spec:
500500
type: string
501501
protocol:
502502
type: string
503+
certSecretName:
504+
type: string
503505
ttl:
504506
type: integer
505507
retry_timeout:

charts/postgres-operator/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ configMultisite:
445445
user: ""
446446
password: ""
447447
protocol: http
448+
# certSecretName: ..
448449
# Timeout for cross site failover, and timeout for demoting to read only when accessing shared etcd cluster fails.
449450
# There should be adequate safety margin between the two to allow for demotion to take place.
450451
#ttl: 90

docs/hugo/content/en/crd/crd-postgresql.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,13 @@ key, operator, value, effect and tolerationSeconds |
361361

362362
#### etcd
363363

364-
| Name | Type | required | Description |
365-
| ------------------------------ |:-------:| ---------:| ------------------:|
366-
| hosts | string | true | list of etcd hosts, including etcd-client-port (default: `2379`), comma separated like in the etcd config |
367-
| password | string | false | Password for the global etcd |
368-
| protocol | string | true | Protocol for the global etcd (http or https) |
369-
| user | string | false | Username for the global etcd |
364+
| Name | Type | required | Description |
365+
|----------------|:------:|---------:|----------------------------------------------------------------------------------------------------------:|
366+
| hosts | string | true | list of etcd hosts, including etcd-client-port (default: `2379`), comma separated like in the etcd config |
367+
| password | string | false | Password for the global etcd |
368+
| protocol | string | true | Protocol for the global etcd (http or https) |
369+
| user | string | false | Username for the global etcd |
370+
| certSecretName | string | false | Secret for client certificates (tls.crt/key) and server certificate validation (ca.crt) |
370371

371372
{{< back >}}
372373

manifests/operatorconfiguration.crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ spec:
696696
type: string
697697
protocol:
698698
type: string
699+
certSecretName:
700+
type: string
699701
ttl:
700702
type: integer
701703
retry_timeout:

manifests/postgresql.crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ spec:
498498
type: string
499499
protocol:
500500
type: string
501+
certSecretName:
502+
type: string
501503
ttl:
502504
type: integer
503505
retry_timeout:

pkg/apis/cpo.opensource.cybertec.at/v1/crds.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,9 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
658658
"protocol": {
659659
Type: "string",
660660
},
661+
"certSecretName": {
662+
Type: "string",
663+
},
661664
},
662665
},
663666
"ttl": {
@@ -2307,14 +2310,25 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
23072310
"site": {
23082311
Type: "string",
23092312
},
2310-
"etcd_host": {
2311-
Type: "string",
2312-
},
2313-
"etcd_user": {
2314-
Type: "string",
2315-
},
2316-
"etcd_password": {
2317-
Type: "string",
2313+
"etcd": {
2314+
Type: "object",
2315+
Properties: map[string]apiextv1.JSONSchemaProps{
2316+
"hosts": {
2317+
Type: "string",
2318+
},
2319+
"user": {
2320+
Type: "string",
2321+
},
2322+
"password": {
2323+
Type: "string",
2324+
},
2325+
"protocol": {
2326+
Type: "string",
2327+
},
2328+
"certSecretName": {
2329+
Type: "string",
2330+
},
2331+
},
23182332
},
23192333
"ttl": {
23202334
Type: "integer",

pkg/apis/cpo.opensource.cybertec.at/v1/postgresql_type.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,9 @@ type Multisite struct {
332332
}
333333

334334
type EtcdConfig struct {
335-
Hosts *string `json:"hosts,omitempty"`
336-
User *string `json:"user,omitempty"`
337-
Password *string `json:"password,omitempty"`
338-
Protocol *string `json:"protocol,omitempty"`
335+
Hosts *string `json:"hosts,omitempty"`
336+
User *string `json:"user,omitempty"`
337+
Password *string `json:"password,omitempty"`
338+
Protocol *string `json:"protocol,omitempty"`
339+
CertSecretName *string `json:"certSecretName,omitempty"`
339340
}

pkg/apis/cpo.opensource.cybertec.at/v1/zz_generated.deepcopy.go

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

pkg/cluster/cluster.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package cluster
44

55
import (
66
"context"
7+
"crypto/tls"
78
"database/sql"
89
"encoding/base64"
910
"encoding/json"
@@ -2015,11 +2016,22 @@ func (c *Cluster) getPasswordForUser(username string) (string, error) {
20152016
util.CoalesceStrPtr(msSpec.Etcd.Hosts, c.OpConfig.Multisite.Etcd.Hosts),
20162017
util.CoalesceStrPtr(msSpec.Etcd.Protocol, c.OpConfig.Multisite.Etcd.Protocol),
20172018
)
2019+
certSecretName := util.CoalesceStrPtr(msSpec.Etcd.CertSecretName, c.OpConfig.Multisite.Etcd.CertSecretName)
2020+
var tlsConfig *tls.Config
2021+
if certSecretName != "" {
2022+
var err error
2023+
tlsConfig, err = c.getTlsConfigFromCertSecret(certSecretName)
2024+
if err != nil {
2025+
return "", err
2026+
}
2027+
}
2028+
20182029
client, err := clientv3.New(clientv3.Config{
20192030
Endpoints: endpoints,
20202031
Username: util.CoalesceStrPtr(msSpec.Etcd.User, c.OpConfig.Multisite.Etcd.User),
20212032
Password: util.CoalesceStrPtr(msSpec.Etcd.Password, c.OpConfig.Multisite.Etcd.Password),
20222033
DialTimeout: time.Duration(2) * time.Second,
2034+
TLS: tlsConfig,
20232035
})
20242036
if err != nil {
20252037
return "", fmt.Errorf("unable to access multisite etcd: %s", err)

0 commit comments

Comments
 (0)