Skip to content

Commit

Permalink
Migrate to kubebuilder v4 (#1355)
Browse files Browse the repository at this point in the history
* update licenses

* migrate project to kubebuilder v4

* post-merge fixes

* fix licenses

* fix check-operator dockerfile

* migrate deprecated kustomization fields

* comment out v1alpha1 resources/patches

* post-merge fix

* fix generated files

---------

Co-authored-by: levan-m <116471169+levan-m@users.noreply.github.com>
Co-authored-by: Levan Machablishvili <levan.machablishvili@datadoghq.com>
  • Loading branch information
3 people committed Sep 4, 2024
1 parent 9d154ce commit 010c848
Show file tree
Hide file tree
Showing 323 changed files with 2,223 additions and 1,244 deletions.
10 changes: 5 additions & 5 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ README.md @DataDog/documentation @DataDog/container-ecosystems


# Features owners
/controllers/datadogagent/feature/admissioncontroller/* @DataDog/container-platform
/controllers/datadogagent/feature/prometheusscrape/* @DataDog/container-platform
/controllers/datadogagent/feature/clusterchecks/* @DataDog/container-platform
/controllers/datadogagent/feature/kubernetesstatecore/* @DataDog/container-integrations
/controllers/datadogagent/feature/helmcheck/* @DataDog/container-integrations
/internal/controller/datadogagent/feature/admissioncontroller/* @DataDog/container-platform
/internal/controller/datadogagent/feature/prometheusscrape/* @DataDog/container-platform
/internal/controller/datadogagent/feature/clusterchecks/* @DataDog/container-platform
/internal/controller/datadogagent/feature/kubernetesstatecore/* @DataDog/container-integrations
/internal/controller/datadogagent/feature/helmcheck/* @DataDog/container-integrations
42 changes: 18 additions & 24 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
[run]
deadline = "5m"
tests = false
skip-dirs = [
".cache",
"go/pkg/mod",
"pkg/mod",
]

[linters-settings]

[linters-settings.govet]
check-shadowing = true
enable = [
"shadow"
]

[linters-settings.gocyclo]
min-complexity = 12.0

[linters-settings.maligned]
suggest-new = true

[linters-settings.goconst]
min-len = 3.0
min-occurrences = 3.0
Expand All @@ -26,7 +20,9 @@
locale = "US"

[linters-settings.gci]
local-prefixes = "github.com/DataDog/datadog-operator"
sections = [
"prefix(github.com/DataDog/datadog-operator)"
]

[linters-settings.godot]
exclude = [
Expand All @@ -37,15 +33,12 @@
enable-all = true
disable = [
"exhaustruct",
"nosnakecase",
"logrlint",
"nonamedreturns",
"maligned",
"revive",
"lll",
"gas",
"gosec",
"dupl",
"scopelint",
"execinquery",
"gocyclo",
"gochecknoinits",
"gochecknoglobals",
Expand All @@ -54,16 +47,14 @@
"cyclop",
"gomnd",
"wrapcheck",
"exhaustivestruct",
"forcetypeassert",
"goerr113",
"err113",
"testpackage",
"wastedassign",
"thelper",
"paralleltest",
"nestif",
"exhaustive",
"interfacer",
"gci",
"wsl",
"godox",
Expand All @@ -76,11 +67,9 @@
"nilnil",
"ireturn",
"maintidx",
"ifshort",
"gocritic",
"errchkjson",
"gofumpt",
"golint",
"stylecheck",
"staticcheck",
"whitespace",
Expand All @@ -94,9 +83,6 @@
"goconst",
"errcheck",
"misspell",
"varcheck",
"structcheck",
"deadcode",
"rowserrcheck",
"sqlclosecheck",
"depguard",
Expand All @@ -105,10 +91,18 @@
"nakedret",
"gomoddirectives",
"dupword",
"intrange",
"mnd",
"musttag"
]

[issues]
exclude-use-default = false
max-per-linter = 0
max-same-issues = 0
exclude = []
exclude = []
exclude-dirs = [
".cache",
"go/pkg/mod",
"pkg/mod",
]
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY apis/ apis/
COPY controllers/ controllers/
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY pkg/ pkg/
COPY cmd/helpers/ cmd/helpers/

# Build
ARG LDFLAGS
ARG GOARCH
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} GO111MODULE=on go build -a -ldflags "${LDFLAGS}" -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} GO111MODULE=on go build -a -ldflags "${LDFLAGS}" -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} GO111MODULE=on go build -a -ldflags "${LDFLAGS}" -o helpers cmd/helpers/main.go

FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
Expand Down
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ $(CONTROLLER_GEN): Makefile ## Download controller-gen locally if necessary.

KUSTOMIZE = bin/$(PLATFORM)/kustomize
$(KUSTOMIZE): Makefile ## Download kustomize locally if necessary.
$(call go-get-tool,$@,sigs.k8s.io/kustomize/kustomize/v4@v4.5.7)
$(call go-get-tool,$@,sigs.k8s.io/kustomize/kustomize/v5@v5.4.3)

ENVTEST = bin/$(PLATFORM)/setup-envtest
$(ENVTEST): Makefile ## Download envtest-setup locally if necessary.
Expand All @@ -110,17 +110,17 @@ endef

.PHONY: manager
manager: generate lint managergobuild ## Build manager binary
go build -ldflags '${LDFLAGS}' -o bin/$(PLATFORM)/manager main.go
go build -ldflags '${LDFLAGS}' -o bin/$(PLATFORM)/manager cmd/main.go
managergobuild: ## Builds only manager go binary
go build -ldflags '${LDFLAGS}' -o bin/$(PLATFORM)/manager main.go
go build -ldflags '${LDFLAGS}' -o bin/$(PLATFORM)/manager cmd/main.go

##@ Deploy

manager: generate lint managergobuild ## Build manager binary

.PHONY: run
run: generate lint manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
go run ./main.go
go run ./cmd/main.go

.PHONY: install
install: manifests $(KUSTOMIZE) ## Install CRDs into a cluster
Expand All @@ -144,11 +144,11 @@ manifests: generate-manifests patch-crds ## Generate manifestcd s e.g. CRD, RBAC

.PHONY: generate-manifests
generate-manifests: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role paths="./apis/..." paths="./controllers/..." output:crd:artifacts:config=config/crd/bases/v1
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role paths="./api/..." paths="./internal/controller/..." output:crd:artifacts:config=config/crd/bases/v1

.PHONY: generate
generate: $(CONTROLLER_GEN) generate-openapi generate-docs ## Generate code
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./apis/..."
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."

.PHONY: generate-docs
generate-docs: manifests
Expand Down Expand Up @@ -202,11 +202,11 @@ gotest:

.PHONY: integration-tests
integration-tests: $(ENVTEST) ## Run tests.
KUBEBUILDER_ASSETS="$(ROOT)/bin/$(PLATFORM)/" go test --tags=integration github.com/DataDog/datadog-operator/controllers -coverprofile cover_integration_v1.out
KUBEBUILDER_ASSETS="$(ROOT)/bin/$(PLATFORM)/" go test --tags=integration github.com/DataDog/datadog-operator/internal/controller -coverprofile cover_integration_v1.out

.PHONY: integration-tests-v2
integration-tests-v2: $(ENVTEST) ## Run tests with reconciler V2
KUBEBUILDER_ASSETS="$(ROOT)/bin/$(PLATFORM)/" go test --tags=integration_v2 github.com/DataDog/datadog-operator/controllers -coverprofile cover_integration_v2.out
KUBEBUILDER_ASSETS="$(ROOT)/bin/$(PLATFORM)/" go test --tags=integration_v2 github.com/DataDog/datadog-operator/internal/controller -coverprofile cover_integration_v2.out

.PHONY: e2e-tests
e2e-tests: manifests $(KUSTOMIZE) ## Run E2E tests and destroy environment stacks after tests complete. To run locally, complete pre-reqs (see docs/how-to-contribute.md) and prepend command with `aws-vault exec sso-agent-sandbox-account-admin --`. E.g. `aws-vault exec sso-agent-sandbox-account-admin -- make e2e-tests`.
Expand All @@ -218,7 +218,7 @@ e2e-tests-keep-stacks: manifests $(KUSTOMIZE) ## Run E2E tests and keep environm

.PHONY: bundle
bundle: bin/$(PLATFORM)/operator-sdk bin/$(PLATFORM)/yq $(KUSTOMIZE) manifests ## Generate bundle manifests and metadata, then validate generated files.
bin/$(PLATFORM)/operator-sdk generate kustomize manifests --apis-dir ./apis -q
bin/$(PLATFORM)/operator-sdk generate kustomize manifests --apis-dir ./api -q
cd config/manager && $(ROOT)/$(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | bin/$(PLATFORM)/operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
hack/patch-bundle.sh
Expand Down Expand Up @@ -286,8 +286,8 @@ install-tools: bin/$(PLATFORM)/golangci-lint bin/$(PLATFORM)/operator-sdk bin/$(

.PHONY: generate-openapi
generate-openapi: bin/$(PLATFORM)/openapi-gen
bin/$(PLATFORM)/openapi-gen --logtostderr=true -o "./" -i ./apis/datadoghq/v1alpha1 -O zz_generated.openapi -p ./apis/datadoghq/v1alpha1 -h ./hack/boilerplate.go.txt -r "-"
bin/$(PLATFORM)/openapi-gen --logtostderr=true -o "./" -i ./apis/datadoghq/v2alpha1 -O zz_generated.openapi -p ./apis/datadoghq/v2alpha1 -h ./hack/boilerplate.go.txt -r "-"
bin/$(PLATFORM)/openapi-gen --logtostderr=true -o "." -i ./api/datadoghq/v1alpha1 -O zz_generated.openapi -p ./api/datadoghq/v1alpha1 -h ./hack/boilerplate.go.txt -r "-"
bin/$(PLATFORM)/openapi-gen --logtostderr=true -o "." -i ./api/datadoghq/v2alpha1 -O zz_generated.openapi -p ./api/datadoghq/v2alpha1 -h ./hack/boilerplate.go.txt -r "-"

.PHONY: preflight-redhat-container
preflight-redhat-container: bin/$(PLATFORM)/preflight
Expand All @@ -308,7 +308,7 @@ lint: bin/$(PLATFORM)/golangci-lint fmt vet ## Lint

.PHONY: licenses
licenses: bin/$(PLATFORM)/go-licenses
./bin/$(PLATFORM)/go-licenses report . --template ./hack/licenses.tpl > LICENSE-3rdparty.csv 2> errors
./bin/$(PLATFORM)/go-licenses report ./cmd --template ./hack/licenses.tpl > LICENSE-3rdparty.csv 2> errors

.PHONY: verify-licenses
verify-licenses: bin/$(PLATFORM)/go-licenses ## Verify licenses
Expand All @@ -333,7 +333,7 @@ bin/$(PLATFORM)/yq: Makefile
hack/install-yq.sh v4.31.2

bin/$(PLATFORM)/golangci-lint: Makefile
hack/golangci-lint.sh -b "bin/$(PLATFORM)" v1.56.0
hack/golangci-lint.sh -b "bin/$(PLATFORM)" v1.59.1

bin/$(PLATFORM)/operator-sdk: Makefile
hack/install-operator-sdk.sh v1.34.1
Expand All @@ -353,7 +353,7 @@ bin/$(PLATFORM)/openapi-gen:
GOBIN=$(ROOT)/bin/$(PLATFORM) go install k8s.io/kube-openapi/cmd/openapi-gen@v0.0.0-20230717233707-2695361300d9

bin/$(PLATFORM)/kubebuilder:
./hack/install-kubebuilder.sh 3.13.0 ./bin/$(PLATFORM)
./hack/install-kubebuilder.sh 4.1.1 ./bin/$(PLATFORM)

bin/$(PLATFORM)/kubebuilder-tools:
./hack/install-kubebuilder-tools.sh 1.28.3 ./bin/$(PLATFORM)
Expand Down
18 changes: 9 additions & 9 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: com
layout:
- go.kubebuilder.io/v3
- go.kubebuilder.io/v4
multigroup: true
plugins:
manifests.sdk.operatorframework.io/v2: {}
Expand All @@ -18,31 +18,31 @@ resources:
domain: com
group: datadoghq
kind: DatadogMetric
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
path: github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: com
group: datadoghq
kind: DatadogMonitor
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
path: github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: com
group: datadoghq
kind: DatadogAgent
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
path: github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: com
group: datadoghq
kind: DatadogAgent
path: github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1
path: github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1
version: v2alpha1
webhooks:
conversion: true
Expand All @@ -53,7 +53,7 @@ resources:
domain: com
group: datadoghq
kind: DatadogSLO
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
path: github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand All @@ -62,15 +62,15 @@ resources:
domain: com
group: datadoghq
kind: DatadogAgentProfile
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
path: github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: com
group: datadoghq
kind: DatadogPodAutoscaler
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
path: github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand All @@ -79,6 +79,6 @@ resources:
domain: com
group: datadoghq
kind: DatadogDashboard
path: github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1
path: github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1
version: v1alpha1
version: "3"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package common

import (
commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
commonv1 "github.com/DataDog/datadog-operator/api/datadoghq/common/v1"
"github.com/DataDog/datadog-operator/pkg/defaulting"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package common
import (
"testing"

commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
apiutils "github.com/DataDog/datadog-operator/apis/utils"
commonv1 "github.com/DataDog/datadog-operator/api/datadoghq/common/v1"
apiutils "github.com/DataDog/datadog-operator/api/utils"
"github.com/DataDog/datadog-operator/pkg/defaulting"
"github.com/stretchr/testify/assert"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package v1alpha1

import (
commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
commonv1 "github.com/DataDog/datadog-operator/api/datadoghq/common/v1"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package v1alpha1
import (
"testing"

commonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
commonv1 "github.com/DataDog/datadog-operator/api/datadoghq/common/v1"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ type DatadogMonitorStatus struct {
// MonitorStateLastTransitionTime is the last time the monitor state changed
MonitorStateLastTransitionTime *metav1.Time `json:"monitorStateLastTransitionTime,omitempty"`
// MonitorStateSyncStatus shows the health of syncing the monitor state to Datadog
MonitorStateSyncStatus MonitorStateSyncStatusMessage `json:"syncStatus,omitempty"`
MonitorStateSyncStatus MonitorStateSyncStatusMessage `json:"monitorStateSyncStatus,omitempty"`
// TriggeredState only includes details for monitor groups that are triggering
// +listType=map
// +listMapKey=monitorGroup
Expand Down Expand Up @@ -307,8 +307,10 @@ type DatadogMonitorTriggeredState struct {
// DatadogMonitorDowntimeStatus represents the downtime status of a DatadogMonitor
// +k8s:openapi-gen=true
type DatadogMonitorDowntimeStatus struct {
// IsDowntimed shows the downtime status of the monitor.
IsDowntimed bool `json:"isDowntimed,omitempty"`
DowntimeID int `json:"downtimeId,omitempty"`
// DowntimeID is the downtime ID.
DowntimeID int `json:"downtimeID,omitempty"`
}

// DatadogMonitor allows to define and manage Monitors from your Kubernetes Cluster
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 010c848

Please sign in to comment.