Skip to content

Commit

Permalink
feat: upgrade kubebuilder version (#500)
Browse files Browse the repository at this point in the history
Upgrade kubebuilder to version 3.5.0 along with a couple of other
tools that need to be upgraded.

This upgrade will allow to work with multi-group APIs in the future
if we need it and also to new comers that know kubebuilder 3.x to
join to the project in the future.

Closes #482

Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com>
  • Loading branch information
sxd committed Aug 2, 2022
1 parent c949828 commit bdd7e3e
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 92 deletions.
48 changes: 32 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ POSTGRES_IMAGE_NAME ?= ghcr.io/cloudnative-pg/postgresql:14
KUSTOMIZE_VERSION ?= v4.5.2
KIND_CLUSTER_NAME ?= pg
KIND_CLUSTER_VERSION ?= v1.24.2
CONTROLLER_TOOLS_VERSION ?= v0.9.2
GORELEASER_VERSION ?= v1.10.3

export CONTROLLER_IMG
export BUILD_IMAGE
Expand Down Expand Up @@ -79,7 +81,6 @@ help: ## Display this help.
##@ Development

ENVTEST_ASSETS_DIR=$$(pwd)/testbin

test: generate fmt vet manifests ## Run tests.
mkdir -p ${ENVTEST_ASSETS_DIR} ;\
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest ;\
Expand Down Expand Up @@ -120,13 +121,13 @@ deploy: manifests kustomize ## Deploy controller in the configured Kubernetes cl
CONFIG_TMP_DIR=$$(mktemp -d) ;\
cp -r config/* $$CONFIG_TMP_DIR ;\
{ \
cd $$CONFIG_TMP_DIR/default ;\
$(KUSTOMIZE) edit add patch --path manager_image_pull_secret.yaml ;\
cd $$CONFIG_TMP_DIR/manager ;\
$(KUSTOMIZE) edit set image controller="${CONTROLLER_IMG}" ;\
$(KUSTOMIZE) edit add patch --path env_override.yaml ;\
$(KUSTOMIZE) edit add configmap controller-manager-env \
--from-literal="POSTGRES_IMAGE_NAME=${POSTGRES_IMAGE_NAME}" ;\
cd $$CONFIG_TMP_DIR/default ;\
$(KUSTOMIZE) edit add patch --path manager_image_pull_secret.yaml ;\
cd $$CONFIG_TMP_DIR/manager ;\
$(KUSTOMIZE) edit set image controller="${CONTROLLER_IMG}" ;\
$(KUSTOMIZE) edit add patch --path env_override.yaml ;\
$(KUSTOMIZE) edit add configmap controller-manager-env \
--from-literal="POSTGRES_IMAGE_NAME=${POSTGRES_IMAGE_NAME}" ;\
} ;\
$(KUSTOMIZE) build $$CONFIG_TMP_DIR/default | kubectl apply -f - ;\
rm -fr $$CONFIG_TMP_DIR
Expand Down Expand Up @@ -193,25 +194,40 @@ apidoc: k8s-api-docgen ## Update the API Reference section of the documentation.

##@ Tools

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

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

KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

KUSTOMIZE = $(LOCALBIN)/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@$(KUSTOMIZE_VERSION))

K8S_API_DOCGEN = $(shell pwd)/bin/k8s-api-docgen
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

K8S_API_DOCGEN = $(LOCALBIN)/k8s-api-docgen
k8s-api-docgen: ## Download k8s-api-docgen locally if necessary.
$(call go-install-tool,$(K8S_API_DOCGEN),github.com/EnterpriseDB/k8s-api-docgen/cmd/k8s-api-docgen@latest)

GO_LICENSES = $(shell pwd)/bin/go-licenses
GO_LICENSES = $(LOCALBIN)/go-licenses
go-licenses: ## Download go-licenses locally if necessary.
$(call go-install-tool,$(GO_LICENSES),github.com/google/go-licenses@latest)

GO_RELEASER = $(shell pwd)/bin/goreleaser
GO_RELEASER = $(LOCALBIN)/goreleaser
go-releaser: ## Download go-releaser locally if necessary.
$(call go-install-tool,$(GO_RELEASER),github.com/goreleaser/goreleaser@v1.8.3)
$(call go-install-tool,$(GO_RELEASER),github.com/goreleaser/goreleaser@$(GORELEASER_VERSION))

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
# go-install-tool will 'go install' any package $2 and install it to $1.
Expand Down
53 changes: 48 additions & 5 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
domain: cnpg.io
layout:
- go.kubebuilder.io/v3
projectName: cloudnative-pg-kubebuilderv3
repo: github.com/cloudnative-pg/cloudnative-pg
resources:
- group: postgresql
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cnpg.io
group: postgresql
kind: Cluster
path: github.com/cloudnative-pg/cloudnative-pg/api/v1
version: v1
- group: postgresql
webhooks:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cnpg.io
group: postgresql
kind: Backup
path: github.com/cloudnative-pg/cloudnative-pg/api/v1
version: v1
- group: postgresql
webhooks:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cnpg.io
group: postgresql
kind: ScheduledBackup
path: github.com/cloudnative-pg/cloudnative-pg/api/v1
version: v1
- group: postgresql
webhooks:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: cnpg.io
group: postgresql
kind: Pooler
path: github.com/cloudnative-pg/cloudnative-pg/api/v1
version: v1
version: "2"
webhooks:
defaulting: true
validation: true
webhookVersion: v1
version: "3"
9 changes: 1 addition & 8 deletions config/crd/bases/postgresql.cnpg.io_backups.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: backups.postgresql.cnpg.io
spec:
Expand Down Expand Up @@ -295,9 +294,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
44 changes: 26 additions & 18 deletions config/crd/bases/postgresql.cnpg.io_clusters.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: clusters.postgresql.cnpg.io
spec:
Expand Down Expand Up @@ -135,6 +134,7 @@ spec:
The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
namespaceSelector:
description: A label query over the set of namespaces
that the term applies to. The term is applied
Expand Down Expand Up @@ -191,6 +191,7 @@ spec:
The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
namespaces:
description: namespaces specifies a static list
of namespace names that the term applies to. The
Expand Down Expand Up @@ -289,6 +290,7 @@ spec:
requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
namespaceSelector:
description: A label query over the set of namespaces
that the term applies to. The term is applied to the
Expand Down Expand Up @@ -340,6 +342,7 @@ spec:
requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
namespaces:
description: namespaces specifies a static list of namespace
names that the term applies to. The term is applied
Expand Down Expand Up @@ -441,6 +444,7 @@ spec:
The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
namespaceSelector:
description: A label query over the set of namespaces
that the term applies to. The term is applied
Expand Down Expand Up @@ -497,6 +501,7 @@ spec:
The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
namespaces:
description: namespaces specifies a static list
of namespace names that the term applies to. The
Expand Down Expand Up @@ -595,6 +600,7 @@ spec:
requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
namespaceSelector:
description: A label query over the set of namespaces
that the term applies to. The term is applied to the
Expand Down Expand Up @@ -646,6 +652,7 @@ spec:
requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
namespaces:
description: namespaces specifies a static list of namespace
names that the term applies to. The term is applied
Expand Down Expand Up @@ -1634,6 +1641,7 @@ spec:
required:
- key
type: object
x-kubernetes-map-type: atomic
sslCert:
description: The reference to an SSL certificate to be used
to connect to this instance
Expand All @@ -1653,6 +1661,7 @@ spec:
required:
- key
type: object
x-kubernetes-map-type: atomic
sslKey:
description: The reference to an SSL private key to be used
to connect to this instance
Expand All @@ -1672,6 +1681,7 @@ spec:
required:
- key
type: object
x-kubernetes-map-type: atomic
sslRootCert:
description: The reference to an SSL CA public key to be used
to connect to this instance
Expand All @@ -1691,6 +1701,7 @@ spec:
required:
- key
type: object
x-kubernetes-map-type: atomic
required:
- name
type: object
Expand Down Expand Up @@ -1882,6 +1893,7 @@ spec:
required:
- key
type: object
x-kubernetes-map-type: atomic
searchAttribute:
description: Attribute to match against the username
type: string
Expand Down Expand Up @@ -2066,6 +2078,7 @@ spec:
- kind
- name
type: object
x-kubernetes-map-type: atomic
dataSourceRef:
description: 'dataSourceRef specifies the object from which
to populate the volume with data, if a non-empty volume
Expand All @@ -2081,10 +2094,10 @@ spec:
if one of them is empty and the other is non-empty. There
are two important differences between DataSource and DataSourceRef:
* While DataSource only allows two specific types of objects,
DataSourceRef allows any non-core object, as well as PersistentVolumeClaim
DataSourceRef allows any non-core object, as well as PersistentVolumeClaim
objects. * While DataSource ignores disallowed values (dropping
them), DataSourceRef preserves all values, and generates
an error if a disallowed value is specified. (Beta) Using
them), DataSourceRef preserves all values, and generates
an error if a disallowed value is specified. (Beta) Using
this field requires the AnyVolumeDataSource feature gate
to be enabled.'
properties:
Expand All @@ -2104,6 +2117,7 @@ spec:
- kind
- name
type: object
x-kubernetes-map-type: atomic
resources:
description: 'resources represents the minimum resources the
volume should have. If RecoverVolumeExpansionFailure feature
Expand Down Expand Up @@ -2182,6 +2196,7 @@ spec:
only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
storageClassName:
description: 'storageClassName is the name of the StorageClass
required by the claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1'
Expand Down Expand Up @@ -2305,13 +2320,12 @@ spec:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are:
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
type FooStatus struct{ // Represents the observations of a foo's
current state. // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
// +listType=map // +listMapKey=type Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down Expand Up @@ -2567,9 +2581,3 @@ spec:
specReplicasPath: .spec.instances
statusReplicasPath: .status.instances
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

0 comments on commit bdd7e3e

Please sign in to comment.