Skip to content

Commit

Permalink
kubebuilder v4 + dependencies upgrade (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewChubatiuk authored Jun 21, 2024
1 parent 5cef723 commit e9b2e9c
Show file tree
Hide file tree
Showing 168 changed files with 13,590 additions and 9,541 deletions.
7 changes: 3 additions & 4 deletions Dockerfile.build
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.22 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -10,12 +10,11 @@ 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/ internal/
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -trimpath -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -trimpath -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
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ e2e-local: fmt vet manifests patch_crds
$(GOCMD) tool cover -func coverage.txt | grep total

lint:
golangci-lint run --exclude '(SA1019):' -E typecheck -E gosimple -E gocritic --timeout 5m ./controllers/... ./internal/...
golint ./controllers/...
golangci-lint run --exclude '(SA1019):' -E typecheck -E gosimple -E gocritic --timeout 5m ./internal/...
golint ./internal/controller/...

.PHONY:clean
clean:
Expand All @@ -280,12 +280,12 @@ all: build
# Run tests
test: manifests generate fmt vet patch_crds
echo 'mode: atomic' > coverage.txt && \
$(TEST_ARGS) $(REPO)/controllers/... $(REPO)/api/...
$(TEST_ARGS) $(REPO)/internal/controller/... $(REPO)/api/...
$(GOCMD) tool cover -func coverage.txt | grep total

# Build manager binary
manager: fmt vet
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} $(GOBUILD) -o bin/manager main.go
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} $(GOBUILD) -o bin/manager cmd/main.go

# Run against the configured Kubernetes cluster in ~/.kube/config
run: manager
Expand Down Expand Up @@ -344,7 +344,7 @@ ifeq (, $(shell which kustomize))
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go install sigs.k8s.io/kustomize/kustomize/[email protected] ;\
go install sigs.k8s.io/kustomize/kustomize/[email protected] ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
Expand Down Expand Up @@ -397,7 +397,7 @@ docker-build-arch:
.

package-arch:
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} $(GOBUILD) -o bin/manager-$(GOARCH) main.go
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} $(GOBUILD) -o bin/manager-$(GOARCH) cmd/main.go


build-operator-crosscompile: fmt vet
Expand Down
65 changes: 48 additions & 17 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,106 +1,137 @@
# 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: victoriametrics.com
layout: go.kubebuilder.io/v2
layout:
- go.kubebuilder.io/v4
projectName: victoriametrics-operator
repo: github.com/VictoriaMetrics/operator
resources:
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMAgent
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMAlert
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMAlertmanager
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMAlertmanagerConfig
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMPodScrape
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMRule
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMServiceScrape
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMSingle
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMCluster
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMProbe
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMNodeScrape
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMStaticScrape
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMUser
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
-
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMAuth
path: github.com/VictoriaMetrics/operator/api/v1beta1
version: v1beta1
version: "3"
plugins:
go.operator-sdk.io/v2-alpha: {}
File renamed without changes.
4 changes: 2 additions & 2 deletions config/certmanager/certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# More document can be found at https://docs.cert-manager.io
# WARNING: Targets CertManager 0.11 check https://docs.cert-manager.io/en/latest/tasks/upgrading/index.html for
# breaking changes
apiVersion: cert-manager.io/v1alpha2
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: selfsigned-issuer
namespace: system
spec:
selfSigned: {}
---
apiVersion: cert-manager.io/v1alpha2
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ spec:
name: https
- name: manager
args:
- "--metrics-addr=127.0.0.1:8080"
- "--metrics-bind-address=127.0.0.1:8080"
4 changes: 2 additions & 2 deletions config/deployments/webhook/webhookcainjection_patch.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This patch add annotation to admission webhook config and
# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize.
#apiVersion: admissionregistration.k8s.io/v1beta1
#apiVersion: admissionregistration.k8s.io/v1
#kind: MutatingWebhookConfiguration
#metadata:
# name: mutating-webhook-configuration
# annotations:
# cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
---
apiVersion: admissionregistration.k8s.io/v1beta1
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: validating-webhook-configuration
Expand Down
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
command:
- manager
args:
- "--enable-leader-election"
- "--leader-elect"
image: manager
env:
- name: WATCH_NAMESPACE
Expand Down
33 changes: 33 additions & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- vmuser_editor_role.yaml
- vmuser_viewer_role.yaml
- vmauth_editor_role.yaml
- vmauth_viewer_role.yaml
- vmstaticscrape_editor_role.yaml
- vmstaticscrape_viewer_role.yaml
- vmnodescrape_editor_role.yaml
- vmnodescrape_viewer_role.yaml
- vmprobe_editor_role.yaml
- vmprobe_viewer_role.yaml
- vmcluster_editor_role.yaml
- vmcluster_viewer_role.yaml
- vmsingle_editor_role.yaml
- vmsingle_viewer_role.yaml
- vmservicescrape_editor_role.yaml
- vmservicescrape_viewer_role.yaml
- vmrule_editor_role.yaml
- vmrule_viewer_role.yaml
- vmpodscrape_editor_role.yaml
- vmpodscrape_viewer_role.yaml
- vmalertmanagerconfig_editor_role.yaml
- vmalertmanagerconfig_viewer_role.yaml
- vmalertmanager_editor_role.yaml
- vmalertmanager_viewer_role.yaml
- vmalert_editor_role.yaml
- vmalert_viewer_role.yaml
- vmagent_editor_role.yaml
- vmagent_viewer_role.yaml

# Comment the following 4 lines if you want to disable
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
# which protects your /metrics endpoint.
Expand All @@ -20,3 +49,7 @@ patches:
- path: service_account_patch.yaml
target:
name: vm-operator-manager-rolebinding
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
# if you do not want those helpers be installed with your Project.
27 changes: 27 additions & 0 deletions config/rbac/vmcluster_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to edit vmclusters.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: victoriametrics-operator
app.kubernetes.io/managed-by: kustomize
name: vmcluster-editor-role
rules:
- apiGroups:
- operator.victoriametrics.com
resources:
- vmclusters
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- operator.victoriametrics.com
resources:
- vmclusters/status
verbs:
- get
23 changes: 23 additions & 0 deletions config/rbac/vmcluster_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# permissions for end users to view vmclusters.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: victoriametrics-operator
app.kubernetes.io/managed-by: kustomize
name: vmcluster-viewer-role
rules:
- apiGroups:
- operator.victoriametrics.com
resources:
- vmclusters
verbs:
- get
- list
- watch
- apiGroups:
- operator.victoriametrics.com
resources:
- vmclusters/status
verbs:
- get
2 changes: 1 addition & 1 deletion config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ resources:
- operator_v1beta1_vmstaticscrape.yaml
- operator_v1beta1_vmuser.yaml
- operator_v1beta1_vmauth.yaml
- operator_v1beta1_vmalertmanagerconfig.yaml
- operator_v1beta1_vmalertmanagerconfig.yaml
9 changes: 9 additions & 0 deletions config/samples/operator_v1beta1_vmagent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMAgent
metadata:
labels:
app.kubernetes.io/name: victoriametrics-operator
app.kubernetes.io/managed-by: kustomize
name: vmagent-sample
spec:
# TODO(user): Add fields here
9 changes: 9 additions & 0 deletions config/samples/operator_v1beta1_vmalert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMAlert
metadata:
labels:
app.kubernetes.io/name: victoriametrics-operator
app.kubernetes.io/managed-by: kustomize
name: vmalert-sample
spec:
# TODO(user): Add fields here
Loading

0 comments on commit e9b2e9c

Please sign in to comment.