Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: controller utils updates #70

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check Latest Commit Message
run: make test-commit
Expand All @@ -27,7 +27,7 @@ jobs:
if: github.event_name == 'pull_request'
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Get PR Commits
id: get-pr-commits
Expand All @@ -52,7 +52,7 @@ jobs:
if: github.event_name == 'pull_request'
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check Pull Request Title
uses: deepakputhraya/action-pr-title@master
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check License Lines
uses: kt3k/[email protected]
Expand All @@ -89,15 +89,15 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: "1.19"
go-version: "1.22"

- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
version: v1.57.1
args: --timeout 3m
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.19"
go-version: "1.21"

# NOTE: removing support for snapcraft as their CLI has become increasingly unstable and errors have become
# common place. See https://github.com/snapcore/action-publish/issues/28 for an example of some of the issues
Expand Down
52 changes: 26 additions & 26 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:
fail-fast: false
matrix:
include:
- go-version: "1.19"
- go-version: "1.20"
- go-version: "1.21"
- go-version: "1.22"
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

Expand All @@ -42,26 +42,26 @@ jobs:
fail-fast: false
matrix:
include:
- go-version: "1.19"
- go-version: "1.20"
- go-version: "1.21"
- go-version: "1.22"
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Build Binary Artifact (operator-builder)
run: make build

- name: Store Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: operator-builder
name: operator-builder-${{ matrix.go-version }}
path: bin/operator-builder

#
Expand All @@ -78,36 +78,36 @@ jobs:
- name: Standalone Operator (Current Go Version)
artifact: standalone-codebase
test-workload-path: test/cases/standalone
go-version: "1.20"
go-version: "1.22"
- name: Standalone Edge Cases Operator (Current Go Version - 1)
artifact: standalone-edge-codebase
test-workload-path: test/cases/edge-standalone
go-version: "1.19"
go-version: "1.21"
- name: Workload Collection Operator (Current Go Version)
artifact: collection-codebase
test-workload-path: test/cases/collection
go-version: "1.20"
go-version: "1.22"
- name: Workload Collection Edge Cases Operator (Current Go Version - 1)
artifact: collection-edge-codebase
test-workload-path: test/cases/edge-collection
go-version: "1.19"
go-version: "1.21"
env:
TEST_WORKLOAD_PATH: "${{ matrix.test-workload-path }}"
TEST_PATH: "/tmp/operator-builder-func-test"
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download operator-builder Binary
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: operator-builder
name: operator-builder-${{ matrix.go-version }}
path: bin

- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

Expand All @@ -122,7 +122,7 @@ jobs:

- name: Store ${{ matrix.name }} Codebase
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ env.TEST_PATH }}
Expand All @@ -145,22 +145,22 @@ jobs:
artifact: standalone-codebase
test-build: "true"
test-deploy: "true"
go-version: "1.20"
go-version: "1.22"
- name: Standalone Edge Cases Operator (Current Go Version - 1)
artifact: standalone-edge-codebase
test-build: "false"
test-deploy: "false"
go-version: "1.19"
go-version: "1.21"
- name: Workload Collection Operator (Current Go Version)
artifact: collection-codebase
test-build: "true"
test-deploy: "false"
go-version: "1.20"
go-version: "1.22"
- name: Workload Collection Edge Cases Operator (Current Go Version - 1)
artifact: collection-edge-codebase
test-build: "true"
test-deploy: "false"
go-version: "1.19"
go-version: "1.21"
services:
registry:
image: registry:2
Expand All @@ -171,17 +171,17 @@ jobs:
working-directory: /tmp/operator-builder-test
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Download ${{ matrix.name }} Codebase
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifact }}
path: /tmp/operator-builder-test
Expand Down
10 changes: 8 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ linters:
- asciicheck
- bodyclose
#- cyclop
- depguard
#- depguard
- dogsled
- dupl
- durationcheck
Expand Down Expand Up @@ -134,7 +134,7 @@ linters:
- wastedassign
- whitespace
- wrapcheck
- wsl
#- wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
Expand All @@ -147,6 +147,12 @@ issues:
- path: internal/commands/*\.go
linters:
- gochecknoglobals
- path: internal/plugins/workload/v1/scaffolds
linters:
- goconst
- path: internal/plugins/config/v1/plugin.go
linters:
- gocritic
- path: internal/plugins/workload/v1/scaffolds/templates/readme.go
linters:
- gomnd
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ install: build
#
# traditional testing
#
GOLANGCI_LINT_VERSION ?= v1.52.2
GOLANGCI_LINT_VERSION ?= v1.57.1
install-linter:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo/v2 v2.7.0 h1:/XxtEV3I3Eif/HobnVx9YmJgk8ENdRsuUmM+fLCFNow=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
Expand Down
1 change: 0 additions & 1 deletion internal/markers/marker/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Argument struct {
isSet bool
}

//nolint:gocritic //needed to implement string interface
func (a Argument) String() string {
if a.Optional {
return fmt.Sprintf("<optional arg %s>", a.Type)
Expand Down
17 changes: 8 additions & 9 deletions internal/plugins/workload/v1/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins"
kustomizecommonv1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v1"
scaffoldsv4 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v4/scaffolds"

"github.com/nukleros/operator-builder/internal/plugins/workload/v1/scaffolds/templates"
"github.com/nukleros/operator-builder/internal/plugins/workload/v1/scaffolds/templates/cli"
Expand All @@ -24,7 +23,8 @@ import (
)

const (
operatorSDKVersion = "v1.28.0"
operatorSDKVersion = "v1.28.0"
controllerToolsVersion = "v0.14.0"
)

var _ plugins.Scaffolder = &initScaffolder{}
Expand Down Expand Up @@ -100,13 +100,12 @@ func (s *initScaffolder) Scaffold() error {
ControllerImg: s.controllerImg,
},
&templates.Makefile{
RootCmdName: s.cliRootCommandName,
ControllerImg: s.controllerImg,
EnableOLM: s.enableOlm,
KustomizeVersion: kustomizecommonv1.KustomizeVersion,
ControllerToolsVersion: scaffoldsv4.ControllerToolsVersion,
ControllerRuntimeVersion: scaffoldsv4.ControllerRuntimeVersion,
OperatorSDKVersion: operatorSDKVersion,
RootCmdName: s.cliRootCommandName,
ControllerImg: s.controllerImg,
EnableOLM: s.enableOlm,
KustomizeVersion: kustomizecommonv1.KustomizeVersion,
ControllerToolsVersion: controllerToolsVersion,
OperatorSDKVersion: operatorSDKVersion,
},
&e2e.Test{},
); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (f *Controller) setOtherImports() {
`ctrl "sigs.k8s.io/controller-runtime"`,
`"sigs.k8s.io/controller-runtime/pkg/client"`,
`"sigs.k8s.io/controller-runtime/pkg/controller"`,
`"sigs.k8s.io/controller-runtime/pkg/manager"`,
`"github.com/nukleros/operator-builder-tools/pkg/controller/phases"`,
`"github.com/nukleros/operator-builder-tools/pkg/controller/predicates"`,
`"github.com/nukleros/operator-builder-tools/pkg/controller/workload"`,
Expand Down Expand Up @@ -143,6 +144,7 @@ type {{ .Resource.Kind }}Reconciler struct {
FieldManager string
Watches []client.Object
Phases *phases.Registry
Manager manager.Manager
}

func New{{ .Resource.Kind }}Reconciler(mgr ctrl.Manager) *{{ .Resource.Kind }}Reconciler {
Expand All @@ -154,6 +156,7 @@ func New{{ .Resource.Kind }}Reconciler(mgr ctrl.Manager) *{{ .Resource.Kind }}Re
Log: ctrl.Log.WithName("controllers").WithName("{{ .Resource.Group }}").WithName("{{ .Resource.Kind }}"),
Watches: []client.Object{},
Phases: &phases.Registry{},
Manager: mgr,
}
}

Expand Down Expand Up @@ -291,7 +294,7 @@ func (r *{{ .Resource.Kind }}Reconciler) EnqueueRequestOnCollectionChange(req *w
}

// create a function which maps this specific reconcile request
mapFn := func(collection client.Object) []reconcile.Request {
mapFn := func(_ context.Context, collection client.Object) []reconcile.Request {
return []reconcile.Request{
{
NamespacedName: types.NamespacedName{
Expand All @@ -304,7 +307,7 @@ func (r *{{ .Resource.Kind }}Reconciler) EnqueueRequestOnCollectionChange(req *w

// watch the collection and use our map function to enqueue the request
if err := r.Controller.Watch(
&source.Kind{Type: req.Collection},
source.Kind(r.Manager.GetCache(), req.Collection),
handler.EnqueueRequestsFromMapFunc(mapFn),
predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
Expand Down Expand Up @@ -373,6 +376,11 @@ func (r *{{ .Resource.Kind }}Reconciler) GetController() controller.Controller {
return r.Controller
}

// GetManager returns the manager object assocated with the reconciler.
func (r *{{ .Resource.Kind }}Reconciler) GetManager() manager.Manager {
return r.Manager
}

// GetWatches returns the objects which are current being watched by the reconciler.
func (r *{{ .Resource.Kind }}Reconciler) GetWatches() []client.Object {
return r.Watches
Expand Down
Loading
Loading