-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Create cross namespace secrets #1490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
8cf76d8
6205020
af719c0
43154ba
188e812
f572047
fd5edea
4e9816b
25a6417
0f31b5b
09039e8
c0bfca9
b2171be
f0472fd
a992494
9e1d906
2f89354
1ed916f
775aa34
fcd9d27
27c6ac2
8f183c2
880c8a8
4ca2c56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1089,6 +1089,16 @@ func (c *Cluster) initRobotUsers() error { | |
| if c.shouldAvoidProtectedOrSystemRole(username, "manifest robot role") { | ||
| continue | ||
| } | ||
| name := username | ||
| namespace := "default" | ||
FxKu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if strings.Contains(username, ".") { | ||
|
||
| splits := strings.Split(username, ".") | ||
| name = splits[1] | ||
| namespace = splits[0] | ||
|
||
| username = name | ||
| } | ||
|
|
||
| flags, err := normalizeUserFlags(userFlags) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid flags for user %q: %v", username, err) | ||
|
|
@@ -1099,7 +1109,8 @@ func (c *Cluster) initRobotUsers() error { | |
| } | ||
| newRole := spec.PgUser{ | ||
| Origin: spec.RoleOriginManifest, | ||
| Name: username, | ||
| Name: name, | ||
| Namespace: namespace, | ||
| Password: util.RandomPassword(constants.PasswordLength), | ||
| Flags: flags, | ||
| AdminRole: adminRole, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,14 @@ import ( | |
|
|
||
| "github.com/sirupsen/logrus" | ||
| acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1" | ||
| fakeacidv1 "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/fake" | ||
| "github.com/zalando/postgres-operator/pkg/spec" | ||
| "github.com/zalando/postgres-operator/pkg/util/config" | ||
| "github.com/zalando/postgres-operator/pkg/util/constants" | ||
| "github.com/zalando/postgres-operator/pkg/util/k8sutil" | ||
| "github.com/zalando/postgres-operator/pkg/util/teams" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes/fake" | ||
| "k8s.io/client-go/tools/record" | ||
| ) | ||
|
|
||
|
|
@@ -845,3 +847,64 @@ func TestPreparedDatabases(t *testing.T) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| func TestCrossNamespacedSecrets(t *testing.T) { | ||
| testName := "test secrets in different namespace" | ||
| clientSet := fake.NewSimpleClientset() | ||
| acidClientSet := fakeacidv1.NewSimpleClientset() | ||
| namespace := "default" | ||
|
|
||
| client := k8sutil.KubernetesClient{ | ||
| StatefulSetsGetter: clientSet.AppsV1(), | ||
| ServicesGetter: clientSet.CoreV1(), | ||
| DeploymentsGetter: clientSet.AppsV1(), | ||
| PostgresqlsGetter: acidClientSet.AcidV1(), | ||
| SecretsGetter: clientSet.CoreV1(), | ||
| } | ||
| pg := acidv1.Postgresql{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "acid-fake-cluster", | ||
| Namespace: namespace, | ||
| }, | ||
| Spec: acidv1.PostgresSpec{ | ||
| Volume: acidv1.Volume{ | ||
| Size: "1Gi", | ||
| }, | ||
| Users: map[string]acidv1.UserFlags{ | ||
| "appspace.db_user": {}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| var cluster = New( | ||
| Config{ | ||
| OpConfig: config.Config{ | ||
| ConnectionPooler: config.ConnectionPooler{ | ||
| ConnectionPoolerDefaultCPURequest: "100m", | ||
| ConnectionPoolerDefaultCPULimit: "100m", | ||
| ConnectionPoolerDefaultMemoryRequest: "100Mi", | ||
| ConnectionPoolerDefaultMemoryLimit: "100Mi", | ||
| NumberOfInstances: int32ToPointer(1), | ||
| }, | ||
| PodManagementPolicy: "ordered_ready", | ||
| Resources: config.Resources{ | ||
| ClusterLabels: map[string]string{"application": "spilo"}, | ||
| ClusterNameLabel: "cluster-name", | ||
| DefaultCPURequest: "300m", | ||
| DefaultCPULimit: "300m", | ||
| DefaultMemoryRequest: "300Mi", | ||
| DefaultMemoryLimit: "300Mi", | ||
| PodRoleLabel: "spilo-role", | ||
| }, | ||
| }, | ||
| }, client, pg, logger, eventRecorder) | ||
|
|
||
| err := cluster.initRobotUsers() | ||
| if err != nil { | ||
| t.Errorf("%s Could not create namespaced users with error: %s", testName, err) | ||
|
||
| } | ||
|
|
||
| if cluster.pgUsers["db_user"].Namespace == cluster.Namespace { | ||
| t.Errorf("%s: Could not create namespaced users", testName) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it more informative, please log the name of the secret and the namespace