Skip to content

Commit

Permalink
project: kubebuilder layout v3 -> v4
Browse files Browse the repository at this point in the history
  • Loading branch information
ffromani committed Jan 23, 2025
1 parent bf469c1 commit bf1a729
Show file tree
Hide file tree
Showing 108 changed files with 169 additions and 119 deletions.
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Kubebuilder DevContainer",
"image": "docker.io/golang:1.23",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {}
},

"runArgs": ["--network=host"],

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
]
}
},

"onCreateCommand": "bash .devcontainer/post-install.sh"
}

23 changes: 23 additions & 0 deletions .devcontainer/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -x

curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
mv ./kind /usr/local/bin/kind

curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
chmod +x kubebuilder
mv kubebuilder /usr/local/bin/

KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl

docker network create -d=bridge --subnet=172.19.0.0/24 kind

kind version
kubebuilder version
docker --version
go version
kubectl version --client
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
bin/*
testbin/*
Dockerfile.cross

# Test binary, build with `go test -c`
# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Kubernetes Generated files - skip generated files, except for vendored files
# Go workspace file
go.work

# Kubernetes Generated files - skip generated files, except for vendored files
!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
.vscode
*.swp
*.swo
*~
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ is derived by the controller-gen/operator-sdk/kubebuilder tooling.

The master source is the set of annotated go types.

The main content is `api/numaresourcesoperator` whose subfolders hold the versioned api:
The main content is `api` whose subfolders hold the versioned api:
`v1alpha1`, `v1`...

The top-level api packages (`api/numaresourcesoperator/v1`) should have minimal deps: they
The top-level api packages (`api/v1`) should have minimal deps: they
should depend only on
1. stdlib
2. other API packages (e.g. k8s, ocp)

We add helper packages which build on top of api packages and provide utilities: they sit in
`api/numaresources/$VERSION/helper/$HELPER/...` and these packages *can* have more dependencies.
`api/$VERSION/helper/$HELPER/...` and these packages *can* have more dependencies.

NOTE: helper packages can depend on top-level api packages, but top-level api packages **must not**
depend on helpers. Keep the top-level dependencies minimal and controlled!
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ test-unit-pkgs: generate-source pkg/
go test ./api/... ./pkg/... ./rte/pkg/... ./internal/... ./nrovalidate/validator/...

test-unit-pkgs-cover: generate-source
go test -coverprofile=coverage.out ./api/numaresourcesoperator/v1/helper/... ./api/numaresourcesoperator/v1alpha1/helper/... ./pkg/... ./rte/pkg/... ./internal/... ./nrovalidate/validator/...
go test -coverprofile=coverage.out ./api/v1/helper/... ./api/v1alpha1/helper/... ./pkg/... ./rte/pkg/... ./internal/... ./nrovalidate/validator/...

test-controllers: envtest generate-source
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./controllers/...
Expand Down Expand Up @@ -162,7 +162,7 @@ cover-summary:
binary: build-tools
LDFLAGS="-s -w"; \
LDFLAGS+=" -X github.com/openshift-kni/numaresources-operator/pkg/images.tag=$(VERSION)"; \
go build -mod=vendor -o bin/manager -ldflags "$$LDFLAGS" -tags "$$GOTAGS" main.go
go build -mod=vendor -o bin/manager -ldflags "$$LDFLAGS" -tags "$$GOTAGS" cmd/main.go

binary-rte: build-tools
LDFLAGS="-s -w"; \
Expand Down Expand Up @@ -272,7 +272,7 @@ bin-dir:
@mkdir -p bin || :

run: manifests generate generate-source fmt vet ## Run a controller from your host.
go run ./main.go
go run ./cmd/main.go

# backward compatibility
docker-build: container-build
Expand Down Expand Up @@ -467,4 +467,4 @@ golangci-lint: pkg/version/_buildinfo.json
else\
echo "Using golangci-lint cached at $(GOLANGCI_LINT), current version $(GOLANGCI_LINT_LOCAL_VERSION) expected version: $(GOLANGCI_LINT_VERSION)";\
fi
$(GOLANGCI_LINT) run --verbose --print-resources-usage -c .golangci.yaml
$(GOLANGCI_LINT) run --verbose --print-resources-usage -c .golangci.yml
10 changes: 7 additions & 3 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 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: openshift.io
layout:
- go.kubebuilder.io/v3
- go.kubebuilder.io/v4
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
Expand All @@ -14,7 +18,7 @@ resources:
domain: openshift.io
group: nodetopology
kind: NUMAResourcesOperator
path: github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1alpha1
path: github.com/openshift-kni/numaresources-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand All @@ -32,7 +36,7 @@ resources:
domain: openshift.io
group: nodetopology
kind: NUMAResourcesScheduler
path: github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1alpha1
path: github.com/openshift-kni/numaresources-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

// Package v1 contains API Schema definitions for the nodetopology v1 API group
// Package v1 contains API Schema definitions for the nodetopology v1 API group.
// +kubebuilder:object:generate=true
// +groupName=nodetopology.openshift.io
package v1
Expand All @@ -25,15 +25,12 @@ import (
)

var (
// GroupVersion is group version used to register these objects
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "nodetopology.openshift.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

// SchemeGroupVersion is DEPRECATED, needed for the client generation
SchemeGroupVersion = GroupVersion
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package namespacedname
import (
"sigs.k8s.io/controller-runtime/pkg/client"

nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
)

func AsObjectKey(nn nropv1.NamespacedName) client.ObjectKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

v1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
v1 "github.com/openshift-kni/numaresources-operator/api/v1"
)

func TestAsObjectKey(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

mcov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
)

// Tree maps a NodeGroup to the MachineConfigPool identified by the NodeGroup's MCPSelector.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

mcov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
)

func TestFindTreesOpenshift(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ -25,7 +25,7 @@ import (

mcov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

nropv1alpha1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1alpha1"
nropv1alpha1 "github.com/openshift-kni/numaresources-operator/api/v1alpha1"
)

type Tree struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

mcov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

nropv1alpha1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1alpha1"
nropv1alpha1 "github.com/openshift-kni/numaresources-operator/api/v1alpha1"
)

func TestFindTrees(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/conversion"

nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
mcov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"sigs.k8s.io/controller-runtime/pkg/conversion"

nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
)

var _ conversion.Convertible = &NUMAResourcesScheduler{}
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions main.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ import (
rtemanifests "github.com/k8stopologyawareschedwg/deployer/pkg/manifests/rte"
"github.com/k8stopologyawareschedwg/deployer/pkg/options"

nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1alpha1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1alpha1"
"github.com/openshift-kni/numaresources-operator/controllers"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
nropv1alpha1 "github.com/openshift-kni/numaresources-operator/api/v1alpha1"
"github.com/openshift-kni/numaresources-operator/internal/api/features"
"github.com/openshift-kni/numaresources-operator/internal/controller"
intkloglevel "github.com/openshift-kni/numaresources-operator/internal/kloglevel"
"github.com/openshift-kni/numaresources-operator/pkg/hash"
"github.com/openshift-kni/numaresources-operator/pkg/images"
Expand Down Expand Up @@ -282,7 +282,7 @@ func main() {
os.Exit(1)
}

if err = (&controllers.NUMAResourcesOperatorReconciler{
if err = (&controller.NUMAResourcesOperatorReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("numaresources-controller"),
Expand All @@ -300,7 +300,7 @@ func main() {
klog.ErrorS(err, "unable to create controller", "controller", "NUMAResourcesOperator")
os.Exit(1)
}
if err = (&controllers.KubeletConfigReconciler{
if err = (&controller.KubeletConfigReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("kubeletconfig-controller"),
Expand All @@ -324,7 +324,7 @@ func main() {
}
klog.InfoS("manifests loaded", "component", "Scheduler")

if err = (&controllers.NUMAResourcesSchedulerReconciler{
if err = (&controller.NUMAResourcesSchedulerReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
SchedulerManifests: schedMf,
Expand Down
1 change: 0 additions & 1 deletion cmd/numaresources-operator/README.md

This file was deleted.

1 change: 0 additions & 1 deletion cmd/resource-topology-exporter/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion internal/api/annotations/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package helper

import (
nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
anns "github.com/openshift-kni/numaresources-operator/internal/api/annotations"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package controllers
package controller

import (
"context"
Expand Down Expand Up @@ -42,7 +42,7 @@ import (
mcov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

"github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform"
nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
"github.com/openshift-kni/numaresources-operator/internal/machineconfigpools"
"github.com/openshift-kni/numaresources-operator/pkg/apply"
"github.com/openshift-kni/numaresources-operator/pkg/kubeletconfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package controllers
package controller

import (
"context"
Expand All @@ -33,7 +33,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform"
nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
"github.com/openshift-kni/numaresources-operator/pkg/objectnames"
rteconfig "github.com/openshift-kni/numaresources-operator/rte/pkg/config"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package controllers
package controller

import (
"context"
Expand Down Expand Up @@ -51,9 +51,9 @@ import (
"github.com/k8stopologyawareschedwg/deployer/pkg/manifests"
apimanifests "github.com/k8stopologyawareschedwg/deployer/pkg/manifests/api"
k8swgrteupdate "github.com/k8stopologyawareschedwg/deployer/pkg/objectupdate/rte"
nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
"github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1/helper/namespacedname"
nodegroupv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1/helper/nodegroup"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
"github.com/openshift-kni/numaresources-operator/api/v1/helper/namespacedname"
nodegroupv1 "github.com/openshift-kni/numaresources-operator/api/v1/helper/nodegroup"
"github.com/openshift-kni/numaresources-operator/internal/api/annotations"
"github.com/openshift-kni/numaresources-operator/internal/dangling"
"github.com/openshift-kni/numaresources-operator/internal/relatedobjects"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package controllers
package controller

import (
"context"
Expand Down Expand Up @@ -50,7 +50,7 @@ import (
securityv1 "github.com/openshift/api/security/v1"
machineconfigv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

nropv1 "github.com/openshift-kni/numaresources-operator/api/numaresourcesoperator/v1"
nropv1 "github.com/openshift-kni/numaresources-operator/api/v1"
"github.com/openshift-kni/numaresources-operator/internal/api/annotations"
inthelper "github.com/openshift-kni/numaresources-operator/internal/api/annotations/helper"
testobjs "github.com/openshift-kni/numaresources-operator/internal/objects"
Expand Down
Loading

0 comments on commit bf1a729

Please sign in to comment.