new default values for user and role definition
This commit is contained in:
parent
d68ef1a20e
commit
5d7c0959dc
|
|
@ -138,7 +138,6 @@ spec:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- secretname
|
- secretname
|
||||||
- userkey
|
|
||||||
- passwordkey
|
- passwordkey
|
||||||
properties:
|
properties:
|
||||||
secretname:
|
secretname:
|
||||||
|
|
@ -149,6 +148,10 @@ spec:
|
||||||
type: string
|
type: string
|
||||||
rolekey:
|
rolekey:
|
||||||
type: string
|
type: string
|
||||||
|
defaultuservalue:
|
||||||
|
type: string
|
||||||
|
defaultrolevalue:
|
||||||
|
type: string
|
||||||
details:
|
details:
|
||||||
type: string
|
type: string
|
||||||
template:
|
template:
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,6 @@ spec:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- secretname
|
- secretname
|
||||||
- userkey
|
|
||||||
- passwordkey
|
- passwordkey
|
||||||
properties:
|
properties:
|
||||||
secretname:
|
secretname:
|
||||||
|
|
@ -145,6 +144,10 @@ spec:
|
||||||
type: string
|
type: string
|
||||||
rolekey:
|
rolekey:
|
||||||
type: string
|
type: string
|
||||||
|
defaultuservalue:
|
||||||
|
type: string
|
||||||
|
defaultrolevalue:
|
||||||
|
type: string
|
||||||
details:
|
details:
|
||||||
type: string
|
type: string
|
||||||
template:
|
template:
|
||||||
|
|
|
||||||
|
|
@ -916,7 +916,7 @@ var OperatorConfigCRDResourceValidation = apiextv1beta1.CustomResourceValidation
|
||||||
Items: &apiextv1beta1.JSONSchemaPropsOrArray{
|
Items: &apiextv1beta1.JSONSchemaPropsOrArray{
|
||||||
Schema: &apiextv1beta1.JSONSchemaProps{
|
Schema: &apiextv1beta1.JSONSchemaProps{
|
||||||
Type: "object",
|
Type: "object",
|
||||||
Required: []string{"secretname", "userkey", "passwordkey"},
|
Required: []string{"secretname", "passwordkey"},
|
||||||
Properties: map[string]apiextv1beta1.JSONSchemaProps{
|
Properties: map[string]apiextv1beta1.JSONSchemaProps{
|
||||||
"secretname": {
|
"secretname": {
|
||||||
Type: "string",
|
Type: "string",
|
||||||
|
|
@ -930,6 +930,12 @@ var OperatorConfigCRDResourceValidation = apiextv1beta1.CustomResourceValidation
|
||||||
"rolekey": {
|
"rolekey": {
|
||||||
Type: "string",
|
Type: "string",
|
||||||
},
|
},
|
||||||
|
"defaultuservalue": {
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
"defaultrolevalue": {
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
"details": {
|
"details": {
|
||||||
Type: "string",
|
Type: "string",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,7 @@ func (c *Cluster) deleteConnectionPooler() (err error) {
|
||||||
serviceName = service.Name
|
serviceName = service.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// set delete propagation policy to foreground, so that all the dependant
|
// set delete propagation policy to foreground, so that all the dependent
|
||||||
// will be deleted.
|
// will be deleted.
|
||||||
err = c.KubeClient.
|
err = c.KubeClient.
|
||||||
Services(c.Namespace).
|
Services(c.Namespace).
|
||||||
|
|
|
||||||
|
|
@ -500,6 +500,7 @@ func (c *Cluster) syncSecrets() error {
|
||||||
c.logger.Warningf("secret %q does not contain the role %q", secretSpec.Name, secretUsername)
|
c.logger.Warningf("secret %q does not contain the role %q", secretSpec.Name, secretUsername)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
c.Secrets[secret.UID] = secret
|
||||||
c.logger.Debugf("secret %q already exists, fetching its password", util.NameFromMeta(secret.ObjectMeta))
|
c.logger.Debugf("secret %q already exists, fetching its password", util.NameFromMeta(secret.ObjectMeta))
|
||||||
if secretUsername == c.systemUsers[constants.SuperuserKeyName].Name {
|
if secretUsername == c.systemUsers[constants.SuperuserKeyName].Name {
|
||||||
secretUsername = constants.SuperuserKeyName
|
secretUsername = constants.SuperuserKeyName
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import (
|
||||||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
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/cluster"
|
||||||
"github.com/zalando/postgres-operator/pkg/spec"
|
"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/config"
|
||||||
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
|
"github.com/zalando/postgres-operator/pkg/util/k8sutil"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
|
@ -159,13 +160,17 @@ func (c *Controller) getInfrastructureRoleDefinitions() []*config.Infrastructure
|
||||||
roleDef.PasswordKey = value
|
roleDef.PasswordKey = value
|
||||||
case "rolekey":
|
case "rolekey":
|
||||||
roleDef.RoleKey = value
|
roleDef.RoleKey = value
|
||||||
|
case "defaultuservalue":
|
||||||
|
roleDef.DefaultUserValue = value
|
||||||
|
case "defaultrolevalue":
|
||||||
|
roleDef.DefaultRoleValue = value
|
||||||
default:
|
default:
|
||||||
c.logger.Warningf("Role description is not known: %s", properties)
|
c.logger.Warningf("Role description is not known: %s", properties)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if roleDef.SecretName != emptyName &&
|
if roleDef.SecretName != emptyName &&
|
||||||
roleDef.UserKey != "" &&
|
(roleDef.UserKey != "" || roleDef.DefaultUserValue != "") &&
|
||||||
roleDef.PasswordKey != "" {
|
roleDef.PasswordKey != "" {
|
||||||
rolesDefs = append(rolesDefs, &roleDef)
|
rolesDefs = append(rolesDefs, &roleDef)
|
||||||
}
|
}
|
||||||
|
|
@ -328,9 +333,10 @@ func (c *Controller) getInfrastructureRole(
|
||||||
return nil, fmt.Errorf("could not decode yaml role: %v", err)
|
return nil, fmt.Errorf("could not decode yaml role: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
roleDescr.Name = string(secretData[infraRole.UserKey])
|
roleDescr.Name = util.Coalesce(string(secretData[infraRole.UserKey]), infraRole.DefaultUserValue)
|
||||||
roleDescr.Password = string(secretData[infraRole.PasswordKey])
|
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() {
|
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
|
// only old CRD and configmap format
|
||||||
{
|
{
|
||||||
[]*config.InfrastructureRole{},
|
[]*config.InfrastructureRole{},
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,9 @@ type InfrastructureRole struct {
|
||||||
PasswordKey string
|
PasswordKey string
|
||||||
RoleKey string
|
RoleKey string
|
||||||
|
|
||||||
|
DefaultUserValue string
|
||||||
|
DefaultRoleValue string
|
||||||
|
|
||||||
// This field point out the detailed yaml definition of the role, if exists
|
// This field point out the detailed yaml definition of the role, if exists
|
||||||
Details string
|
Details string
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue