Skip to content

Commit 195b9bd

Browse files
committed
#162, #165 : Compatible with PostgreSql 16 and upgraded the operator framework libraries Kubebuilder 3.12.0 in order to benefit from the latest features up to Kubernetes version 1.27.3
1 parent ca71755 commit 195b9bd

File tree

153 files changed

+3713
-2636
lines changed

Some content is hidden

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

153 files changed

+3713
-2636
lines changed

.dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
22
# Ignore build and test binaries.
33
bin/
4-
testbin/

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ docker-build
66
*.dll
77
*.so
88
*.dylib
9-
bin
9+
bin/*
1010
testbin/*
11+
Dockerfile.cross
1112

1213
# Test binary, build with `go test -c`
1314
*.test
@@ -19,8 +20,11 @@ testbin/*
1920

2021
!vendor/**/zz_generated.*
2122

23+
test-output.txt
24+
2225
# editor and IDE paraphernalia
2326
.idea
27+
.vscode
2428
*.swp
2529
*.swo
2630
*~

Dockerfile

+10-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Build the manager binary
2-
FROM golang:1.18 as builder
3-
4-
ARG TARGETPLATFORM
5-
ARG BUILDPLATFORM
2+
FROM golang:1.21 as builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
65

76
WORKDIR /workspace
87
# Copy the Go Modules manifests
@@ -13,23 +12,16 @@ COPY go.sum go.sum
1312
RUN go mod download
1413

1514
# Copy the go source
16-
COPY main.go main.go
15+
COPY cmd/main.go cmd/main.go
1716
COPY api/ api/
18-
COPY controllers/ controllers/
17+
COPY internal/controller/ internal/controller/
1918

2019
# Build
21-
ENV CGO_ENABLED=0 \
22-
GO111MODULE=on
23-
24-
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
25-
RUN \
26-
export GOOS \
27-
&& GOOS=$(echo ${TARGETPLATFORM} | cut -d / -f1) \
28-
&& export GOARCH \
29-
&& GOARCH=$(echo ${TARGETPLATFORM} | cut -d / -f2) \
30-
&& export GOARM \
31-
&& GOARM=$(echo ${TARGETPLATFORM} | cut -d / -f3 | cut -c2-) \
32-
&& go build -a -o manager main.go
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
3325

3426
# Use distroless as minimal base image to package the manager binary
3527
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

+52-27
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
LATEST = controller:latest
44
IMG ?= $(LATEST)
55
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
6-
ENVTEST_K8S_VERSION = 1.24.2
6+
ENVTEST_K8S_VERSION = 1.27.3
77

88
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
99
ifeq (,$(shell go env GOBIN))
@@ -12,6 +12,12 @@ else
1212
GOBIN=$(shell go env GOBIN)
1313
endif
1414

15+
# CONTAINER_TOOL defines the container tool to be used for building images.
16+
# Be aware that the target commands are only tested with Docker which is
17+
# scaffolded by default. However, you might want to replace it to use other
18+
# tools. (i.e. podman)
19+
CONTAINER_TOOL ?= docker
20+
1521
# Setting SHELL to bash allows bash commands to be executed by recipes.
1622
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1723
SHELL = /usr/bin/env bash -o pipefail
@@ -24,7 +30,7 @@ all: build
2430

2531
# The help target prints out all targets with their descriptions organized
2632
# beneath their categories. The categories are represented by '##@' and the
27-
# target descriptions by '##'. The awk commands is responsible for reading the
33+
# target descriptions by '##'. The awk command is responsible for reading the
2834
# entire set of makefiles included in this invocation, looking for lines of the
2935
# file as xyz: ## something, and then pretty-format the target and help. Then,
3036
# if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -57,33 +63,47 @@ vet: ## Run go vet against code.
5763

5864
.PHONY: test
5965
test: build envtest ## Run tests.
60-
go test $(shell pwd)/test -run $(shell pwd)/test/suite_test.go -v -test.timeout 10000s
61-
#KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(shell pwd)/test -run $(shell pwd)/test/suite_test.go -v -coverprofile cover.out -test.timeout 10000s
62-
#KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test test/suite_test.go -coverprofile cover.out -v -test.timeout 10000s
66+
go test $(shell pwd)/internal/test -run $(shell pwd)/internal/test/suite_test.go -v -test.timeout 10000s
67+
#KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
6368

6469
##@ Build
6570

6671
.PHONY: build
6772
build: manifests generate fmt vet ## Build manager binary.
68-
go generate
69-
go build -o bin/manager main.go
73+
go generate cmd/main.go
74+
go build -o bin/manager cmd/main.go
7075

7176
.PHONY: run
7277
run: install ## Run a controller from your host.
73-
go run ./main.go
74-
75-
#docker-build: test ## Build docker image with the manager.
76-
.PHONY: docker-build-push
77-
docker-build-push: build ## Build docker image with the manager.
78-
docker buildx build --platform linux/amd64,linux/arm64 -t ${IMG} --push .
78+
go run ./cmd/main.go
7979

80+
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
81+
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
82+
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
8083
#.PHONY: docker-build
81-
#docker-build: test ## Build docker image with the manager.
82-
# docker build -t ${IMG} .
84+
#docker-build: ## Build docker image with the manager.
85+
# $(CONTAINER_TOOL) build -t ${IMG} .
8386

8487
#.PHONY: docker-push
8588
#docker-push: ## Push docker image with the manager.
86-
# docker push ${IMG}
89+
# $(CONTAINER_TOOL) push ${IMG}
90+
91+
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
92+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
93+
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
94+
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
95+
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
96+
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
97+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
98+
.PHONY: docker-buildx
99+
docker-buildx: ## Build and push docker image for the manager for cross-platform support
100+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
101+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
102+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
103+
- $(CONTAINER_TOOL) buildx use project-v3-builder
104+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
105+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
106+
rm Dockerfile.cross
87107

88108
##@ Deployment
89109

@@ -93,11 +113,11 @@ endif
93113

94114
.PHONY: install
95115
install: build kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
96-
$(KUSTOMIZE) build config/crd | kubectl apply -f -
116+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
97117

98118
.PHONY: uninstall
99119
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
100-
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
120+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
101121

102122
.PHONY: deploy-check
103123
deploy-check:
@@ -112,14 +132,14 @@ endif
112132
## Run acceptance tests then deploy into Docker Hub the controller as the Docker image provided in arg ${IMG}
113133
## and update the local file "kubegres.yaml" with the image ${IMG}
114134
.PHONY: deploy
115-
deploy: deploy-check test docker-build-push kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
135+
deploy: deploy-check docker-buildx kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
116136
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
117137
$(KUSTOMIZE) build config/default > kubegres.yaml
118138
@echo "DEPLOYED $(IMG) INTO DOCKER HUB. UPDATED 'kubegres.yaml' WITH '$(IMG)'. YOU CAN COMMIT 'kubegres.yaml' AND CREATE A RELEASE IN GITHUB."
119139

120140
.PHONY: undeploy
121141
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
122-
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
142+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
123143

124144
##@ Build Dependencies
125145

@@ -129,24 +149,29 @@ $(LOCALBIN):
129149
mkdir -p $(LOCALBIN)
130150

131151
## Tool Binaries
152+
KUBECTL ?= kubectl
132153
KUSTOMIZE ?= $(LOCALBIN)/kustomize
133154
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
134155
ENVTEST ?= $(LOCALBIN)/setup-envtest
135156

136157
## Tool Versions
137-
KUSTOMIZE_VERSION ?= v3.8.7
138-
CONTROLLER_TOOLS_VERSION ?= v0.9.2
158+
KUSTOMIZE_VERSION ?= v5.2.1
159+
CONTROLLER_TOOLS_VERSION ?= v0.13.0
139160

140-
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
141161
.PHONY: kustomize
142-
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
162+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
143163
$(KUSTOMIZE): $(LOCALBIN)
144-
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
164+
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
165+
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
166+
rm -rf $(LOCALBIN)/kustomize; \
167+
fi
168+
test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
145169

146170
.PHONY: controller-gen
147-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
171+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
148172
$(CONTROLLER_GEN): $(LOCALBIN)
149-
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
173+
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
174+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
150175

151176
.PHONY: envtest
152177
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.

PROJECT

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: reactive-tech.io
26
layout:
3-
- go.kubebuilder.io/v3
7+
- go.kubebuilder.io/v4
48
projectName: kubegres
59
repo: reactive-tech.io/kubegres
610
resources:

README.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
[Kubegres](https://www.kubegres.io/) is a Kubernetes operator allowing to deploy one or many clusters of PostgreSql pods with data
2-
replication and failover enabled out-of-the box. It brings simplicity when using PostgreSql considering how complex managing
1+
[Kubegres](https://www.kubegres.io/) is a Kubernetes operator allowing to deploy one or many clusters of PostgreSql pods with data
2+
replication and failover enabled out-of-the box. It brings simplicity when using PostgreSql considering how complex managing
33
stateful-set's life-cycle and data replication could be with Kubernetes.
44

55
**Features**
66

7-
* It can manage one or many clusters of Postgres instances.
8-
Each cluster of Postgres instances is created using a YAML of "kind: Kubegres". Each cluster is self-contained and is
7+
* It can manage one or many clusters of Postgres instances.
8+
Each cluster of Postgres instances is created using a YAML of "kind: Kubegres". Each cluster is self-contained and is
99
identified by its unique name and namespace.
1010

11-
* It creates a cluster of PostgreSql servers with [Streaming Replication](https://wiki.postgresql.org/wiki/Streaming_Replication) enabled: it creates a Primary PostgreSql pod and a
11+
* It creates a cluster of PostgreSql servers with [Streaming Replication](https://wiki.postgresql.org/wiki/Streaming_Replication) enabled: it creates a Primary PostgreSql pod and a
1212
number of Replica PostgreSql pods and replicates primary's database in real-time to Replica pods.
1313

1414
* It manages fail-over: if a Primary PostgreSql crashes, it automatically promotes a Replica PostgreSql as a Primary.
@@ -17,14 +17,14 @@ stateful-set's life-cycle and data replication could be with Kubernetes.
1717

1818
* It provides a very simple YAML with properties specialised for PostgreSql.
1919

20-
* It is resilient, has over [85 automatized tests](https://github.com/reactive-tech/kubegres/tree/main/test) cases and
21-
has been running in production.
20+
* It is resilient, has over [85 automatized tests](https://github.com/reactive-tech/kubegres/tree/main/test) cases and
21+
has been running in production.
2222

2323

2424
**How does Kubegres differentiate itself?**
2525

2626
Kubegres is fully integrated with Kubernetes' lifecycle as it runs as an operator written in Go.
27-
It is minimalist in terms of codebase compared to other open-source Postgres operators. It has the minimal and
27+
It is minimalist in terms of codebase compared to other open-source Postgres operators. It has the minimal and
2828
yet robust required features to manage a cluster of PostgreSql on Kubernetes. We aim keeping this project small and simple.
2929

3030
Among many reasons, there are [5 main ones why we recommend Kubegres](https://www.kubegres.io/#kubegres_compared).
@@ -39,23 +39,23 @@ If you would like to contribute to Kubegres, please read the page [How to contri
3939

4040
**More details about the project**
4141

42-
[Kubegres](https://www.kubegres.io/) was developed by [Reactive Tech Limited](https://www.reactive-tech.io/) and Alex
43-
Arica as the lead developer. Reactive Tech offers [support services](https://www.kubegres.io/support/) for Kubegres,
42+
[Kubegres](https://www.kubegres.io/) was developed by [Reactive Tech Limited](https://www.reactive-tech.io/) and Alex
43+
Arica as the lead developer. Reactive Tech offers [support services](https://www.kubegres.io/support/) for Kubegres,
4444
Kubernetes and PostgreSql.
4545

46-
It was developed with the framework [Kubebuilder](https://book.kubebuilder.io/) version 3, an SDK for building Kubernetes
46+
It was developed with the framework [Kubebuilder](https://book.kubebuilder.io/) version 3, an SDK for building Kubernetes
4747
APIs using CRDs. Kubebuilder is maintained by the official Kubernetes API Machinery Special Interest Group (SIG).
4848

4949
**Support**
5050

51-
[Reactive Tech Limited](https://www.reactive-tech.io/) offers support for organisations using Kubegres. And we prioritise
51+
[Reactive Tech Limited](https://www.reactive-tech.io/) offers support for organisations using Kubegres. And we prioritise
5252
new features requested by organisations paying supports as long the new features would benefit the Open Source community.
53-
We start working on the implementation of new features within 24h of the request from organisations paying supports.
53+
We start working on the implementation of new features within 24h of the request from organisations paying supports.
5454
More details in the [support page](https://www.kubegres.io/support/).
5555

5656
**Sponsor**
5757

58-
If you would like to help this project by sponsoring it, we can display your company's logo on this GitHub page
58+
If you would like to help this project by sponsoring it, we can display your company's logo on this GitHub page
5959
and on [https://www.kubegres.io](https://www.kubegres.io). More details in the [sponsor page](https://www.kubegres.io/sponsor/).
6060

6161
**Interesting links**
File renamed without changes.

api/v1/groupversion_info.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
/*
2-
Copyright 2021 Reactive Tech Limited.
3-
"Reactive Tech Limited" is a company located in England, United Kingdom.
4-
https://www.reactive-tech.io
5-
6-
Lead Developer: Alex Arica
2+
Copyright 2023.
73
84
Licensed under the Apache License, Version 2.0 (the "License");
95
you may not use this file except in compliance with the License.

api/v1/kubegres_types.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
/*
2-
Copyright 2021 Reactive Tech Limited.
3-
"Reactive Tech Limited" is a company located in England, United Kingdom.
4-
https://www.reactive-tech.io
5-
6-
Lead Developer: Alex Arica
2+
Copyright 2023.
73
84
Licensed under the Apache License, Version 2.0 (the "License");
95
you may not use this file except in compliance with the License.
@@ -113,8 +109,8 @@ type KubegresStatus struct {
113109

114110
// ----------------------- RESOURCE ---------------------------------------
115111

116-
// +kubebuilder:object:root=true
117-
// +kubebuilder:subresource:status
112+
//+kubebuilder:object:root=true
113+
//+kubebuilder:subresource:status
118114

119115
// Kubegres is the Schema for the kubegres API
120116
type Kubegres struct {
@@ -125,7 +121,7 @@ type Kubegres struct {
125121
Status KubegresStatus `json:"status,omitempty"`
126122
}
127123

128-
// +kubebuilder:object:root=true
124+
//+kubebuilder:object:root=true
129125

130126
// KubegresList contains a list of Kubegres
131127
type KubegresList struct {

api/v1/zz_generated.deepcopy.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)