Skip to content

Commit 74caa4b

Browse files
committed
feat: wip
1 parent 4791b95 commit 74caa4b

File tree

10 files changed

+444
-12
lines changed

10 files changed

+444
-12
lines changed

api/postgresql/v1alpha1/postgresqluserrole_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ type PostgresqlUserRolePrivilege struct {
5656
// +kubebuilder:validation:Required
5757
// +kubebuilder:validation:MinLength=1
5858
GeneratedSecretName string `json:"generatedSecretName"`
59+
// Extra connection URL Parameters
60+
ExtraConnectionURLParameters map[string]string `json:"extraConnectionUrlParameters,omitempty"`
5961
}
6062

6163
type PostgresqlUserRoleAttributes struct {

api/postgresql/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/postgresql.easymile.com_postgresqluserroles.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ spec:
9393
required:
9494
- name
9595
type: object
96+
extraConnectionUrlParameters:
97+
additionalProperties:
98+
type: string
99+
description: Extra connection URL Parameters
100+
type: object
96101
generatedSecretName:
97102
description: Generated secret name prefix
98103
minLength: 1

config/samples/userrole/managed-simple-rotation.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ spec:
2020
name: simple
2121
# Generated secret name with information for the selected database
2222
generatedSecretName: managed-simple-rotation
23+
# Extra connection URL Parameters
24+
extraConnectionUrlParameters:
25+
{}
26+
# param1: value1

config/samples/userrole/managed-simple.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ spec:
1818
name: simple
1919
# Generated secret name with information for the selected database
2020
generatedSecretName: managed-simple
21+
# Extra connection URL Parameters
22+
extraConnectionUrlParameters:
23+
{}
24+
# param1: value1
2125
# Role attributes
2226
# Note: Only attributes that aren't conflicting with operator are supported.
2327
roleAttributes:

config/samples/userrole/provided-simple.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ spec:
1616
name: simple
1717
# Generated secret name with information for the selected database
1818
generatedSecretName: simple1
19+
# Extra connection URL Parameters
20+
extraConnectionUrlParameters:
21+
{}
22+
# param1: value1
1923
# Import secret that will contain "USERNAME" and "PASSWORD" for provided mode
2024
importSecretName: provided-simple
2125
# Role attributes

docs/crds/PostgresqlUserRole.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ All these names are available for `kubectl`:
3737

3838
### PostgresqlUserRolePrivilege
3939

40-
| Field | Description | Scheme | Required |
41-
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | -------- |
42-
| privilege | User privilege on database. Enumeration is `OWNER`, `WRITER`, `READER`. | String | true |
43-
| connectionType | Connection type to be used for secret generation (Can be set to BOUNCER if wanted and supported by engine configuration). Enumeration is `PRIMARY`, `BOUNCER`. Default value is `PRIMARY` | String | false |
44-
| database | [PostgresqlDatabase](./PostgresqlDatabase.md) object reference | [CRLink](#crlink) | true |
45-
| generatedSecretName | Generated secret name used for secret generation. | String | true |
40+
| Field | Description | Scheme | Required |
41+
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | -------- |
42+
| privilege | User privilege on database. Enumeration is `OWNER`, `WRITER`, `READER`. | String | true |
43+
| connectionType | Connection type to be used for secret generation (Can be set to BOUNCER if wanted and supported by engine configuration). Enumeration is `PRIMARY`, `BOUNCER`. Default value is `PRIMARY` | String | false |
44+
| database | [PostgresqlDatabase](./PostgresqlDatabase.md) object reference | [CRLink](#crlink) | true |
45+
| generatedSecretName | Generated secret name used for secret generation. | String | true |
46+
| extraConnectionUrlParameters | Extra connection url parameters that will be added into `POSTGRES_URL_ARGS` and `ARGS` fields in generated secret | `map[string]string` | false |
4647

4748
### PostgresqlUserRoleAttributes
4849

@@ -96,6 +97,9 @@ spec:
9697
name: simple
9798
# Generated secret name with information for the selected database
9899
generatedSecretName: simple1
100+
# Extra connection URL Parameters
101+
extraConnectionUrlParameters: {}
102+
# param1: value1
99103
# Import secret that will contain "USERNAME" and "PASSWORD" for provided mode
100104
importSecretName: provided-simple
101105
# Role attributes

internal/controller/postgresql/postgresqluserrole_controller.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,17 @@ func (r *PostgresqlUserRoleReconciler) newSecretForPGUser(
561561
uc = pgec.Spec.UserConnections.BouncerConnection
562562
}
563563

564+
// Compute uri args from main ones to user defined ones
565+
uriArgList := []string{uc.URIArgs}
566+
// Loop over user defined list
567+
for k, v := range rolePrivilege.ExtraConnectionURLParameters {
568+
uriArgList = append(uriArgList, fmt.Sprintf("%s=%s", k, v))
569+
}
570+
// Join
571+
uriArgs := strings.Join(uriArgList, "&")
572+
564573
pgUserURL := postgres.TemplatePostgresqlURL(uc.Host, username, password, dbInstance.Status.Database, uc.Port)
565-
pgUserURLWArgs := postgres.TemplatePostgresqlURLWithArgs(uc.Host, username, password, uc.URIArgs, dbInstance.Status.Database, uc.Port)
574+
pgUserURLWArgs := postgres.TemplatePostgresqlURLWithArgs(uc.Host, username, password, uriArgs, dbInstance.Status.Database, uc.Port)
566575

567576
// Create secret data
568577
data := map[string][]byte{
@@ -573,7 +582,7 @@ func (r *PostgresqlUserRoleReconciler) newSecretForPGUser(
573582
SecretMainKeyDatabase: []byte(dbInstance.Status.Database),
574583
SecretMainKeyHost: []byte(uc.Host),
575584
SecretMainKeyPort: []byte(strconv.Itoa(uc.Port)),
576-
SecretMainKeyArgs: []byte(uc.URIArgs),
585+
SecretMainKeyArgs: []byte(uriArgs),
577586
}
578587

579588
// Manage replica connections
@@ -585,8 +594,17 @@ func (r *PostgresqlUserRoleReconciler) newSecretForPGUser(
585594
}
586595
// Loop over list to inject in data replica data
587596
for i, ruc := range rucList {
597+
// Compute uri args from main ones to user defined ones
598+
uriArgList := []string{ruc.URIArgs}
599+
// Loop over user defined list
600+
for k, v := range rolePrivilege.ExtraConnectionURLParameters {
601+
uriArgList = append(uriArgList, fmt.Sprintf("%s=%s", k, v))
602+
}
603+
// Join
604+
uriArgs := strings.Join(uriArgList, "&")
605+
588606
replicaPGUserURL := postgres.TemplatePostgresqlURL(ruc.Host, username, password, dbInstance.Status.Database, ruc.Port)
589-
replicaPGUserURLWArgs := postgres.TemplatePostgresqlURLWithArgs(ruc.Host, username, password, ruc.URIArgs, dbInstance.Status.Database, ruc.Port)
607+
replicaPGUserURLWArgs := postgres.TemplatePostgresqlURLWithArgs(ruc.Host, username, password, uriArgs, dbInstance.Status.Database, ruc.Port)
590608

591609
// Build template
592610
keyTemplate := SecretKeyReplicaPrefix + "_" + strconv.Itoa(i) + "_%s"
@@ -598,7 +616,7 @@ func (r *PostgresqlUserRoleReconciler) newSecretForPGUser(
598616
data[fmt.Sprintf(keyTemplate, SecretMainKeyDatabase)] = []byte(dbInstance.Status.Database)
599617
data[fmt.Sprintf(keyTemplate, SecretMainKeyHost)] = []byte(ruc.Host)
600618
data[fmt.Sprintf(keyTemplate, SecretMainKeyPort)] = []byte(strconv.Itoa(ruc.Port))
601-
data[fmt.Sprintf(keyTemplate, SecretMainKeyArgs)] = []byte(ruc.URIArgs)
619+
data[fmt.Sprintf(keyTemplate, SecretMainKeyArgs)] = []byte(uriArgs)
602620
}
603621

604622
labels := map[string]string{

0 commit comments

Comments
 (0)