Skip to content

Commit ebda393

Browse files
knan-nrksdudoladov
authored andcommitted
database.go: remove hardcoded .svc.cluster.local dns suffix (#561)
* database.go: substitute hardcoded .svc.cluster.local dns suffix with config parameter Use the pod's configured dns search path, for clusters where .svc.cluster.local is not correct.
1 parent 3ffc8ac commit ebda393

File tree

9 files changed

+18
-1
lines changed

9 files changed

+18
-1
lines changed

charts/postgres-operator/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config:
2323
workers: "4"
2424
docker_image: registry.opensource.zalan.do/acid/spilo-cdp-11:1.5-p70
2525
secret_name_template: '{username}.{cluster}.credentials'
26+
cluster_domain: cluster.local
2627
super_username: postgres
2728
enable_teams_api: "false"
2829
spilo_privileged: "false"

docs/administrator.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ In this definition, the operator overwrites the account's name to match
103103
`pod_service_account_name` and the `default` namespace to match the target
104104
namespace. The operator performs **no** further syncing of this account.
105105

106+
## Non-default cluster domain
107+
108+
If your cluster uses a different dns domain than `cluster.local`, this needs
109+
to be set in the operator ConfigMap. This is used by the operator to connect
110+
to the clusters after creation.
111+
106112
## Role-based access control for the operator
107113

108114
The `manifests/operator-service-account-rbac.yaml` defines cluster roles and

docs/reference/operator_parameters.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ configuration they are grouped under the `kubernetes` key.
159159
allowed. The default is
160160
`{username}.{cluster}.credentials.{tprkind}.{tprgroup}`.
161161

162+
* **cluster_domain**
163+
defines the default dns domain for the kubernetes cluster the operator is
164+
running in. The default is `cluster.local`. Used by the operator to connect
165+
to the postgres clusters after creation.
166+
162167
* **oauth_token_secret_name**
163168
a name of the secret containing the `OAuth2` token to pass to the teams API.
164169
The default is `postgresql-operator`.

manifests/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ data:
1313
docker_image: registry.opensource.zalan.do/acid/spilo-cdp-11:1.5-p70
1414
pod_service_account_name: "zalando-postgres-operator"
1515
secret_name_template: '{username}.{cluster}.credentials'
16+
cluster_domain: cluster.local
1617
super_username: postgres
1718
enable_teams_api: "false"
1819
spilo_privileged: "false"

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ configuration:
2121
pod_terminate_grace_period: 5m
2222
pdb_name_format: "postgres-{cluster}-pdb"
2323
secret_name_template: "{username}.{cluster}.credentials.{tprkind}.{tprgroup}"
24+
cluster_domain: cluster.local
2425
oauth_token_secret_name: postgresql-operator
2526
pod_role_label: spilo-role
2627
spilo_privileged: false

pkg/apis/acid.zalan.do/v1/operator_configuration_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type KubernetesMetaConfiguration struct {
4949
WatchedNamespace string `json:"watched_namespace,omitempty"`
5050
PDBNameFormat config.StringTemplate `json:"pdb_name_format,omitempty"`
5151
SecretNameTemplate config.StringTemplate `json:"secret_name_template,omitempty"`
52+
ClusterDomain string `json:"cluster_domain"`
5253
OAuthTokenSecretName spec.NamespacedName `json:"oauth_token_secret_name,omitempty"`
5354
InfrastructureRolesSecretName spec.NamespacedName `json:"infrastructure_roles_secret_name,omitempty"`
5455
PodRoleLabel string `json:"pod_role_label,omitempty"`

pkg/cluster/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (c *Cluster) pgConnectionString() string {
3434
password := c.systemUsers[constants.SuperuserKeyName].Password
3535

3636
return fmt.Sprintf("host='%s' dbname=postgres sslmode=require user='%s' password='%s' connect_timeout='%d'",
37-
fmt.Sprintf("%s.%s.svc.cluster.local", c.Name, c.Namespace),
37+
fmt.Sprintf("%s.%s.svc.%s", c.Name, c.Namespace, c.OpConfig.ClusterDomain),
3838
c.systemUsers[constants.SuperuserKeyName].Name,
3939
strings.Replace(password, "$", "\\$", -1),
4040
constants.PostgresConnectTimeout/time.Second)

pkg/controller/operator_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
4242
result.PodEnvironmentConfigMap = fromCRD.Kubernetes.PodEnvironmentConfigMap
4343
result.PodTerminateGracePeriod = time.Duration(fromCRD.Kubernetes.PodTerminateGracePeriod)
4444
result.SpiloPrivileged = fromCRD.Kubernetes.SpiloPrivileged
45+
result.ClusterDomain = fromCRD.Kubernetes.ClusterDomain
4546
result.WatchedNamespace = fromCRD.Kubernetes.WatchedNamespace
4647
result.PDBNameFormat = fromCRD.Kubernetes.PDBNameFormat
4748
result.SecretNameTemplate = fromCRD.Kubernetes.SecretNameTemplate

pkg/util/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Resources struct {
2626
PodDeletionWaitTimeout time.Duration `name:"pod_deletion_wait_timeout" default:"10m"`
2727
PodTerminateGracePeriod time.Duration `name:"pod_terminate_grace_period" default:"5m"`
2828
PodPriorityClassName string `name:"pod_priority_class_name"`
29+
ClusterDomain string `name:"cluster_domain" default:"cluster.local"`
2930
SpiloPrivileged bool `name:"spilo_privileged" default:"false"`
3031
ClusterLabels map[string]string `name:"cluster_labels" default:"application:spilo"`
3132
InheritedLabels []string `name:"inherited_labels" default:""`

0 commit comments

Comments
 (0)