From a15f556cf8fc62057c4d92fe9ba2fa43be2d692c Mon Sep 17 00:00:00 2001 From: Dean Roehrich Date: Wed, 18 Oct 2023 11:20:01 -0500 Subject: [PATCH] Update the project for kubebuilder go/v4 layout Change the layout to follow the Standard Go Project Layout, as described in https://book.kubebuilder.io/migration/v3vsv4. This allows newer releases of kubebuilder to be used with this repo. Signed-off-by: Dean Roehrich --- Dockerfile | 7 ++++--- Makefile | 4 ++-- PROJECT | 2 +- main.go => cmd/main.go | 0 controllers/workflow_controller.go | 2 +- {controllers => internal/controller}/conversion_test.go | 2 +- {controllers => internal/controller}/metrics/metrics.go | 0 {controllers => internal/controller}/suite_test.go | 9 +++++---- .../controller}/workflow_controller_test.go | 2 +- 9 files changed, 15 insertions(+), 13 deletions(-) rename main.go => cmd/main.go (100%) rename {controllers => internal/controller}/conversion_test.go (99%) rename {controllers => internal/controller}/metrics/metrics.go (100%) rename {controllers => internal/controller}/suite_test.go (94%) rename {controllers => internal/controller}/workflow_controller_test.go (99%) diff --git a/Dockerfile b/Dockerfile index 1df32722..43839653 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Copyright 2020, 2021, 2022 Hewlett Packard Enterprise Development LP +# Copyright 2020-2023 Hewlett Packard Enterprise Development LP # Other additional copyright holders may be indicated within. # # The entirety of this work is licensed under the Apache License, @@ -24,8 +24,9 @@ COPY go.mod go.mod COPY go.sum go.sum # Copy the go source -COPY main.go main.go +COPY cmd/ cmd/ COPY api/ api/ +COPY internal/ internal/ COPY controllers/ controllers/ COPY mount-daemon/ mount-daemon/ COPY utils/ utils/ @@ -33,7 +34,7 @@ COPY vendor/ vendor/ COPY github/cluster-api/util/conversion/ github/cluster-api/util/conversion/ # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager cmd/main.go FROM builder as testing WORKDIR /workspace diff --git a/Makefile b/Makefile index e3162cf9..8e4e14a9 100644 --- a/Makefile +++ b/Makefile @@ -135,10 +135,10 @@ build-daemon: manifests generate fmt vet ## Build standalone clientMount daemon GOOS=linux GOARCH=amd64 go build -ldflags="-X '$(PACKAGE).version=$(RPM_VERSION)'" -o bin/clientmountd mount-daemon/main.go build: manifests generate fmt vet ## Build manager binary. - go build -o bin/manager main.go + go build -o bin/manager cmd/main.go run: manifests generate fmt vet ## Run a controller from your host. - go run ./main.go + go run cmd/main.go docker-build: VERSION ?= $(shell cat .version) docker-build: .version manifests generate fmt vet ## Build docker image with the manager. diff --git a/PROJECT b/PROJECT index c10f3068..806a76d8 100644 --- a/PROJECT +++ b/PROJECT @@ -4,7 +4,7 @@ # More info: https://book.kubebuilder.io/reference/project-config.html domain: github.io layout: -- go.kubebuilder.io/v3 +- go.kubebuilder.io/v4 plugins: manifests.sdk.operatorframework.io/v2: {} scorecard.sdk.operatorframework.io/v2: {} diff --git a/main.go b/cmd/main.go similarity index 100% rename from main.go rename to cmd/main.go diff --git a/controllers/workflow_controller.go b/controllers/workflow_controller.go index 81ae02d9..ba08ea1d 100644 --- a/controllers/workflow_controller.go +++ b/controllers/workflow_controller.go @@ -38,7 +38,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" dwsv1alpha2 "github.com/DataWorkflowServices/dws/api/v1alpha2" - "github.com/DataWorkflowServices/dws/controllers/metrics" + "github.com/DataWorkflowServices/dws/internal/controller/metrics" "github.com/DataWorkflowServices/dws/utils/updater" ) diff --git a/controllers/conversion_test.go b/internal/controller/conversion_test.go similarity index 99% rename from controllers/conversion_test.go rename to internal/controller/conversion_test.go index ae8f30a0..fdf2aea8 100644 --- a/controllers/conversion_test.go +++ b/internal/controller/conversion_test.go @@ -17,7 +17,7 @@ * limitations under the License. */ -package controllers +package controller import ( "context" diff --git a/controllers/metrics/metrics.go b/internal/controller/metrics/metrics.go similarity index 100% rename from controllers/metrics/metrics.go rename to internal/controller/metrics/metrics.go diff --git a/controllers/suite_test.go b/internal/controller/suite_test.go similarity index 94% rename from controllers/suite_test.go rename to internal/controller/suite_test.go index 4946990b..24257ffb 100644 --- a/controllers/suite_test.go +++ b/internal/controller/suite_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controllers +package controller import ( "context" @@ -37,6 +37,7 @@ import ( dwsv1alpha1 "github.com/DataWorkflowServices/dws/api/v1alpha1" dwsv1alpha2 "github.com/DataWorkflowServices/dws/api/v1alpha2" + "github.com/DataWorkflowServices/dws/controllers" //+kubebuilder:scaffold:imports ) @@ -82,9 +83,9 @@ var _ = BeforeSuite(func() { testEnv = &envtest.Environment{ WebhookInstallOptions: envtest.WebhookInstallOptions{ - Paths: []string{filepath.Join("..", "config", "webhook")}, + Paths: []string{filepath.Join("..", "..", "config", "webhook")}, }, - CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, + CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, CRDInstallOptions: envtest.CRDInstallOptions{ // This adds the conversion webhook configuration to @@ -147,7 +148,7 @@ var _ = BeforeSuite(func() { // start reconcilers - err = (&WorkflowReconciler{ + err = (&controllers.WorkflowReconciler{ Client: k8sManager.GetClient(), Log: ctrl.Log.WithName("controllers").WithName("Workflow"), Scheme: testEnv.Scheme, diff --git a/controllers/workflow_controller_test.go b/internal/controller/workflow_controller_test.go similarity index 99% rename from controllers/workflow_controller_test.go rename to internal/controller/workflow_controller_test.go index 07eb2cb0..f3142e6c 100644 --- a/controllers/workflow_controller_test.go +++ b/internal/controller/workflow_controller_test.go @@ -17,7 +17,7 @@ * limitations under the License. */ -package controllers +package controller import ( "context"