mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-05 04:21:41 +02:00
new default values for user and role definition
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
||||
"github.com/zalando/postgres-operator/pkg/cluster"
|
||||
"github.com/zalando/postgres-operator/pkg/spec"
|
||||
"github.com/zalando/postgres-operator/pkg/util"
|
||||
"github.com/zalando/postgres-operator/pkg/util/config"
|
||||
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
|
||||
"gopkg.in/yaml.v2"
|
||||
@@ -159,13 +160,17 @@ func (c *Controller) getInfrastructureRoleDefinitions() []*config.Infrastructure
|
||||
roleDef.PasswordKey = value
|
||||
case "rolekey":
|
||||
roleDef.RoleKey = value
|
||||
case "defaultuservalue":
|
||||
roleDef.DefaultUserValue = value
|
||||
case "defaultrolevalue":
|
||||
roleDef.DefaultRoleValue = value
|
||||
default:
|
||||
c.logger.Warningf("Role description is not known: %s", properties)
|
||||
}
|
||||
}
|
||||
|
||||
if roleDef.SecretName != emptyName &&
|
||||
roleDef.UserKey != "" &&
|
||||
(roleDef.UserKey != "" || roleDef.DefaultUserValue != "") &&
|
||||
roleDef.PasswordKey != "" {
|
||||
rolesDefs = append(rolesDefs, &roleDef)
|
||||
}
|
||||
@@ -328,9 +333,10 @@ func (c *Controller) getInfrastructureRole(
|
||||
return nil, fmt.Errorf("could not decode yaml role: %v", err)
|
||||
}
|
||||
} else {
|
||||
roleDescr.Name = string(secretData[infraRole.UserKey])
|
||||
roleDescr.Name = util.Coalesce(string(secretData[infraRole.UserKey]), infraRole.DefaultUserValue)
|
||||
roleDescr.Password = string(secretData[infraRole.PasswordKey])
|
||||
roleDescr.MemberOf = append(roleDescr.MemberOf, string(secretData[infraRole.RoleKey]))
|
||||
roleDescr.MemberOf = append(roleDescr.MemberOf,
|
||||
util.Coalesce(string(secretData[infraRole.RoleKey]), infraRole.DefaultRoleValue))
|
||||
}
|
||||
|
||||
if roleDescr.Valid() {
|
||||
|
||||
@@ -326,6 +326,25 @@ func TestInfrastructureRoleDefinitions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
// new configmap format with defaultRoleValue
|
||||
{
|
||||
[]*config.InfrastructureRole{},
|
||||
spec.NamespacedName{},
|
||||
"secretname: infrastructureroles-new-test, userkey: test-user, passwordkey: test-password, defaultrolevalue: test-role",
|
||||
[]*config.InfrastructureRole{
|
||||
&config.InfrastructureRole{
|
||||
SecretName: spec.NamespacedName{
|
||||
Namespace: v1.NamespaceDefault,
|
||||
Name: testInfrastructureRolesNewSecretName,
|
||||
},
|
||||
UserKey: "test-user",
|
||||
PasswordKey: "test-password",
|
||||
RoleKey: "",
|
||||
DefaultRoleValue: "test-role",
|
||||
Template: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
// only old CRD and configmap format
|
||||
{
|
||||
[]*config.InfrastructureRole{},
|
||||
|
||||
Reference in New Issue
Block a user