From 655a0f21d504c72f27670663e31e1a539327e61a Mon Sep 17 00:00:00 2001 From: Chris Hein Date: Thu, 17 Dec 2020 01:46:08 -0800 Subject: [PATCH] moving api -> apis and setting multigroup: true Signed-off-by: Chris Hein --- Dockerfile | 27 +++++++++++++++++++ PROJECT | 1 + .../v1alpha4/groupversion_info.go | 0 .../v1alpha4/nestedcontrolplane_types.go | 0 .../v1alpha4/zz_generated.deepcopy.go | 0 .../nestedcontrolplane_controller.go | 2 +- controllers/{ => controlplane}/suite_test.go | 2 +- main.go | 17 ++++++++++-- 8 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 Dockerfile rename {api => apis/controlplane}/v1alpha4/groupversion_info.go (100%) rename {api => apis/controlplane}/v1alpha4/nestedcontrolplane_types.go (100%) rename {api => apis/controlplane}/v1alpha4/zz_generated.deepcopy.go (100%) rename controllers/{ => controlplane}/nestedcontrolplane_controller.go (98%) rename controllers/{ => controlplane}/suite_test.go (98%) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5169a8c0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Build the manager binary +FROM golang:1.15 as builder + +WORKDIR /workspace +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum +# 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 + +# Copy the go source +COPY main.go main.go +COPY apis/ apis/ +COPY controllers/ controllers/ + +# Build +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go + +# Use distroless as minimal base image to package the manager binary +# Refer to https://github.com/GoogleContainerTools/distroless for more details +FROM gcr.io/distroless/static:nonroot +WORKDIR / +COPY --from=builder /workspace/manager . +USER 65532:65532 + +ENTRYPOINT ["/manager"] diff --git a/PROJECT b/PROJECT index 696ed092..0134ee06 100644 --- a/PROJECT +++ b/PROJECT @@ -1,6 +1,7 @@ domain: cluster.x-k8s.io layout: go.kubebuilder.io/v3 projectName: cluster-api-provider-nested +multigroup: true repo: sigs.k8s.io/cluster-api-provider-nested resources: - group: controlplane diff --git a/api/v1alpha4/groupversion_info.go b/apis/controlplane/v1alpha4/groupversion_info.go similarity index 100% rename from api/v1alpha4/groupversion_info.go rename to apis/controlplane/v1alpha4/groupversion_info.go diff --git a/api/v1alpha4/nestedcontrolplane_types.go b/apis/controlplane/v1alpha4/nestedcontrolplane_types.go similarity index 100% rename from api/v1alpha4/nestedcontrolplane_types.go rename to apis/controlplane/v1alpha4/nestedcontrolplane_types.go diff --git a/api/v1alpha4/zz_generated.deepcopy.go b/apis/controlplane/v1alpha4/zz_generated.deepcopy.go similarity index 100% rename from api/v1alpha4/zz_generated.deepcopy.go rename to apis/controlplane/v1alpha4/zz_generated.deepcopy.go diff --git a/controllers/nestedcontrolplane_controller.go b/controllers/controlplane/nestedcontrolplane_controller.go similarity index 98% rename from controllers/nestedcontrolplane_controller.go rename to controllers/controlplane/nestedcontrolplane_controller.go index e13591d5..5922dd24 100644 --- a/controllers/nestedcontrolplane_controller.go +++ b/controllers/controlplane/nestedcontrolplane_controller.go @@ -24,7 +24,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - controlplanev1alpha4 "sigs.k8s.io/cluster-api-provider-nested/api/v1alpha4" + controlplanev1alpha4 "sigs.k8s.io/cluster-api-provider-nested/apis/controlplane/v1alpha4" ) // NestedControlPlaneReconciler reconciles a NestedControlPlane object diff --git a/controllers/suite_test.go b/controllers/controlplane/suite_test.go similarity index 98% rename from controllers/suite_test.go rename to controllers/controlplane/suite_test.go index dc3825fa..74b7915f 100644 --- a/controllers/suite_test.go +++ b/controllers/controlplane/suite_test.go @@ -30,7 +30,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - controlplanev1alpha4 "sigs.k8s.io/cluster-api-provider-nested/api/v1alpha4" + controlplanev1alpha4 "sigs.k8s.io/cluster-api-provider-nested/apis/controlplane/v1alpha4" // +kubebuilder:scaffold:imports ) diff --git a/main.go b/main.go index 39c0e32c..80b1b896 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ import ( "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/klog" "k8s.io/klog/klogr" @@ -34,6 +35,9 @@ import ( "sigs.k8s.io/cluster-api/util" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/healthz" + + controlplanev1alpha4 "sigs.k8s.io/cluster-api-provider-nested/apis/controlplane/v1alpha4" + controlplanecontrollers "sigs.k8s.io/cluster-api-provider-nested/controllers/controlplane" // +kubebuilder:scaffold:imports ) @@ -56,8 +60,9 @@ var ( func init() { klog.InitFlags(nil) - _ = clientgoscheme.AddToScheme(scheme) - _ = clusterv1.AddToScheme(scheme) + utilruntime.Must(clientgoscheme.AddToScheme(scheme)) + utilruntime.Must(clusterv1.AddToScheme(scheme)) + utilruntime.Must(controlplanev1alpha4.AddToScheme(scheme)) // +kubebuilder:scaffold:scheme } @@ -141,6 +146,14 @@ func main() { } // TODO(community): Register controllers and webhooks here. + if err = (&controlplanecontrollers.NestedControlPlaneReconciler{ + Client: mgr.GetClient(), + Log: ctrl.Log.WithName("controllers").WithName("controlplane").WithName("NestedControlPlane"), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "NestedControlPlane") + os.Exit(1) + } // +kubebuilder:scaffold:builder setupLog.Info("Starting manager", "version", version.Get().String())