Skip to content

Commit

Permalink
#97: batch/v1beta1 Cronjob is deprecated in Kubernetes version 1.25. #…
Browse files Browse the repository at this point in the history
…131: Upgrade Kubegres to use the framework Kubebuilder 3.6.0
  • Loading branch information
alex-arica committed Sep 20, 2022
1 parent 7d751fe commit ca71755
Show file tree
Hide file tree
Showing 48 changed files with 2,368 additions and 1,192 deletions.
7 changes: 3 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore all files which are not go type
!**/*.go
!**/*.mod
!**/*.sum
# Ignore build and test binaries.
bin/
testbin/
41 changes: 16 additions & 25 deletions Backlog
Original file line number Diff line number Diff line change
@@ -1,45 +1,36 @@

- Scheduled for December 2021:
- update local kind & kubectl
- Build controller with Kubebuilder v3.2.0
- Remove warning for CronJob which was updated from beta to stable since Kubernetes 1.21
Features in order of priority:

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

- Scheduled for either December 2021 or Jan 2022:
- #20 : Delete PVC
- #20 : Delete PVC

- Scheduled for May 2022:
- #12 : Reuse PVC (see below) and Primary becomes a Replica
- #12 : Reuse PVC (see below) and Primary becomes a Replica

As part of the available options for the field "failover.pvc", there would be:
- "retain": the default option currently with Kubegres where PVC are kept but not reused for safety and investigation reasons
- "delete": the PVC will be deleted
- "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?

- Scheduled for June 2022:
- #?: PG bouncer
- #30: Add one or many sidecar container options in Kubegres YAML

- #?: PG bouncer

- #51: add documentation about how to recover backup
- add use cases documentation, for example how to expand storage manually and how to upgrade Postgres major version.
- check how to setup log archiving in case of replica does not found a data

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

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

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

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

- Scheduled for November 2022:
- #10 : Deploy Kubegres with a HELM chart
- #10 : Deploy Kubegres with a HELM chart

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

Blocked:
#49 : Expand Storage (waiting on the Kubernetes feature: https://github.com/kubernetes/enhancements/pull/2842)
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.15 as builder
FROM golang:1.18 as builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM
Expand Down
3 changes: 3 additions & 0 deletions Kubebuilder-cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kubebuilder init --domain reactive-tech.io --repo reactive-tech.io/kubegres
kubebuilder create api --group kubegres --version v1 --kind Kubegres
make manifests
125 changes: 81 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Image URL to use all building/pushing image targets
LATEST = controller:latest
IMG ?= $(LATEST)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.2

# 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

# 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
.SHELLFLAGS = -ec

.PHONY: all
all: build

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

.PHONY: help
help: ## Display this help.
@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)

##@ Development

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

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

fmt: ## Run go fmt against code (it formats source code).
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

vet: ## Run go vet against code (it check the constructs in the code).
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

test: build ## Run tests.
.PHONY: test
test: build envtest ## Run tests.
go test $(shell pwd)/test -run $(shell pwd)/test/suite_test.go -v -test.timeout 10000s

#ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
#test: manifests generate fmt vet ## Run tests.
# mkdir -p ${ENVTEST_ASSETS_DIR}
# 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
# source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
#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

##@ Build

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

run: install build ## Connect to a local Kubernetes cluster, install the operator and run controller
.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 .

#.PHONY: docker-build
#docker-build: test ## Build docker image with the manager.
# docker build -t ${IMG} .

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

##@ Deployment

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

uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. (by default a local Kubernetes cluster)
$(KUSTOMIZE) build config/crd | kubectl delete -f -
.PHONY: install
install: build kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(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 -

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

## Usage: 'make deploy IMG=reactivetechio/kubegres:[version]'
## eg: 'make deploy IMG=reactivetechio/kubegres:1.4'
## eg: 'make deploy IMG=reactivetechio/kubegres:1.16'
## 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}
deploy: deploy-check test docker-build-push kustomize
.PHONY: deploy
deploy: deploy-check test docker-build-push 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."

undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
.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 -

##@ Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
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_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || 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.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
4 changes: 2 additions & 2 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ limitations under the License.
*/

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

import (
Expand Down
1 change: 1 addition & 0 deletions api/v1/kubegres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type KubegresStatus struct {

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

// Kubegres is the Schema for the kubegres API
type Kubegres struct {
metav1.TypeMeta `json:",inline"`
Expand Down
3 changes: 2 additions & 1 deletion api/v1/zz_generated.deepcopy.go

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

25 changes: 0 additions & 25 deletions config/certmanager/certificate.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions config/certmanager/kustomization.yaml

This file was deleted.

16 changes: 0 additions & 16 deletions config/certmanager/kustomizeconfig.yaml

This file was deleted.

Loading

0 comments on commit ca71755

Please sign in to comment.