You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AboutBits PostgreSQL Operator is a Kubernetes operator that helps you manage PostgreSQL databases, roles (users), and privileges in a declarative way using Custom Resource Definitions (CRDs).
4
+
5
+
## Usage
6
+
7
+
This operator allows you to manage PostgreSQL resources using Kubernetes manifests.
8
+
Further documentation of each Custom Resource can be found here:
9
+
10
+
-[ClusterConnection](docs/cluster-connection.md) – Define a connection to a PostgreSQL cluster.
The following example shows how to set up a connection to a PostgreSQL cluster, create a database and schema, a login role (user), and configure permissions.
20
+
21
+
```yaml
22
+
# Define a ClusterConnection resource to connect to a PostgreSQL cluster.
23
+
---
24
+
apiVersion: v1
25
+
kind: Secret
26
+
metadata:
27
+
name: my-postgres-secret
28
+
type: kubernetes.io/basic-auth
29
+
stringData:
30
+
username: postgres
31
+
password: password
32
+
---
33
+
apiVersion: postgresql.aboutbits.it/v1
34
+
kind: ClusterConnection
35
+
metadata:
36
+
name: my-postgres-connection
37
+
spec:
38
+
host: postgres-host
39
+
port: 5432
40
+
database: postgres
41
+
adminSecretRef:
42
+
name: my-postgres-secret
43
+
44
+
# Create a Database
45
+
---
46
+
apiVersion: postgresql.aboutbits.it/v1
47
+
kind: Database
48
+
metadata:
49
+
name: my-database
50
+
spec:
51
+
clusterRef:
52
+
name: my-postgres-connection
53
+
name: my_app_db
54
+
reclaimPolicy: Retain
55
+
owner: dba_user
56
+
57
+
# Create a Schema
58
+
---
59
+
apiVersion: postgresql.aboutbits.it/v1
60
+
kind: Schema
61
+
metadata:
62
+
name: my-schema
63
+
spec:
64
+
clusterRef:
65
+
name: my-postgres-connection
66
+
name: my_app_schema
67
+
reclaimPolicy: Retain
68
+
owner: dba_user
69
+
70
+
# Create a Login Role (User)
71
+
---
72
+
apiVersion: v1
73
+
kind: Secret
74
+
metadata:
75
+
name: my-app-user-secret
76
+
type: kubernetes.io/basic-auth
77
+
stringData:
78
+
password: secret_password
79
+
---
80
+
apiVersion: postgresql.aboutbits.it/v1
81
+
kind: Role
82
+
metadata:
83
+
name: my-role
84
+
spec:
85
+
clusterRef:
86
+
name: my-postgres-connection
87
+
name: my_app_user
88
+
passwordSecretRef:
89
+
name: my-app-user-secret
90
+
flags:
91
+
createdb: false
92
+
93
+
# Configure Permissions
94
+
---
95
+
apiVersion: postgresql.aboutbits.it/v1
96
+
kind: Grant
97
+
metadata:
98
+
name: my-grant
99
+
spec:
100
+
clusterRef:
101
+
name: my-postgres-connection
102
+
database: my_app_db
103
+
role: my_app_user
104
+
objectType: schema
105
+
schema: my_app_schema
106
+
privileges:
107
+
- usage
108
+
109
+
# Configure Default Privileges
110
+
---
111
+
apiVersion: postgresql.aboutbits.it/v1
112
+
kind: DefaultPrivilege
113
+
metadata:
114
+
name: my-default-privilege
115
+
spec:
116
+
clusterRef:
117
+
name: my-postgres-connection
118
+
database: my_app_db
119
+
role: my_app_user
120
+
owner: shared_developer_user
121
+
objectType: table
122
+
schema: my_app_schema
123
+
privileges:
124
+
- select
125
+
- insert
126
+
- update
127
+
- delete
128
+
```
129
+
130
+
## Contribute
4
131
5
132
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
6
133
@@ -12,19 +139,19 @@ To build the project, the following prerequisites must be met:
12
139
- [Gradle](https://gradle.org/) (Optional)
13
140
- [Docker](https://www.docker.com/)
14
141
15
-
### Setup configuration
142
+
### Setup
16
143
17
144
To get started, call:
18
145
19
146
```bash
20
147
make init
21
148
```
22
149
23
-
### Running the project in the console
150
+
### Development
24
151
25
152
You can run your application in dev mode that enables live coding and continuous testing using:
26
153
27
-
```shell script
154
+
```bash
28
155
make run
29
156
30
157
# or
@@ -45,131 +172,22 @@ make test
45
172
./gradlew :operator:test
46
173
```
47
174
48
-
### Run the project as a service in IntelliJ
175
+
####Run the project as a service in IntelliJ
49
176
50
177
1. Open the `Services` tool on the left side of the IDE
51
178
2. Click on "+" and select "Quarkus"
52
179
53
180
Afterward, the project can be started in IntelliJ by navigating to `Run` -> `Run '...'`.
54
181
55
-
##Test the CRD on the ephemeral Dev Services cluster
182
+
### Docker Environment
56
183
57
-
This example demonstrates how to set up a local development environment using Quarkus Dev Services to test the Operator manually.
58
-
As the K3s cluster port and the secrets change on every `./gradlew :operator:quarkusDev` run, you will have to manually update the port and secrets in the `~/.kube/config` every time.
184
+
See [Docker Environment](docs/docker-environment.md) for setting up a local development environment using Quarkus Dev Services.
59
185
60
-
### 1. Configure Kubeconfig from Dev Services
61
-
62
-
When running in dev mode (`make run` or via IntelliJ), Quarkus starts the pre-configured K3s and PostgreSQL Dev Services.
63
-
64
-
1. Access the Quarkus Dev UI at [http://localhost:8080/q/dev-ui/dev-services](http://localhost:8080/q/dev-ui/dev-services).
65
-
2. Locate the properties for the `kubernetes-client` Dev Service.
66
-
3. Convert these properties into a **Kubeconfig YAML** format, see the example below.
67
-
4. Merge this configuration into your local `~/.kube/config`. This allows your local environment to communicate with the ephemeral Kubernetes cluster provided by Dev Services.
For the `postgresql` Dev Service, you can generate the necessary Custom Resources to test the Operator:
97
-
98
-
1. From the Dev UI, get the `postgresql` Dev Service properties (username, password, host, port).
99
-
2. Convert the `postgresql` Dev Service properties to a **Basic Auth Secret** and a **ClusterConnection** CR instance.
100
-
For more details see class `ClusterConnectionSpec` or the `ClusterConnection` CRD definition from `build/kubernetes/clusterconnections.postgresql.aboutbits.it-v1.yml` as a reference.
101
-
3. Apply the generated files using IntelliJ or `kubectl`.
- Operator SDK ([guide](https://docs.quarkiverse.io/quarkus-operator-sdk/dev/index.html)): Quarkus extension for the Java Operator SDK (https://javaoperatorsdk.io)
210
-
- Helm ([guide](https://docs.quarkiverse.io/quarkus-helm/dev/index.html)): Quarkus extension for Kubernetes Helm charts
211
-
- SmallRye Health ([guide](https://quarkus.io/guides/smallrye-health)): Monitor service health
212
-
- Micrometer metrics ([guide](https://quarkus.io/guides/micrometer)): Instrument the runtime and your application with dimensional metrics using Micrometer.
213
-
- YAML Configuration ([guide](https://quarkus.io/guides/config-yaml)): Use YAML to configure your Quarkus application
237
+
The MIT License (MIT). Please see the [license file](LICENSE) for more information.
0 commit comments