Skip to content

Commit

Permalink
Migrate to kubebuilder multigroup support (#207)
Browse files Browse the repository at this point in the history
* move api to multigroup support
* move controller to multigroup support
* update to golang 1.21

for now we can't move to 1.22 due to a controler-gen panic issue, see:
kubernetes-sigs/controller-tools#880
  • Loading branch information
clamoriniere committed Jul 5, 2024
1 parent 23fea1d commit dbe256f
Show file tree
Hide file tree
Showing 43 changed files with 113 additions and 127 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{
"name": "Go",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/go:0-1.19",
"image": "mcr.microsoft.com/devcontainers/go:1-1.21",
"features": {
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {},
"ghcr.io/devcontainers-contrib/features/kubectx-kubens": {},
"ghcr.io/mpriscella/features/kind": {}
}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Expand All @@ -24,4 +24,5 @@

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
"postStartCommand": ["git", "config", "--global", "--add", "safe.directory", "/workspaces/watermarkpodautoscaler"]
}
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: build

env:
GO_VERSION: 1.19
GO_VERSION: 1.21

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "CodeQL"

env:
GO_VERSION: 1.19
GO_VERSION: 1.21

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Release

env:
GO_VERSION: 1.19
GO_VERSION: 1.21

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]
env:
GO111MODULE: "on"
PROJECTNAME: "watermarkpodautoscaler"
GO_VERSION: 1.19
GO_VERSION: 1.21
jobs:
build:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"varcheck",
"rowserrcheck",
"sqlclosecheck",
"depguard",
"perfsprint",
]

[issues]
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.19 as builder
FROM golang:1.21 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -11,7 +11,7 @@ RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY apis/ apis/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY third_party/ third_party/
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ e2e: manager manifests verify-license goe2e

# Runs e2e tests (expects a configured cluster)
goe2e:
KUBEBUILDER_ASSETS="$(ROOT)/bin/$(PLATFORM)/" go test --tags=e2e ./controllers/test
KUBEBUILDER_ASSETS="$(ROOT)/bin/$(PLATFORM)/" go test --tags=e2e ./controllers/datadoghq/test

# Build manager binary
.PHONY: manager
Expand Down Expand Up @@ -178,7 +178,7 @@ 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 ./api/v1alpha1 -O zz_generated.openapi -p ./api/v1alpha1 -h ./hack/boilerplate.go.txt -r "-"
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 "-"

.PHONY: patch-crds
patch-crds: bin/$(PLATFORM)/yq
Expand Down Expand Up @@ -206,7 +206,7 @@ bin/$(PLATFORM)/yq: Makefile
hack/install-yq.sh "bin/$(PLATFORM)" v4.31.2

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

bin/$(PLATFORM)/operator-sdk: Makefile
hack/install-operator-sdk.sh v1.23.0
Expand Down
28 changes: 20 additions & 8 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
domain: datadoghq.com
layout: go.kubebuilder.io/v2
layout:
- go.kubebuilder.io/v3
multigroup: true
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
projectName: watermarkpodautoscaler
repo: github.com/DataDog/watermarkpodautoscaler
resources:
-
# TODO(user): Uncomment the below line if this resource implements a controller, else delete it.
# controller: true
- api:
crdVersion: v1
namespaced: true
controller: true
domain: datadoghq.com
group: datadoghq
kind: WatermarkPodAutoscaler
# TODO(user): Update the package path for your API if the below value is incorrect.
path: github.com/DataDog/watermarkpodautoscaler/api/v1alpha1
path: github.com/DataDog/watermarkpodautoscaler/apis/datadoghq/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: datadoghq.com
group: datadoghq
kind: RecommendWatermarkPodAutoscaler
path: github.com/DataDog/watermarkpodautoscaler/apis/datadoghq/v1alpha1
version: v1alpha1
version: "3"
plugins:
go.sdk.operatorframework.io/v2-alpha: {}
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 @@ -9,7 +9,7 @@ package test
import (
"time"

"github.com/DataDog/watermarkpodautoscaler/api/v1alpha1"
"github.com/DataDog/watermarkpodautoscaler/apis/datadoghq/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
File renamed without changes.

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

2 changes: 1 addition & 1 deletion bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.bundle.channel.default.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.23.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v2
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3

# Labels for testing.
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ metadata:
]
capabilities: Basic Install
operators.operatorframework.io/builder: operator-sdk-v1.23.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v2
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
name: watermarkpodautoscaler.v0.5.2
namespace: placeholder
spec:
Expand Down
2 changes: 1 addition & 1 deletion bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ annotations:
operators.operatorframework.io.bundle.channel.default.v1: alpha
operators.operatorframework.io.metrics.builder: operator-sdk-v1.23.0
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v2
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3

# Annotations for testing.
operators.operatorframework.io.test.mediatype.v1: scorecard+v1
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-wpa/app/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

"github.com/DataDog/watermarkpodautoscaler/api/v1alpha1"
"github.com/DataDog/watermarkpodautoscaler/apis/datadoghq/v1alpha1"
)

// NewClient returns new client instance.
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-wpa/app/dryrun/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/DataDog/watermarkpodautoscaler/api/v1alpha1"
"github.com/DataDog/watermarkpodautoscaler/apis/datadoghq/v1alpha1"
"github.com/DataDog/watermarkpodautoscaler/cmd/kubectl-wpa/app/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ metadata:
]
capabilities: Basic Install
operators.operatorframework.io/builder: operator-sdk-v1.23.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v2
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
name: watermarkpodautoscaler.v0.6.0-rc.1
namespace: placeholder
spec:
Expand Down
2 changes: 2 additions & 0 deletions controllers/datadoghq/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package datadoghq containers all the WatermarkPodAutoscaler controller logic.
package datadoghq
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package controllers
package datadoghq

import (
"context"

datadoghqv1alpha1 "github.com/DataDog/watermarkpodautoscaler/api/v1alpha1"
datadoghqv1alpha1 "github.com/DataDog/watermarkpodautoscaler/apis/datadoghq/v1alpha1"
"github.com/DataDog/watermarkpodautoscaler/pkg/util"
logr "github.com/go-logr/logr"
)
Expand Down
4 changes: 2 additions & 2 deletions controllers/metrics.go → controllers/datadoghq/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package controllers
package datadoghq

import (
"os"
"strings"

datadoghqv1alpha1 "github.com/DataDog/watermarkpodautoscaler/api/v1alpha1"
datadoghqv1alpha1 "github.com/DataDog/watermarkpodautoscaler/apis/datadoghq/v1alpha1"

"github.com/prometheus/client_golang/prometheus"

Expand Down
Loading

0 comments on commit dbe256f

Please sign in to comment.