Skip to content

Commit

Permalink
#162, #165 : Compatible with PostgreSql 16 and upgraded the operator …
Browse files Browse the repository at this point in the history
…framework libraries Kubebuilder 3.12.0 in order to benefit from the latest features up to Kubernetes version 1.27.3
  • Loading branch information
alex-arica committed Oct 26, 2023
1 parent ca71755 commit 195b9bd
Show file tree
Hide file tree
Showing 153 changed files with 3,713 additions and 2,636 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
testbin/
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ docker-build
*.dll
*.so
*.dylib
bin
bin/*
testbin/*
Dockerfile.cross

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

!vendor/**/zz_generated.*

test-output.txt

# editor and IDE paraphernalia
.idea
.vscode
*.swp
*.swo
*~
28 changes: 10 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Build the manager binary
FROM golang:1.18 as builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM
FROM golang:1.21 as builder
ARG TARGETOS
ARG TARGETARCH

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

# Copy the go source
COPY main.go main.go
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY controllers/ controllers/
COPY internal/controller/ internal/controller/

# Build
ENV CGO_ENABLED=0 \
GO111MODULE=on

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

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
79 changes: 52 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
LATEST = controller:latest
IMG ?= $(LATEST)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.2
ENVTEST_K8S_VERSION = 1.27.3

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

# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
Expand All @@ -24,7 +30,7 @@ all: build

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

.PHONY: test
test: build envtest ## Run tests.
go test $(shell pwd)/test -run $(shell pwd)/test/suite_test.go -v -test.timeout 10000s
#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
#KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test test/suite_test.go -coverprofile cover.out -v -test.timeout 10000s
go test $(shell pwd)/internal/test -run $(shell pwd)/internal/test/suite_test.go -v -test.timeout 10000s
#KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

##@ Build

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go generate
go build -o bin/manager main.go
go generate cmd/main.go
go build -o bin/manager cmd/main.go

.PHONY: run
run: install ## Run a controller from your host.
go run ./main.go

#docker-build: test ## Build docker image with the manager.
.PHONY: docker-build-push
docker-build-push: build ## Build docker image with the manager.
docker buildx build --platform linux/amd64,linux/arm64 -t ${IMG} --push .
go run ./cmd/main.go

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

#.PHONY: docker-push
#docker-push: ## Push docker image with the manager.
# docker push ${IMG}
# $(CONTAINER_TOOL) push ${IMG}

# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - 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)
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
- $(CONTAINER_TOOL) buildx use project-v3-builder
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
- $(CONTAINER_TOOL) buildx rm project-v3-builder
rm Dockerfile.cross

##@ Deployment

Expand All @@ -93,11 +113,11 @@ endif

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

.PHONY: uninstall
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.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -

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

.PHONY: undeploy
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.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -

##@ Build Dependencies

Expand All @@ -129,24 +149,29 @@ $(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
KUBECTL ?= kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.9.2
KUSTOMIZE_VERSION ?= v5.2.1
CONTROLLER_TOOLS_VERSION ?= v0.13.0

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

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

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
Expand Down
6 changes: 5 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: reactive-tech.io
layout:
- go.kubebuilder.io/v3
- go.kubebuilder.io/v4
projectName: kubegres
repo: reactive-tech.io/kubegres
resources:
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[Kubegres](https://www.kubegres.io/) is a Kubernetes operator allowing to deploy one or many clusters of PostgreSql pods with data
replication and failover enabled out-of-the box. It brings simplicity when using PostgreSql considering how complex managing
[Kubegres](https://www.kubegres.io/) is a Kubernetes operator allowing to deploy one or many clusters of PostgreSql pods with data
replication and failover enabled out-of-the box. It brings simplicity when using PostgreSql considering how complex managing
stateful-set's life-cycle and data replication could be with Kubernetes.

**Features**

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

* 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
* 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
number of Replica PostgreSql pods and replicates primary's database in real-time to Replica pods.

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

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

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


**How does Kubegres differentiate itself?**

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

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

**More details about the project**

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

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

**Support**

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

**Sponsor**

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

**Interesting links**
Expand Down
File renamed without changes.
6 changes: 1 addition & 5 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/*
Copyright 2021 Reactive Tech Limited.
"Reactive Tech Limited" is a company located in England, United Kingdom.
https://www.reactive-tech.io
Lead Developer: Alex Arica
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
12 changes: 4 additions & 8 deletions api/v1/kubegres_types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/*
Copyright 2021 Reactive Tech Limited.
"Reactive Tech Limited" is a company located in England, United Kingdom.
https://www.reactive-tech.io
Lead Developer: Alex Arica
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -113,8 +109,8 @@ type KubegresStatus struct {

// ----------------------- RESOURCE ---------------------------------------

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Kubegres is the Schema for the kubegres API
type Kubegres struct {
Expand All @@ -125,7 +121,7 @@ type Kubegres struct {
Status KubegresStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
//+kubebuilder:object:root=true

// KubegresList contains a list of Kubegres
type KubegresList struct {
Expand Down
3 changes: 1 addition & 2 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 195b9bd

Please sign in to comment.