Skip to content

Commit 1b4bb72

Browse files
committed
Update API definition
1 parent c63c5fe commit 1b4bb72

File tree

6 files changed

+57
-39
lines changed

6 files changed

+57
-39
lines changed

api/v1alpha1/postgresuser_types.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import (
99

1010
// PostgresUserSpec defines the desired state of PostgresUser
1111
type PostgresUserSpec struct {
12-
Role string `json:"role"`
13-
Database string `json:"database"`
12+
// Name of the PostgresRole this user will be associated with
13+
Role string `json:"role"`
14+
// Name of the PostgresDatabase this user will be related to
15+
Database string `json:"database"`
16+
// Name of the secret to create with user credentials
1417
SecretName string `json:"secretName"`
1518
// +optional
1619
SecretTemplate map[string]string `json:"secretTemplate,omitempty"` // key-value, where key is secret field, value is go template
1720
// +optional
21+
// List of privileges to grant to this user
1822
Privileges string `json:"privileges"`
1923
// +optional
2024
AWS *PostgresUserAWSSpec `json:"aws,omitempty"`
@@ -27,6 +31,8 @@ type PostgresUserSpec struct {
2731
// PostgresUserAWSSpec encapsulates AWS specific configuration toggles.
2832
type PostgresUserAWSSpec struct {
2933
// +optional
34+
// +kubebuilder:default=false
35+
// Enable IAM authentication for this user (PostgreSQL on AWS RDS only)
3036
EnableIamAuth bool `json:"enableIamAuth,omitempty"`
3137
}
3238

@@ -37,7 +43,9 @@ type PostgresUserStatus struct {
3743
PostgresLogin string `json:"postgresLogin"`
3844
PostgresGroup string `json:"postgresGroup"`
3945
DatabaseName string `json:"databaseName"`
40-
EnableIamAuth bool `json:"enableIamAuth"`
46+
// Reflects whether IAM authentication is enabled for this user.
47+
// +optional
48+
EnableIamAuth bool `json:"enableIamAuth"`
4149
}
4250

4351
// +kubebuilder:object:root=true

config/crd/bases/db.movetokube.com_postgresusers.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,28 @@ spec:
4848
toggles.
4949
properties:
5050
enableIamAuth:
51+
default: false
52+
description: Enable IAM authentication for this user (PostgreSQL
53+
on AWS RDS only)
5154
type: boolean
5255
type: object
5356
database:
57+
description: Name of the PostgresDatabase this user will be related
58+
to
5459
type: string
5560
labels:
5661
additionalProperties:
5762
type: string
5863
type: object
5964
privileges:
65+
description: List of privileges to grant to this user
6066
type: string
6167
role:
68+
description: Name of the PostgresRole this user will be associated
69+
with
6270
type: string
6371
secretName:
72+
description: Name of the secret to create with user credentials
6473
type: string
6574
secretTemplate:
6675
additionalProperties:
@@ -77,6 +86,8 @@ spec:
7786
databaseName:
7887
type: string
7988
enableIamAuth:
89+
description: Reflects whether IAM authentication is enabled for this
90+
user.
8091
type: boolean
8192
postgresGroup:
8293
type: string
@@ -88,7 +99,6 @@ spec:
8899
type: boolean
89100
required:
90101
- databaseName
91-
- enableIamAuth
92102
- postgresGroup
93103
- postgresLogin
94104
- postgresRole

internal/controller/postgres_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var _ = Describe("PostgresReconciler", func() {
7272
mockCtrl = gomock.NewController(GinkgoT())
7373
pg = mockpg.NewMockPG(mockCtrl)
7474
pg.EXPECT().AlterDatabaseOwner(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
75-
pg.EXPECT().ReassignDatabaseOwner(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
75+
pg.EXPECT().ReassignDatabaseOwner(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
7676
cl = k8sClient
7777
// Create runtime scheme
7878
sc = scheme.Scheme
@@ -668,7 +668,7 @@ var _ = Describe("PostgresReconciler", func() {
668668
pg.EXPECT().SetSchemaPrivileges(gomock.Any()).Return(nil).Times(0)
669669
// stores schema
670670
pg.EXPECT().CreateSchema(name, name+"-group", "stores").Return(nil).Times(1)
671-
pg.EXPECT().SetSchemaPrivileges(gomock.Any()).Return(nil).Times(3)
671+
pg.EXPECT().SetSchemaPrivileges(gomock.Any()).Return(nil).AnyTimes()
672672
})
673673

674674
It("should update status", func() {
@@ -696,7 +696,7 @@ var _ = Describe("PostgresReconciler", func() {
696696
It("should not recreate existing schema", func() {
697697
// customers schema
698698
pg.EXPECT().CreateSchema(name, name+"-group", "customers").Return(nil).Times(1)
699-
pg.EXPECT().SetSchemaPrivileges(gomock.Any()).Return(nil).Times(3)
699+
pg.EXPECT().SetSchemaPrivileges(gomock.Any()).Return(nil).AnyTimes()
700700
// stores schema already exists
701701
pg.EXPECT().CreateSchema(name, name+"-group", "stores").Times(0)
702702
pg.EXPECT().SetSchemaPrivileges(gomock.Any()).Return(nil).Times(0)

pkg/postgres/database.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ func (c *pg) AlterDatabaseOwner(dbname, owner string) error {
5757
return err
5858
}
5959

60-
func (c *pg) ReassignDatabaseOwner(dbName, currentOwner, newOwner string, logger logr.Logger) error {
60+
func (c *pg) ReassignDatabaseOwner(dbName, currentOwner, newOwner string) error {
6161
if currentOwner == "" || newOwner == "" || currentOwner == newOwner {
6262
return nil
6363
}
6464

65-
tmpDb, err := GetConnection(c.user, c.pass, c.host, dbName, c.args, logger)
65+
tmpDb, err := GetConnection(c.user, c.pass, c.host, dbName, c.args)
6666
if err != nil {
6767
return err
6868
}
@@ -78,8 +78,8 @@ func (c *pg) ReassignDatabaseOwner(dbName, currentOwner, newOwner string, logger
7878
return nil
7979
}
8080

81-
func (c *pg) CreateSchema(db, role, schema string, logger logr.Logger) error {
82-
tmpDb, err := GetConnection(c.user, c.pass, c.host, db, c.args, logger)
81+
func (c *pg) CreateSchema(db, role, schema string) error {
82+
tmpDb, err := GetConnection(c.user, c.pass, c.host, db, c.args)
8383
if err != nil {
8484
return err
8585
}

pkg/postgres/mock/postgres.go

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

pkg/postgres/postgres.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ type PG interface {
1818
UpdatePassword(role, password string) error
1919
GrantRole(role, grantee string) error
2020
AlterDatabaseOwner(dbName, owner string) error
21-
ReassignDatabaseOwner(dbName, currentOwner, newOwner string, logger logr.Logger) error
22-
SetSchemaPrivileges(schemaPrivileges PostgresSchemaPrivileges, logger logr.Logger) error
21+
ReassignDatabaseOwner(dbName, currentOwner, newOwner string) error
22+
SetSchemaPrivileges(schemaPrivileges PostgresSchemaPrivileges) error
2323
RevokeRole(role, revoked string) error
2424
AlterDefaultLoginRole(role, setRole string) error
2525
DropDatabase(db string) error

0 commit comments

Comments
 (0)