Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade kubebuilder scaffold to v3 #89

Merged
merged 34 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f5e9a43
refactor: changed Kubebuilder to v4 and scaffold to go/v4
Aug 15, 2023
3cb9d35
feat: implemented retry function
Aug 15, 2023
44b5260
refactor: improved cache retry logic
Aug 15, 2023
a76650b
chore: added project related configs
Aug 15, 2023
c0f1a7d
chore: improved loadCache retry logic
Aug 15, 2023
c42228d
chore: added missing controller test setup
Aug 15, 2023
fe15f05
chore: added additional Makefile steps
Aug 15, 2023
9e9024b
chore: updated sample secrets
Aug 15, 2023
170daa7
chore: updated auto generated K8s manifests
Aug 15, 2023
e8dd837
chore: removed unused files
Aug 15, 2023
8a7f9d0
chore: updated CODEOWNERS
Aug 15, 2023
f2fd422
chore: changed webhook targests for v1alpha1 and v1alpha2 versions
Aug 15, 2023
000f26e
chore: changed test to target v1alpha1 instead of mixed v1alpha1 --> …
Aug 15, 2023
d2d62f9
chore: added script to generate ssl certificates
Aug 15, 2023
d7824bd
fix: file line endings
Aug 15, 2023
f694a50
chore: re-added needed changes to controller deployments files
Aug 15, 2023
e4132d7
fix: always reset secret fields on change
Aug 15, 2023
b8a08ca
chore: improved re-login when cache loading did not succeed
Aug 15, 2023
41a214d
chore: improved reconciling
Aug 15, 2023
9ce4763
feat: added custom metrics to get more insights in passbolt requests
Aug 15, 2023
f38b2b4
chore: improved docker build ignores
Aug 15, 2023
4749f32
chore: changed CI kind node images matrix range from 1.24 - 1.27
Aug 15, 2023
3e46c3f
fix: added missing conversion review versions
Aug 15, 2023
34ee748
chore(ci): install prometheus operator CRDs
Aug 15, 2023
a4ca464
docs: added prometheus operator crds and cert-manager to the requirem…
Aug 15, 2023
f31d2c8
chore: added missing patch for local deploys
Aug 16, 2023
b25a14f
fix(ci): bump go to 1.20 and fix namespace name ref
Aug 16, 2023
5f63148
chore: changed binary name to controller
Aug 16, 2023
33f21c2
fix: apply -f error caused by kustomize file
Aug 16, 2023
82ed847
chore: improved error message for failed cache updates
Aug 16, 2023
c44cedf
chore: improved operator reconciliation start and stop message
Aug 18, 2023
5366312
chore: improved reconciliation status update for non changed secrets
Aug 18, 2023
31bdde0
fix: removed beginning blank line in .gitignore
Aug 29, 2023
ebb8dc3
chore: removed charts/** from paths-ignore
Aug 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
**
!controllers/
!api/
!pkg/
!go.mod
!go.sum
!main.go

# folders
_data/
.github/
bin/
config/
e2e/
hack/

# files
.envrc
.gitignore
.goreleaser.yaml
CODE_OF_CONDUCT.md
docker-compose.yaml
Dockerfile
Dockerfile.dev
LICENSE
Makefile
PROJECT.md
README.md
SECURITY.md
13 changes: 0 additions & 13 deletions .gitattributes

This file was deleted.

2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners

* @leonsteinhaeuser
* @urbanmedia/platform @urbanmedia/unitb-platform
20 changes: 12 additions & 8 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:
- "!dependabot/**"

env:
go_version: 1.19
go_version: '1.20'
artifact_name: passbolt-operator
artifact_bin_name: kubebuilder
IMG: tagesspiegel/passbolt-operator:dev
Expand Down Expand Up @@ -214,17 +214,15 @@ jobs:
- build-temp-image
- prepare-bin
env:
KUBERNETES_NAMESPACE: kubernetes-passbolt-operator-system
KUBERNETES_NAMESPACE: passbolt-operator-system
strategy:
fail-fast: false
matrix:
kind_node_image:
- kindest/node:v1.26.0
- kindest/node:v1.25.3
- kindest/node:v1.24.7
- kindest/node:v1.23.13
- kindest/node:v1.22.15
- kindest/node:v1.21.14
- kindest/node:v1.27.3
- kindest/node:v1.26.6
- kindest/node:v1.25.11
- kindest/node:v1.24.15
steps:
- name: Install go ${{ env.go_version }}
uses: actions/setup-go@v4
Expand Down Expand Up @@ -294,6 +292,12 @@ jobs:
- name: Start the other containers
run: docker-compose up -d

- name: Install Prometheus Operator CRDs
run: |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus-operator-crds prometheus-community/prometheus-operator-crds

- name: Install cert-manager
run: |
helm repo add jetstack https://charts.jetstack.io
Expand Down
18 changes: 13 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@
*.dll
*.so
*.dylib
bin/
Dockerfile.cross

# Test binary, built with `go test -c`
# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
# Kubernetes Generated files - skip generated files, except for vendored files

bin/
!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
.vscode
*.swp
*.swo
*~

.env
.envrc

dist/
generated/
generated/
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ before:

builds:
- id: controller
main: main.go
main: cmd/main.go
binary: controller
env:
- CGO_ENABLED=0
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY controller /controller
USER 65532:65532
ENTRYPOINT ["/controller"]
ENTRYPOINT ["/controller"]
10 changes: 3 additions & 7 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@ WORKDIR /workspace
# Copy the go source
ADD . .

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Build
# 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 main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o controller cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Use distroless as minimal base image to package the controller binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager controller
COPY --from=builder /workspace/controller .
USER 65532:65532

ENTRYPOINT ["/controller"]
52 changes: 29 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Image URL to use all building/pushing image targets
IMG ?= tagesspiegel/passbolt-operator:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0
ENVTEST_K8S_VERSION = 1.27.1
E2E_APPLY_WAIT_DURATION ?= 10
KIND_CLUSTER_NAME ?= passbolt-operator

Expand All @@ -13,6 +13,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 Down Expand Up @@ -58,15 +64,15 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out -covermode=atomic
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

.PHONY: coverhtml
coverhtml: ## Display test coverage in html
go tool cover -html=cover.out

.PHONY: test-e2e
test-e2e: ## Run e2e tests.
kubectl apply -f config/samples/
kubectl apply -k config/samples/
sleep ${E2E_APPLY_WAIT_DURATION}
./e2e/run.sh

Expand All @@ -77,12 +83,12 @@ kind-load: ## Load docker image into kind cluster
##@ Build

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

.PHONY: run
run: manifests generate certs fmt vet ## Run a controller from your host.
go run ./main.go
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go

# If you wish built 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.
Expand Down Expand Up @@ -128,25 +134,20 @@ endif

.PHONY: install
install: manifests 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
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

raw: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default > deploy.raw.yaml

$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -

.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 -

.PHONY: generate-manifests
generate-manifests: manifests kustomize ## Generate manifests and store them in the generated folder
Expand All @@ -163,24 +164,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.0.1
CONTROLLER_TOOLS_VERSION ?= v0.12.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 -Ss $(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
10 changes: 7 additions & 3 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: tagesspiegel.de
layout:
- go.kubebuilder.io/v3
projectName: kubernetes-passbolt-operator
- go.kubebuilder.io/v4
projectName: passbolt-operator
repo: github.com/urbanmedia/passbolt-operator
resources:
- api:
Expand All @@ -20,7 +20,11 @@ resources:
webhooks:
conversion: true
webhookVersion: v1
- domain: tagesspiegel.de
- api:
crdVersion: v1
namespaced: true
controller: true
domain: tagesspiegel.de
group: passbolt
kind: PassboltSecret
path: github.com/urbanmedia/passbolt-operator/api/v1alpha2
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ The Passbolt Operator can be configured with the following environement variable
- [Kubectl](https://kubernetes.io/docs/tasks/tools/) >= v1.25
- [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/) >= v0.17
- mysql-client >= 15.1 (`mysql --version` => `mysql Ver 15.1 Distrib 10.6.11-MariaDB`)
- [Prometheus Operator CRDs installed in the cluster](https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-operator-crds) >= 5.1
- [cert-manager](https://cert-manager.io/docs/installation/helm/) >= v1.12

### Setup the development environment

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 @ Verlag Der Tagesspiegel GmbH
Copyright 2023 Verlag der Tagesspiegel GmbH.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/passboltsecret_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 @ Verlag Der Tagesspiegel GmbH
Copyright 2023 Verlag der Tagesspiegel GmbH.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions api/v1alpha1/passboltsecret_webhook.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 @ Verlag Der Tagesspiegel GmbH
Copyright 2023 Verlag der Tagesspiegel GmbH.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,6 @@ import (
var passboltsecretlog = logf.Log.WithName("passboltsecret-resource")

func (r *PassboltSecret) SetupWebhookWithManager(mgr ctrl.Manager) error {
passboltsecretlog.V(10).Info("setting up webhook", "version", "v1alpha1")
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
Expand Down
Loading