Skip to content

Commit fa60402

Browse files
RafiaSabihRafia SabihFxKu
authored
Move flag to configmap (zalando#1540)
* Move flag to configmap Co-authored-by: Rafia Sabih <[email protected]> Co-authored-by: Felix Kunde <[email protected]>
1 parent 330c2c4 commit fa60402

File tree

17 files changed

+66
-53
lines changed

17 files changed

+66
-53
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ spec:
173173
enable_init_containers:
174174
type: boolean
175175
default: true
176+
enable_cross_namespace_secret:
177+
type: boolean
178+
default: false
176179
enable_pod_antiaffinity:
177180
type: boolean
178181
default: false

charts/postgres-operator/crds/postgresqls.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,6 @@ spec:
515515
type: integer
516516
useLoadBalancer: # deprecated
517517
type: boolean
518-
enableNamespacedSecret:
519-
type: boolean
520518
users:
521519
type: object
522520
additionalProperties:

charts/postgres-operator/values.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ configKubernetes:
9797
# - deployment-time
9898
# - downscaler/*
9999

100+
# allow user secrets in other namespaces than the Postgres cluster
101+
enable_cross_namespace_secret: false
100102
# enables initContainers to run actions before Spilo is started
101103
enable_init_containers: true
102104
# toggles pod anti affinity on the Postgres pods
@@ -151,7 +153,7 @@ configKubernetes:
151153
# template for database user secrets generated by the operator,
152154
# here username contains the namespace in the format namespace.username
153155
# if the user is in different namespace than cluster and cross namespace secrets
154-
# are enabled via EnableNamespacedSecret flag.
156+
# are enabled via `enable_cross_namespace_secret` flag in the configuration.
155157
secret_name_template: "{username}.{cluster}.credentials.{tprkind}.{tprgroup}"
156158
# set user and group for the spilo container (required to run Spilo as non-root process)
157159
# spilo_runasuser: 101

docs/reference/operator_parameters.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ configuration they are grouped under the `kubernetes` key.
264264
[admin docs](../administrator.md#pod-disruption-budget) for more information.
265265
Default is true.
266266

267+
* **enable_cross_namespace_secrets**
268+
To allow secrets in a different namespace other than the Postgres cluster
269+
namespace. Once enabled, specify the namespace in the user name under the
270+
`users` section in the form `{namespace}.{username}`. The operator will then
271+
create the user secret in that namespace. The part after the first `.` is
272+
considered to be the user name. The default is `false`.
273+
267274
* **enable_init_containers**
268275
global option to allow for creating init containers in the cluster manifest to
269276
run actions before Spilo is started. Default is true.
@@ -275,13 +282,12 @@ configuration they are grouped under the `kubernetes` key.
275282

276283
* **secret_name_template**
277284
a template for the name of the database user secrets generated by the
278-
operator. `{namespace}` is replaced with name of the namespace (if cross
279-
namespace secrets are enabled via EnableNamespacedSecret flag, otherwise the
280-
secret is in cluster's namespace and in that case it is not present in secret
281-
name), `{username}` is replaced with name of the secret, `{cluster}` with the
282-
name of the cluster, `{tprkind}` with the kind of CRD (formerly known as TPR)
283-
and `{tprgroup}` with the group of the CRD. No other placeholders are allowed.
284-
The default is
285+
operator. `{namespace}` is replaced with name of the namespace if
286+
`enable_cross_namespace_secret` is set, otherwise the
287+
secret is in cluster's namespace. `{username}` is replaced with name of the
288+
secret, `{cluster}` with the name of the cluster, `{tprkind}` with the kind
289+
of CRD (formerly known as TPR) and `{tprgroup}` with the group of the CRD.
290+
No other placeholders are allowed. The default is
285291
`{namespace}.{username}.{cluster}.credentials.{tprkind}.{tprgroup}`.
286292

287293
* **cluster_domain**

docs/user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ At the moment it is not possible to define membership of the manifest role in
140140
other roles.
141141

142142
To define the secrets for the users in a different namespace than that of the cluster,
143-
one can use the flag `EnableNamespacedSecret` and declare the namespace for the
143+
one can set `enable_cross_namespace_secret` and declare the namespace for the
144144
secrets in the manifest in the following manner,
145145

146146
```yaml

e2e/tests/test_e2e.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -598,29 +598,36 @@ def test_zz_cross_namespace_secrets(self):
598598
self.k8s.api.core_v1.create_namespace(v1_appnamespace)
599599
self.k8s.wait_for_namespace_creation(app_namespace)
600600

601+
patch_cross_namespace_secret = {
602+
"data": {
603+
"enable_cross_namespace_secret": "true"
604+
}
605+
}
606+
self.k8s.update_config(patch_cross_namespace_secret,
607+
step="cross namespace secrets enabled")
608+
601609
self.k8s.api.custom_objects_api.patch_namespaced_custom_object(
602610
'acid.zalan.do', 'v1', 'default',
603611
'postgresqls', 'acid-minimal-cluster',
604612
{
605613
'spec': {
606-
'enableNamespacedSecret': True,
607614
'users':{
608615
'appspace.db_user': [],
609616
}
610617
}
611618
})
619+
612620
self.eventuallyEqual(lambda: self.k8s.count_secrets_with_label("cluster-name=acid-minimal-cluster,application=spilo", app_namespace),
613621
1, "Secret not created for user in namespace")
614622

615623
#reset the flag
616-
self.k8s.api.custom_objects_api.patch_namespaced_custom_object(
617-
'acid.zalan.do', 'v1', 'default',
618-
'postgresqls', 'acid-minimal-cluster',
619-
{
620-
'spec': {
621-
'enableNamespacedSecret': False,
624+
unpatch_cross_namespace_secret = {
625+
"data": {
626+
"enable_cross_namespace_secret": "false",
622627
}
623-
})
628+
}
629+
self.k8s.update_config(unpatch_cross_namespace_secret, step="disable cross namespace secrets")
630+
624631

625632
@timeout_decorator.timeout(TEST_TIMEOUT_SEC)
626633
def test_lazy_spilo_upgrade(self):

manifests/complete-postgres-manifest.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ spec:
1212
dockerImage: registry.opensource.zalan.do/acid/spilo-13:2.0-p7
1313
teamId: "acid"
1414
numberOfInstances: 2
15-
enableNamespacedSecret: False
1615
users: # Application/Robot users
1716
zalando:
1817
- superuser

manifests/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ data:
3636
# downscaler_annotations: "deployment-time,downscaler/*"
3737
# enable_admin_role_for_users: "true"
3838
# enable_crd_validation: "true"
39+
# enable_cross_namespace_secret: "false"
3940
# enable_database_access: "true"
4041
enable_ebs_gp3_migration: "false"
4142
# enable_ebs_gp3_migration_max_size: "1000"

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ configuration:
4545
# downscaler_annotations:
4646
# - deployment-time
4747
# - downscaler/*
48+
# enable_cross_namespace_secret: "false"
4849
enable_init_containers: true
4950
enable_pod_antiaffinity: false
5051
enable_pod_disruption_budget: true

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,6 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
730730
Type: "boolean",
731731
Description: "Deprecated",
732732
},
733-
"enableNamespacedSecret": {
734-
Type: "boolean",
735-
},
736733
"users": {
737734
Type: "object",
738735
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
@@ -1029,6 +1026,9 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
10291026
},
10301027
},
10311028
},
1029+
"enable_cross_namespace_secret": {
1030+
Type: "boolean",
1031+
},
10321032
"enable_init_containers": {
10331033
Type: "boolean",
10341034
},

0 commit comments

Comments
 (0)