Skip to content

Commit edcfc2c

Browse files
authored
Support multiple global postgres-operators with filter on annotation (#86)
* Update to go 1.18, ubi8 and update vendoring to work with go 1.18 * Use annotation to filter out what CR's to process * Fix bug in annotation filter * Add basic test, and fix reconcile function * Fix lockname for different instances * Update Azure specific code to work with the new Flexible offering * Bump setup-go action * Return proper error if user and database is not managed by same operator * Fix for Azure Postgres Flexible Server
1 parent 6300415 commit edcfc2c

File tree

397 files changed

+53651
-118568
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

397 files changed

+53651
-118568
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ jobs:
88
name: Go test
99
steps:
1010
- uses: actions/checkout@master
11-
- uses: actions/setup-go@v1
11+
- uses: actions/setup-go@v3
1212
with:
13-
go-version: '1.15.2'
13+
go-version: '1.18.1'
1414
- run: |
1515
go test ./...
1616
build:
1717
runs-on: ubuntu-latest
1818
name: Go build
1919
steps:
2020
- uses: actions/checkout@master
21-
- uses: actions/setup-go@v1
21+
- uses: actions/setup-go@v3
2222
with:
23-
go-version: '1.15.2'
23+
go-version: '1.18.1'
2424
- run: |
2525
go build -mod=vendor -o operator github.com/movetokube/postgres-operator/cmd/manager
2626
file operator

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
In order for this operator to work correctly with AWS RDS, you need to set `POSTGRES_CLOUD_PROVIDER` to `AWS` either in
1717
the ext-postgres-operator kubernetes secret or directly in the deployment manifest (`operator.yaml`).
1818

19-
### Azure Database for PostgreSQL
19+
### Azure Database for PostgreSQL (both Single Server and Flexible Server)
2020

2121
In order for this operator to work correctly with Azure managed PostgreSQL database, two env variables needs to be provided for the operator:
2222

build/Dockerfile.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM golang:1.13.3-stretch
1+
FROM golang:1.18-stretch
22

33
COPY . /go/src/github.com/movetokube/postgres-operator
44
WORKDIR /go/src/github.com/movetokube/postgres-operator/cmd/manager
55

66
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/postgres-operator
77

88

9-
FROM registry.access.redhat.com/ubi7/ubi-minimal:latest
9+
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
1010

1111
ENV OPERATOR=/usr/local/bin/postgres-operator \
1212
USER_UID=1001 \

cmd/manager/main.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ import (
55
"errors"
66
"flag"
77
"fmt"
8+
"os"
9+
"runtime"
10+
"strings"
11+
812
kubemetrics "github.com/operator-framework/operator-sdk/pkg/kube-metrics"
913
"github.com/operator-framework/operator-sdk/pkg/metrics"
1014
v1 "k8s.io/api/core/v1"
1115
"k8s.io/apimachinery/pkg/util/intstr"
1216
"k8s.io/client-go/rest"
13-
"os"
14-
"runtime"
1517
"sigs.k8s.io/controller-runtime/pkg/cache"
16-
"strings"
1718

1819
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
1920
_ "k8s.io/client-go/plugin/pkg/client/auth"
2021

2122
"github.com/movetokube/postgres-operator/pkg/apis"
23+
operatorconfig "github.com/movetokube/postgres-operator/pkg/config"
2224
"github.com/movetokube/postgres-operator/pkg/controller"
23-
25+
"github.com/movetokube/postgres-operator/pkg/utils"
2426
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
2527
"github.com/operator-framework/operator-sdk/pkg/leader"
2628
"github.com/operator-framework/operator-sdk/pkg/log/zap"
@@ -69,6 +71,16 @@ func main() {
6971

7072
printVersion()
7173

74+
operatorConfig := operatorconfig.Get()
75+
var lockName string
76+
if operatorConfig.AnnotationFilter == "" {
77+
log.Info("No POSTGRES_INSTANCE set, this instance will only process CR's without an annotation")
78+
lockName = "postgres-operator-lock"
79+
} else {
80+
log.Info(fmt.Sprintf("POSTGRES_INSTANCE is set, this instance will only process CR's with the annotation: %s: %s", utils.INSTANCE_ANNOTATION, operatorConfig.AnnotationFilter))
81+
lockName = fmt.Sprintf("postgres-operator-lock-%s", operatorConfig.AnnotationFilter)
82+
}
83+
7284
namespace, err := k8sutil.GetWatchNamespace()
7385
if err != nil {
7486
log.Error(err, "Failed to get watch namespace")
@@ -85,7 +97,7 @@ func main() {
8597
ctx := context.TODO()
8698

8799
// Become the leader before proceeding
88-
err = leader.Become(ctx, "postgres-operator-lock")
100+
err = leader.Become(ctx, lockName)
89101
if err != nil {
90102
log.Error(err, "")
91103
os.Exit(1)

go.mod

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module github.com/movetokube/postgres-operator
22

3-
go 1.13
3+
go 1.18
44

55
require (
6-
github.com/emicklei/go-restful v2.11.1+incompatible // indirect
76
github.com/go-logr/logr v0.1.0
87
github.com/go-openapi/spec v0.19.4
98
github.com/golang/mock v1.3.1
@@ -16,10 +15,73 @@ require (
1615
k8s.io/apimachinery v0.18.2
1716
k8s.io/client-go v12.0.0+incompatible
1817
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c
19-
//k8s.io/kubernetes v1.16.2 // indirect
2018
sigs.k8s.io/controller-runtime v0.6.0
2119
)
2220

21+
require (
22+
cloud.google.com/go v0.49.0 // indirect
23+
github.com/Azure/go-autorest/autorest v0.9.3-0.20191028180845-3492b2aff503 // indirect
24+
github.com/Azure/go-autorest/autorest/adal v0.8.1-0.20191028180845-3492b2aff503 // indirect
25+
github.com/Azure/go-autorest/autorest/date v0.2.0 // indirect
26+
github.com/Azure/go-autorest/logger v0.1.0 // indirect
27+
github.com/Azure/go-autorest/tracing v0.5.0 // indirect
28+
github.com/PuerkitoBio/purell v1.1.1 // indirect
29+
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
30+
github.com/beorn7/perks v1.0.1 // indirect
31+
github.com/cespare/xxhash/v2 v2.1.1 // indirect
32+
github.com/coreos/prometheus-operator v0.38.1-0.20200424145508-7e176fda06cc // indirect
33+
github.com/davecgh/go-spew v1.1.1 // indirect
34+
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
35+
github.com/emicklei/go-restful v2.11.1+incompatible // indirect
36+
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
37+
github.com/go-logr/zapr v0.1.1 // indirect
38+
github.com/go-openapi/jsonpointer v0.19.3 // indirect
39+
github.com/go-openapi/jsonreference v0.19.3 // indirect
40+
github.com/go-openapi/swag v0.19.5 // indirect
41+
github.com/gogo/protobuf v1.3.1 // indirect
42+
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
43+
github.com/golang/protobuf v1.3.2 // indirect
44+
github.com/google/go-cmp v0.4.0 // indirect
45+
github.com/google/gofuzz v1.1.0 // indirect
46+
github.com/google/uuid v1.1.1 // indirect
47+
github.com/googleapis/gnostic v0.3.1 // indirect
48+
github.com/gophercloud/gophercloud v0.6.0 // indirect
49+
github.com/hashicorp/golang-lru v0.5.3 // indirect
50+
github.com/hpcloud/tail v1.0.0 // indirect
51+
github.com/imdario/mergo v0.3.8 // indirect
52+
github.com/json-iterator/go v1.1.9 // indirect
53+
github.com/mailru/easyjson v0.7.0 // indirect
54+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
55+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
56+
github.com/modern-go/reflect2 v1.0.1 // indirect
57+
github.com/pkg/errors v0.9.1 // indirect
58+
github.com/prometheus/client_golang v1.5.1 // indirect
59+
github.com/prometheus/client_model v0.2.0 // indirect
60+
github.com/prometheus/common v0.9.1 // indirect
61+
github.com/prometheus/procfs v0.0.8 // indirect
62+
go.uber.org/atomic v1.6.0 // indirect
63+
go.uber.org/multierr v1.5.0 // indirect
64+
go.uber.org/zap v1.14.1 // indirect
65+
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 // indirect
66+
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect
67+
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
68+
golang.org/x/sys v0.0.0-20220405052023-b1e9470b6e64 // indirect
69+
golang.org/x/text v0.3.2 // indirect
70+
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
71+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
72+
gomodules.xyz/jsonpatch/v2 v2.0.1 // indirect
73+
google.golang.org/appengine v1.6.5 // indirect
74+
gopkg.in/fsnotify.v1 v1.4.7 // indirect
75+
gopkg.in/inf.v0 v0.9.1 // indirect
76+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
77+
gopkg.in/yaml.v2 v2.2.8 // indirect
78+
k8s.io/klog v1.0.0 // indirect
79+
k8s.io/kube-state-metrics v1.7.2 // indirect
80+
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89 // indirect
81+
sigs.k8s.io/structured-merge-diff/v3 v3.0.0 // indirect
82+
sigs.k8s.io/yaml v1.2.0 // indirect
83+
)
84+
2385
replace (
2486
github.com/Azure/go-autorest => github.com/Azure/go-autorest v13.3.2+incompatible // Required by OLM
2587
k8s.io/client-go => k8s.io/client-go v0.18.2 // Required by prometheus-operator

0 commit comments

Comments
 (0)