Skip to content

Commit a9c3f75

Browse files
handling seq privilege
1 parent 532f3d3 commit a9c3f75

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

controllers/postgresql/grant_controller.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"strings"
2828
"time"
2929

30+
"golang.org/x/exp/slices"
31+
3032
corev1 "k8s.io/api/core/v1"
3133
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3234
"k8s.io/apimachinery/pkg/runtime"
@@ -224,7 +226,7 @@ func (r *GrantReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
224226
return ctrl.Result{}, nil
225227
}
226228
} else if currentGrantType == common.GRANTTABLE {
227-
if check_all.MatchString(*existingGrant.Spec.Table) && existingGrant.Spec.Schema != grant.Spec.Schema {
229+
if check_all.MatchString(*existingGrant.Spec.Table) && existingGrant.Spec.Schema == grant.Spec.Schema {
228230
reason := fmt.Sprintf(
229231
"Already a grant `%s/%s` created with ALL tables permission for role `%s/%s`. So delete this grant `%s/%s`",
230232
existingGrant.Namespace,
@@ -237,7 +239,7 @@ func (r *GrantReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
237239
r.appendGrantStatusCondition(ctx, grant, common.FAIL, metav1.ConditionFalse, GRANTDUPLICATED, reason)
238240
grantLogger.Error(err, reason)
239241
return ctrl.Result{}, nil
240-
} else if existingGrant.Spec.Table == grant.Spec.Table && existingGrant.Spec.Schema != grant.Spec.Schema {
242+
} else if existingGrant.Spec.Table == grant.Spec.Table && existingGrant.Spec.Schema == grant.Spec.Schema {
241243
reason := fmt.Sprintf(
242244
"Already a grant `%s/%s` created with `%s` table permission for role `%s/%s`. So delete this grant `%s/%s`",
243245
existingGrant.Namespace,
@@ -572,7 +574,7 @@ func (r *GrantReconciler) ObserveGrantState(ctx context.Context, grant *postgres
572574

573575
case common.GRANTTABLE:
574576
if check_all.MatchString(privileges[0]) {
575-
privileges = []string{"INSERT", "SELECT", "UPDATE", "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER"}
577+
privileges = []string{"INSERT", "SELECT", "UPDATE", "DELETE", "TRUNCATE", "REFERENCES", "TRIGGER", "USAGE"}
576578
}
577579

578580
if check_all.MatchString(table) {
@@ -603,6 +605,8 @@ func (r *GrantReconciler) ObserveGrantState(ctx context.Context, grant *postgres
603605
}
604606
sort.Sort(sort.StringSlice(privileges))
605607
sort.Sort(sort.StringSlice(futureTablesResults))
608+
privileges = slices.Compact(privileges)
609+
futureTablesResults = slices.Compact(futureTablesResults)
606610
if cmp.Equal(privileges, futureTablesResults) {
607611
isGrantStateNotChanged = true
608612
} else {

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ module github.com/Facets-cloud/postgresql-operator
33
go 1.19
44

55
require (
6+
github.com/google/go-cmp v0.5.9
67
github.com/lib/pq v1.10.8
78
github.com/onsi/ginkgo/v2 v2.6.0
89
github.com/onsi/gomega v1.24.1
10+
golang.org/x/exp v0.0.0-20231127185646-65229373498e
911
k8s.io/api v0.26.0
1012
k8s.io/apimachinery v0.26.0
1113
k8s.io/client-go v0.26.0
@@ -28,7 +30,6 @@ require (
2830
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
2931
github.com/golang/protobuf v1.5.2 // indirect
3032
github.com/google/gnostic v0.5.7-v3refs // indirect
31-
github.com/google/go-cmp v0.5.9 // indirect
3233
github.com/google/gofuzz v1.1.0 // indirect
3334
github.com/google/uuid v1.1.2 // indirect
3435
github.com/imdario/mergo v0.3.6 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
298298
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
299299
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
300300
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
301+
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
302+
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
301303
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
302304
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
303305
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

0 commit comments

Comments
 (0)