Skip to content

Commit d7d3a70

Browse files
author
Matthias Fuhrmeister
authored
Merge branch 'master' into turtle/ELT-16035
2 parents ecfc2a7 + 1d9e64b commit d7d3a70

File tree

13 files changed

+204
-64
lines changed

13 files changed

+204
-64
lines changed

.github/workflows/release.yml

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,48 @@ on:
44
release:
55
types: [published]
66

7+
permissions:
8+
contents: read
9+
packages: write
710
jobs:
811
build:
9-
1012
runs-on: ubuntu-latest
11-
1213
steps:
13-
- uses: actions/checkout@v1
14+
- uses: actions/checkout@v3
15+
1416
- name: Generate Docker Tag
1517
run: |
1618
echo ${{ github.ref }} | cut -d '/' -f 3 > DOCKER_TAG
17-
- name: Build and push container image
18-
run: |
19-
docker build --file build/Dockerfile.dist --tag ghcr.io/movetokube/postgres-operator:$(cat DOCKER_TAG) --tag movetokube/postgres-operator:$(cat DOCKER_TAG) .
20-
docker tag ghcr.io/movetokube/postgres-operator:$(cat DOCKER_TAG) ghcr.io/movetokube/postgres-operator:latest
21-
docker tag movetokube/postgres-operator:$(cat DOCKER_TAG) movetokube/postgres-operator:latest
22-
23-
docker login ghcr.io --username USERNAME --password ${{ secrets.GITHUB_TOKEN }}
24-
docker push ghcr.io/movetokube/postgres-operator:$(cat DOCKER_TAG)
25-
docker push ghcr.io/movetokube/postgres-operator:latest
26-
27-
docker login --username ${{ secrets.DOCKER_USER }} --password ${{ secrets.DOCKER_TOKEN }}
28-
docker push movetokube/postgres-operator:$(cat DOCKER_TAG)
29-
docker push movetokube/postgres-operator:latest
19+
echo "DOCKER_TAG=$(cat DOCKER_TAG)" >> $GITHUB_ENV
20+
21+
- name: Set up QEMU
22+
uses: docker/setup-qemu-action@v2
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v2
26+
27+
- name: Login to Docker Hub
28+
uses: docker/login-action@v2
29+
with:
30+
username: ${{ secrets.DOCKER_USER }}
31+
password: ${{ secrets.DOCKER_TOKEN }}
3032

33+
- name: Login to GitHub Container Registry
34+
uses: docker/login-action@v2
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.repository_owner }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
3139

40+
- name: Build and push
41+
uses: docker/build-push-action@v4
42+
with:
43+
context: .
44+
file: ./build/Dockerfile.dist
45+
platforms: linux/amd64,linux/arm64
46+
push: true
47+
tags: |
48+
ghcr.io/movetokube/postgres-operator:latest
49+
ghcr.io/movetokube/postgres-operator:${{ env.DOCKER_TAG }}
50+
movetokube/postgres-operator:${{ env.DOCKER_TAG }}
51+
movetokube/postgres-operator:latest

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
11
# External PostgreSQL server operator for Kubernetes
22

3-
---------------------------------------------------------
4-
### IMPORTANT UPDATE
5-
6-
### Restoring pushes to DockerHub repository `movetokube/postgres-operator`
7-
8-
Some history about this:
9-
10-
About 10 days after announcing the decition to sunset free organisations in dockerhub and receiving heavily negative community feedback
11-
Docker revoked their decision, did a 180-degree turn and did not sunset free legacy organisations.
12-
13-
Thus, new images of this operator will be pushed to both `movetokube/postgres-operator` and `ghcr.io/movetokube/postgres-operator` for your convenience.
14-
15-
Starting with ext-postgres-operator Helm chart version **1.2.3** images will be pulled from ghcr by default, you can change this if you like.
16-
17-
Here's how to install it (please install with care according to your configuration):
18-
```shell
19-
helm repo add ext-postgres-operator https://movetokube.github.io/postgres-operator/
20-
helm upgrade --install -n operators ext-postgres-operator ext-postgres-operator/ext-postgres-operator --version 1.2.3
21-
```
22-
23-
----------------------------------------------------------
243
## Sponsors
254

265
Please consider sponsoring my work
@@ -39,6 +18,7 @@ None
3918
* Creates Kubernetes secret with postgres_uri in the same namespace as CR
4019
* Support for AWS RDS and Azure Database for PostgresSQL
4120
* Support for managing CRs in dynamically created namespaces
21+
* Template secret values
4222

4323
## Cloud specific configuration
4424

@@ -71,9 +51,17 @@ These environment variables are embedded in [deploy/operator.yaml](deploy/operat
7151
* `WATCH_NAMESPACE` - which namespace to watch. Defaults to empty string for all namespaces
7252
* `OPERATOR_NAME` - name of the operator, defaults to `ext-postgres-operator`
7353
* `POSTGRES_INSTANCE` - identity of operator, this matched with `postgres.db.movetokube.com/instance` in CRs. Default is empty
54+
* `KEEP_SECRET_NAME` - use secret name as provided by user (disabled by default)
7455

7556
`POSTGRES_INSTANCE` is only available since version 1.2.0
7657

58+
> While using `KEEP_SECRET_NAME` could be a convenient way to define secrets with predictable and explicit names,
59+
> the default logic reduces risk of operator from entering the endless reconcile loop as secret is very unlikely to exist.
60+
>
61+
> The administrator should ensure that the `SecretName` does not collide with other secrets in the same namespace.
62+
> If the secret already exists, the operator will never stop reconciling the CR until either offending secret is deleted
63+
> or CR is deleted or updated with another SecretName
64+
7765
## Installation
7866

7967
This operator requires a Kubernetes Secret to be created in the same namespace as operator itself.
@@ -165,9 +153,11 @@ spec:
165153
privileges: OWNER # Can be OWNER/READ/WRITE
166154
annotations: # Annotations to be propagated to the secrets metadata section (optional)
167155
foo: "bar"
156+
secretTemplate: # Output secrets can be customized using standard Go templates
157+
PQ_URL: "host={{.Host}} user={{.Role}} password={{.Password}} dbname={{.Database}}"
168158
```
169159

170-
This creates a user role `username-<hash>` and grants role `test-db-group`, `test-db-writer` or `test-db-reader` depending on `privileges` property. Its credentials are put in secret `my-secret-my-db-user`.
160+
This creates a user role `username-<hash>` and grants role `test-db-group`, `test-db-writer` or `test-db-reader` depending on `privileges` property. Its credentials are put in secret `my-secret-my-db-user` (unless `KEEP_SECRET_NAME` is enabled).
171161

172162
`PostgresUser` needs to reference a `Postgres` in the same namespace.
173163

@@ -195,6 +185,21 @@ With the help of annotations it is possible to create annotation-based copies of
195185

196186
For more information and an example, see [kubernetes-replicator#pull-based-replication](https://github.com/mittwald/kubernetes-replicator#pull-based-replication)
197187

188+
#### Template Use Case
189+
190+
Users can specify the structure and content of secrets based on their unique requirements using standard
191+
[Go templates](https://pkg.go.dev/text/template#hdr-Actions). This flexibility allows for a more tailored approach to
192+
meeting the specific needs of different applications.
193+
194+
Available context:
195+
196+
| Variable | Meaning |
197+
|-------------|--------------------------|
198+
| `.Host` | Database host |
199+
| `.Role` | Generated user/role name |
200+
| `.Database` | Referenced database name |
201+
| `.Password` | Generated role password |
202+
198203
### Contribution
199204

200205
You can contribute to this project by opening a PR to merge to `master`, or one of the `vX.X.X` branches.

build/Dockerfile.dist

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
FROM golang:1.18-stretch
1+
# syntax=docker/dockerfile:1
2+
FROM --platform=${BUILDPLATFORM} golang:1.18-stretch AS build
23

3-
COPY . /go/src/github.com/movetokube/postgres-operator
4-
WORKDIR /go/src/github.com/movetokube/postgres-operator/cmd/manager
4+
ARG TARGETPLATFORM
5+
ARG BUILDPLATFORM
6+
ARG TARGETOS
7+
ARG TARGETARCH
58

6-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/postgres-operator
9+
WORKDIR /src
10+
COPY go.mod go.sum ./
11+
RUN go mod download
712

13+
COPY . .
814

9-
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
15+
RUN --mount=target=. \
16+
--mount=type=cache,target=/root/.cache/go-build \
17+
--mount=type=cache,target=/go/pkg \
18+
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
19+
go build -o /usr/local/bin/postgres-operator cmd/manager/main.go
20+
21+
FROM --platform=${TARGETPLATFORM} registry.access.redhat.com/ubi8/ubi-minimal:latest
1022

1123
ENV OPERATOR=/usr/local/bin/postgres-operator \
1224
USER_UID=1001 \
@@ -20,5 +32,4 @@ RUN /usr/local/bin/user_setup
2032

2133
ENTRYPOINT ["/usr/local/bin/entrypoint"]
2234

23-
USER ${USER_UID}
24-
35+
USER ${USER_UID}

charts/ext-postgres-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ type: application
1111
# This is the chart version. This version number should be incremented each time you make changes
1212
# to the chart and its templates, including the app version.
1313
# Versions are expected to follow Semantic Versioning (https://semver.org/)
14-
version: 1.2.3
14+
version: 1.2.5
1515

1616
# This is the version number of the application being deployed. This version number should be
1717
# incremented each time you make changes to the application. Versions are not expected to
1818
# follow Semantic Versioning. They should reflect the version the application is using.
1919
# It is recommended to use it with quotes.
20-
appVersion: "1.2.3"
20+
appVersion: "1.3.2"

charts/ext-postgres-operator/crds/db.movetokube.com_postgresusers_crd.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ spec:
3131
spec:
3232
description: PostgresUserSpec defines the desired state of PostgresUser
3333
properties:
34+
annotations:
35+
additionalProperties:
36+
type: string
37+
type: object
3438
database:
3539
type: string
3640
privileges:
@@ -39,6 +43,10 @@ spec:
3943
type: string
4044
secretName:
4145
type: string
46+
secretTemplate:
47+
additionalProperties:
48+
type: string
49+
type: object
4250
required:
4351
- database
4452
- role

charts/ext-postgres-operator/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ image:
88
repository: ghcr.io/movetokube/postgres-operator
99
pullPolicy: IfNotPresent
1010
# Overrides the image tag whose default is the chart appVersion.
11-
tag: "latest"
11+
tag: ""
1212

1313
# Override chart name, defaults to Chart.name
1414
nameOverride: ""

deploy/crds/db.movetokube.com_postgresusers_crd.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ spec:
3131
spec:
3232
description: PostgresUserSpec defines the desired state of PostgresUser
3333
properties:
34+
annotations:
35+
additionalProperties:
36+
type: string
37+
type: object
3438
database:
3539
type: string
3640
privileges:
@@ -39,6 +43,10 @@ spec:
3943
type: string
4044
secretName:
4145
type: string
46+
secretTemplate:
47+
additionalProperties:
48+
type: string
49+
type: object
4250
required:
4351
- database
4452
- role

deploy/operator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ spec:
2525
env:
2626
- name: WATCH_NAMESPACE
2727
value: ""
28+
- name: KEEP_SECRET_NAME
29+
value: "false"
2830
- name: POD_NAME
2931
valueFrom:
3032
fieldRef:

pkg/apis/db/v1alpha1/postgresuser_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ type PostgresUserSpec struct {
1414
Database string `json:"database"`
1515
SecretName string `json:"secretName"`
1616
// +optional
17+
SecretTemplate map[string]string `json:"secretTemplate,omitempty"` // key-value, where key is secret field, value is go template
18+
// +optional
1719
Privileges string `json:"privileges"`
1820
// +optional
1921
Annotations map[string]string `json:"annotations,omitempty"`

pkg/apis/db/v1alpha1/zz_generated.deepcopy.go

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

pkg/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"net/url"
5+
"strconv"
56
"sync"
67

78
"github.com/movetokube/postgres-operator/pkg/utils"
@@ -15,6 +16,7 @@ type cfg struct {
1516
PostgresDefaultDb string
1617
CloudProvider string
1718
AnnotationFilter string
19+
KeepSecretName bool
1820
}
1921

2022
var doOnce sync.Once
@@ -30,6 +32,9 @@ func Get() *cfg {
3032
config.PostgresDefaultDb = utils.GetEnv("POSTGRES_DEFAULT_DATABASE")
3133
config.CloudProvider = utils.GetEnv("POSTGRES_CLOUD_PROVIDER")
3234
config.AnnotationFilter = utils.GetEnv("POSTGRES_INSTANCE")
35+
if value, err := strconv.ParseBool(utils.GetEnv("KEEP_SECRET_NAME")); err == nil {
36+
config.KeepSecretName = value
37+
}
3338
})
3439
return config
3540
}

0 commit comments

Comments
 (0)