Skip to content

Commit f2fec08

Browse files
Merge pull request #6 from Facets-cloud/fix_diff_sch_no_dup
Bring main up to date
2 parents 5ee74f6 + e3795f2 commit f2fec08

32 files changed

+1680
-14
lines changed

.github/workflows/image-build-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
context: .
3030
platforms: linux/amd64,linux/arm64
3131
push: true
32-
tags: ${{ env.REGISTRY_IMAGE }}:${{ github.ref_name }},${{ env.REGISTRY_IMAGE }}:latest
32+
tags: ${{ env.REGISTRY_IMAGE }}:${{ github.ref_name }}

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.19 as builder
2+
FROM golang:1.19 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -15,6 +15,8 @@ RUN go mod download
1515
COPY main.go main.go
1616
COPY apis/ apis/
1717
COPY controllers/ controllers/
18+
COPY utility/ utility/
19+
COPY validations/ validations
1820

1921
# Build
2022
# the GOARCH has not a default value to allow the binary be built according to the host where the command

PROJECT

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ resources:
3030
kind: Grant
3131
path: github.com/Facets-cloud/postgresql-operator/apis/postgresql/v1alpha1
3232
version: v1alpha1
33+
- api:
34+
crdVersion: v1
35+
namespaced: true
36+
controller: true
37+
domain: facets.cloud
38+
group: postgresql
39+
kind: GrantStatement
40+
path: github.com/Facets-cloud/postgresql-operator/apis/postgresql/v1alpha1
41+
version: v1alpha1
3342
version: "3"

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ This guide provides an introduction to using the PostgreSQL Operator. It will he
1515
- You’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.
1616
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).
1717
- A kubernetes secret that contains base64 encrypted PostgreSQL Database details `username`, `password`, `endpoint`, `port`, `database` and `role_password`
18-
> _Note:_
19-
> - You can use existing secret with database details and role password
20-
> - You can new secret with database details and role password
21-
> - You can also created two separate secret for database details and role password
2218

23-
- Create a secret that contains both the database details and the role password. You have the flexibility to choose your own name for the key representing the role password, as long as you reference it correctly in the Role CRD.
19+
> [!NOTE]
20+
> - You can use existing secret with database details and role password
21+
> - You can new secret with database details and role password
22+
> - You can also created two separate secret for database details and role password
23+
24+
> [!CAUTION]
25+
> - For granting permissions to a specific role, you should utilize either the Grant or GrantStatement Custom Resource Definition — but not both concurrently. Using both might lead to conflicts or unexpected behavior.
26+
> - For managing role permissions through the GrantStatement Custom Resource Definition on any database, ensure that no additional permissions are assigned outside the CRD manually. Any such additional permissions will be revoked when the CRD gets updated.
27+
> - Please note that you should not use any PostgreSQL GRANT query for a different database in a GrantStatement Custom Resource Definition that is specifically related to one database. If you do, the role cleanup process may not be successful.
28+
29+
- Create a secret that contains both the database details and the role password. You have the flexibility to choose your own name for the key representing the role password, as long as you reference it correctly in the Role CRD.
2430

2531
```bash
2632
kubectl create secret generic <secret_name> --from-literal=username=<postgresql_username> --from-literal=password=<postgresql_password> --from-literal=endpoint=<postgresql_endpoint> --from-literal=port=<postgresql_port> --from-literal=database=<postgresql_database> --from-literal=role_password=<postgresql_role_password>
@@ -75,6 +81,24 @@ spec:
7581
table: ALL
7682
```
7783

84+
#### Example GrantStatement CRD
85+
````yaml
86+
apiVersion: postgresql.facets.cloud/v1alpha1
87+
kind: GrantStatement
88+
metadata:
89+
name: test-grantstatement
90+
spec:
91+
roleRef:
92+
name: test-role
93+
namespace: default
94+
database: postgres
95+
statements:
96+
- 'GRANT CONNECT ON DATABASE postgres TO "test-role";'
97+
- 'GRANT USAGE ON SCHEMA public TO "test-role";'
98+
- 'GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "test-role";'
99+
- 'ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test-role";'
100+
````
101+
78102
For more examples, kindly check [here](examples)
79103

80104
### Running on the cluster
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Copyright 2023 Pramodh Ayyappan.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"github.com/Facets-cloud/postgresql-operator/apis/common"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26+
27+
// GrantStatementSpec defines the desired state of GrantStatement
28+
type GrantStatementSpec struct {
29+
// +kubebuilder:validation:Required
30+
Database string `json:"database"`
31+
32+
// +kubebuilder:validation:Required
33+
RoleRef common.ResourceReference `json:"roleRef"`
34+
35+
// +kubebuilder:validation:Required
36+
// +kubebuilder:validation:MinItems=1
37+
Statements []string `json:"statements"`
38+
}
39+
40+
// GrantStatementStatus defines the observed state of GrantStatement
41+
type GrantStatementStatus struct {
42+
Conditions []metav1.Condition `json:"conditions,omitempty"`
43+
PreviousGrantStatementState PreviousGrantStatementState `json:"previousGrantStatementState,omitempty"`
44+
}
45+
46+
type PreviousGrantStatementState struct {
47+
Database string `json:"database"`
48+
RoleRef common.ResourceReference `json:"roleRef"`
49+
Statements []string `json:"statements"`
50+
}
51+
52+
//+kubebuilder:object:root=true
53+
//+kubebuilder:subresource:status
54+
//+kubebuilder:printcolumn:name="Database",type=string,JSONPath=`.spec.database`
55+
//+kubebuilder:printcolumn:name="Role",type=string,JSONPath=`.spec.roleRef.name`
56+
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[-1:].status`
57+
//+kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[-1:].reason`
58+
//+kubebuilder:printcolumn:name="Last Transition Time",type=string,priority=1,JSONPath=`.status.conditions[-1:].lastTransitionTime`
59+
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
60+
61+
// GrantStatement is the Schema for the grantstatements API
62+
type GrantStatement struct {
63+
metav1.TypeMeta `json:",inline"`
64+
metav1.ObjectMeta `json:"metadata,omitempty"`
65+
66+
Spec GrantStatementSpec `json:"spec,omitempty"`
67+
Status GrantStatementStatus `json:"status,omitempty"`
68+
}
69+
70+
//+kubebuilder:object:root=true
71+
72+
// GrantStatementList contains a list of GrantStatement
73+
type GrantStatementList struct {
74+
metav1.TypeMeta `json:",inline"`
75+
metav1.ListMeta `json:"metadata,omitempty"`
76+
Items []GrantStatement `json:"items"`
77+
}
78+
79+
func init() {
80+
SchemeBuilder.Register(&GrantStatement{}, &GrantStatementList{})
81+
}

apis/postgresql/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)