Skip to content

Commit ca71755

Browse files
committed
#97: batch/v1beta1 Cronjob is deprecated in Kubernetes version 1.25. #131: Upgrade Kubegres to use the framework Kubebuilder 3.6.0
1 parent 7d751fe commit ca71755

Some content is hidden

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

48 files changed

+2368
-1192
lines changed

.dockerignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore all files which are not go type
3-
!**/*.go
4-
!**/*.mod
5-
!**/*.sum
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/

Backlog

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,36 @@
1-
2-
- Scheduled for December 2021:
3-
- update local kind & kubectl
4-
- Build controller with Kubebuilder v3.2.0
5-
- Remove warning for CronJob which was updated from beta to stable since Kubernetes 1.21
1+
Features in order of priority:
62

73
- add a test in spec_readinessProbe_test and spec_livenessProbe_test so that
84
we test the default behaviour when no option is set from the YAML
95

10-
- Scheduled for either December 2021 or Jan 2022:
11-
- #20 : Delete PVC
6+
- #20 : Delete PVC
127

13-
- Scheduled for May 2022:
14-
- #12 : Reuse PVC (see below) and Primary becomes a Replica
8+
- #12 : Reuse PVC (see below) and Primary becomes a Replica
159

1610
As part of the available options for the field "failover.pvc", there would be:
1711
- "retain": the default option currently with Kubegres where PVC are kept but not reused for safety and investigation reasons
1812
- "delete": the PVC will be deleted
1913
- "reuse": if the state of the PVC is healthy, it will be reused by the newly created Replica pod. I think that matches with your suggestion?
2014

21-
- Scheduled for June 2022:
22-
- #?: PG bouncer
15+
- #30: Add one or many sidecar container options in Kubegres YAML
16+
17+
- #?: PG bouncer
18+
19+
- #51: add documentation about how to recover backup
20+
- add use cases documentation, for example how to expand storage manually and how to upgrade Postgres major version.
21+
- check how to setup log archiving in case of replica does not found a data
2322

24-
- Scheduled for July 2022:
25-
- #51: add documentation about how to recover backup
26-
- add use cases documentation, for example how to expand storage manually and how to upgrade Postgres major version.
27-
- check how to setup log archiving in case of replica does not found a data
23+
- #46: Define Service Type for Primary and Replica
2824

29-
- Scheduled for August 2022:
30-
- #46: Define Service Type for Primary and Replica
25+
- #7 : Allow major version upgrade using pg_upgrade
3126

32-
- Scheduled for September 2022:
33-
- #7 : Allow major version upgrade using pg_upgrade
27+
- #35 : Restore database from a PV backup
3428

35-
- Scheduled for October 2022:
36-
- #35 : Restore database from a PV backup
29+
- #82 : Allow using a unique image for the backup job
3730

38-
- Scheduled for November 2022:
39-
- #10 : Deploy Kubegres with a HELM chart
31+
- #10 : Deploy Kubegres with a HELM chart
4032

41-
- Scheduled for December 2022:
42-
- #? : Add a field to allow restarting StatefulSets and Pods via the YAML of "Kind: Kubegres"?
33+
- #? : Add a field to allow restarting StatefulSets and Pods via the YAML of "Kind: Kubegres"?
4334

4435
Blocked:
4536
#49 : Expand Storage (waiting on the Kubernetes feature: https://github.com/kubernetes/enhancements/pull/2842)

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.15 as builder
2+
FROM golang:1.18 as builder
33

44
ARG TARGETPLATFORM
55
ARG BUILDPLATFORM

Kubebuilder-cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kubebuilder init --domain reactive-tech.io --repo reactive-tech.io/kubegres
2+
kubebuilder create api --group kubegres --version v1 --kind Kubegres
3+
make manifests

Makefile

Lines changed: 81 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Image URL to use all building/pushing image targets
33
LATEST = controller:latest
44
IMG ?= $(LATEST)
5-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
6-
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
5+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
6+
ENVTEST_K8S_VERSION = 1.24.2
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+
# Setting SHELL to bash allows bash commands to be executed by recipes.
16+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
17+
SHELL = /usr/bin/env bash -o pipefail
18+
.SHELLFLAGS = -ec
19+
20+
.PHONY: all
1521
all: build
1622

1723
##@ General
@@ -27,91 +33,122 @@ all: build
2733
# More info on the awk command:
2834
# http://linuxcommand.org/lc3_adv_awk.php
2935

36+
.PHONY: help
3037
help: ## Display this help.
3138
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
3239

3340
##@ Development
3441

42+
.PHONY: manifests
3543
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
36-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
44+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
3745

46+
.PHONY: generate
3847
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
3948
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
4049

41-
fmt: ## Run go fmt against code (it formats source code).
50+
.PHONY: fmt
51+
fmt: ## Run go fmt against code.
4252
go fmt ./...
4353

44-
vet: ## Run go vet against code (it check the constructs in the code).
54+
.PHONY: vet
55+
vet: ## Run go vet against code.
4556
go vet ./...
4657

47-
test: build ## Run tests.
58+
.PHONY: test
59+
test: build envtest ## Run tests.
4860
go test $(shell pwd)/test -run $(shell pwd)/test/suite_test.go -v -test.timeout 10000s
49-
50-
#ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
51-
#test: manifests generate fmt vet ## Run tests.
52-
# mkdir -p ${ENVTEST_ASSETS_DIR}
53-
# test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
54-
# source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
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
5563

5664
##@ Build
5765

66+
.PHONY: build
5867
build: manifests generate fmt vet ## Build manager binary.
5968
go generate
6069
go build -o bin/manager main.go
6170

62-
run: install build ## Connect to a local Kubernetes cluster, install the operator and run controller
71+
.PHONY: run
72+
run: install ## Run a controller from your host.
6373
go run ./main.go
6474

6575
#docker-build: test ## Build docker image with the manager.
76+
.PHONY: docker-build-push
6677
docker-build-push: build ## Build docker image with the manager.
6778
docker buildx build --platform linux/amd64,linux/arm64 -t ${IMG} --push .
6879

80+
#.PHONY: docker-build
81+
#docker-build: test ## Build docker image with the manager.
82+
# docker build -t ${IMG} .
83+
84+
#.PHONY: docker-push
85+
#docker-push: ## Push docker image with the manager.
86+
# docker push ${IMG}
87+
6988
##@ Deployment
7089

71-
install: build kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. (by default a local Kubernetes cluster)
72-
$(KUSTOMIZE) build config/crd | kubectl apply -f -
90+
ifndef ignore-not-found
91+
ignore-not-found = false
92+
endif
7393

74-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. (by default a local Kubernetes cluster)
75-
$(KUSTOMIZE) build config/crd | kubectl delete -f -
94+
.PHONY: install
95+
install: build kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
96+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
7697

98+
.PHONY: uninstall
99+
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 -
77101

102+
.PHONY: deploy-check
78103
deploy-check:
79104
ifeq ($(IMG),$(LATEST))
80-
@echo "PLEASE PROVIDE THE ARGUMENT 'IMG' WHEN RUNNING 'make deploy'. EXAMPLE OF USAGE: 'make deploy IMG=reactivetechio/kubegres:1.89'"
105+
@echo "PLEASE PROVIDE THE ARGUMENT 'IMG' WHEN RUNNING 'make deploy'. EXAMPLE OF USAGE: 'make deploy IMG=reactivetechio/kubegres:1.16'"
81106
exit 1
82107
endif
83108
@echo "RUNNING THE ACCEPTANCE TESTS AND THEN WILL DEPLOY $(IMG) INTO DOCKER HUB."
84109

85110
## Usage: 'make deploy IMG=reactivetechio/kubegres:[version]'
86-
## eg: 'make deploy IMG=reactivetechio/kubegres:1.4'
111+
## eg: 'make deploy IMG=reactivetechio/kubegres:1.16'
87112
## Run acceptance tests then deploy into Docker Hub the controller as the Docker image provided in arg ${IMG}
88113
## and update the local file "kubegres.yaml" with the image ${IMG}
89-
deploy: deploy-check test docker-build-push kustomize
114+
.PHONY: deploy
115+
deploy: deploy-check test docker-build-push kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
90116
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
91117
$(KUSTOMIZE) build config/default > kubegres.yaml
92118
@echo "DEPLOYED $(IMG) INTO DOCKER HUB. UPDATED 'kubegres.yaml' WITH '$(IMG)'. YOU CAN COMMIT 'kubegres.yaml' AND CREATE A RELEASE IN GITHUB."
93119

94-
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
95-
$(KUSTOMIZE) build config/default | kubectl delete -f -
96-
97-
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
98-
controller-gen: ## Download controller-gen locally if necessary.
99-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
100-
101-
KUSTOMIZE = $(shell pwd)/bin/kustomize
102-
kustomize: ## Download kustomize locally if necessary.
103-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
104-
105-
# go-get-tool will 'go get' any package $2 and install it to $1.
106-
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
107-
define go-get-tool
108-
@[ -f $(1) ] || { \
109-
set -e ;\
110-
TMP_DIR=$$(mktemp -d) ;\
111-
cd $$TMP_DIR ;\
112-
go mod init tmp ;\
113-
echo "Downloading $(2)" ;\
114-
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
115-
rm -rf $$TMP_DIR ;\
116-
}
117-
endef
120+
.PHONY: undeploy
121+
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 -
123+
124+
##@ Build Dependencies
125+
126+
## Location to install dependencies to
127+
LOCALBIN ?= $(shell pwd)/bin
128+
$(LOCALBIN):
129+
mkdir -p $(LOCALBIN)
130+
131+
## Tool Binaries
132+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
133+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
134+
ENVTEST ?= $(LOCALBIN)/setup-envtest
135+
136+
## Tool Versions
137+
KUSTOMIZE_VERSION ?= v3.8.7
138+
CONTROLLER_TOOLS_VERSION ?= v0.9.2
139+
140+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
141+
.PHONY: kustomize
142+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
143+
$(KUSTOMIZE): $(LOCALBIN)
144+
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
145+
146+
.PHONY: controller-gen
147+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
148+
$(CONTROLLER_GEN): $(LOCALBIN)
149+
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
150+
151+
.PHONY: envtest
152+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
153+
$(ENVTEST): $(LOCALBIN)
154+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

api/v1/groupversion_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ limitations under the License.
1919
*/
2020

2121
// Package v1 contains API Schema definitions for the kubegres v1 API group
22-
//+kubebuilder:object:generate=true
23-
//+groupName=kubegres.reactive-tech.io
22+
// +kubebuilder:object:generate=true
23+
// +groupName=kubegres.reactive-tech.io
2424
package v1
2525

2626
import (

api/v1/kubegres_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ type KubegresStatus struct {
115115

116116
// +kubebuilder:object:root=true
117117
// +kubebuilder:subresource:status
118+
118119
// Kubegres is the Schema for the kubegres API
119120
type Kubegres struct {
120121
metav1.TypeMeta `json:",inline"`

api/v1/zz_generated.deepcopy.go

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

config/certmanager/certificate.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

config/certmanager/kustomization.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)