Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Updates golangci-lint #635

Merged
merged 2 commits into from
Jun 15, 2023
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
6 changes: 3 additions & 3 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ $(GINKGO): $(BINGO_DIR)/ginkgo.mod
@echo "(re)installing $(GOBIN)/ginkgo-v2.8.3"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=ginkgo.mod -o=$(GOBIN)/ginkgo-v2.8.3 "github.com/onsi/ginkgo/v2/ginkgo"

GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.49.0
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.53.2
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/golangci-lint-v1.49.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.49.0 "github.com/golangci/golangci-lint/cmd/golangci-lint"
@echo "(re)installing $(GOBIN)/golangci-lint-v1.53.2"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.53.2 "github.com/golangci/golangci-lint/cmd/golangci-lint"

GORELEASER := $(GOBIN)/goreleaser-v1.17.2
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod
Expand Down
2 changes: 1 addition & 1 deletion .bingo/golangci-lint.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.19

require github.com/golangci/golangci-lint v1.49.0 // cmd/golangci-lint
require github.com/golangci/golangci-lint v1.53.2 // cmd/golangci-lint
210 changes: 210 additions & 0 deletions .bingo/golangci-lint.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CONTROLLER_GEN="${GOBIN}/controller-gen-v0.11.4"

GINKGO="${GOBIN}/ginkgo-v2.8.3"

GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.49.0"
GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.53.2"

GORELEASER="${GOBIN}/goreleaser-v1.17.2"

Expand Down
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ linters:
enable:
- asciicheck
- bodyclose
- depguard
- errorlint
- gofmt
- goimports
Expand Down
4 changes: 4 additions & 0 deletions internal/controllers/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func (c *controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return res, reconcileErr
}

// nolint:unparam
// Today we always return ctrl.Result{} and an error.
// But in the future we might update this function
// to return different results (e.g. requeue).
func (c *controller) reconcile(ctx context.Context, bundle *rukpakv1alpha1.Bundle) (ctrl.Result, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in internal/controllers/bundledeployment/bundledeployment.go we always return an empty value in ctrl.Result{}. It makes sense in Reconcile to satisfy the interface, but not in this unexported func.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with this change. If we ever do want to return something other than ctrl.Result{}, it'll likely be coming from reconcile(), not Reconcile().

I'd be slightly worried that our future selves would be less inclined to change the return values back to (ctrl.Result, error) and would instead do something less desirable overall.

The primary purpose of this split is to make us not really have to think at all about status updating. The result is merely passed through.

Is a linter complaining about this? If so, WDYT about applying the //nolint:<whatever> label with an explanation along these lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelanford I also was not super happy about this linting issue at first, but ended up obeying because I convinced myself that the code is not set in stone. It is super easy to add a new return param once we have a need for it (especially since this is not an exported method).

To me it is the same as adding input arguments into a function: we usually add new args as the need for them arises. There are exceptions (e.g. designing a public interfaces where signature changes are more painful), but it is not the case here.

But I can look into either adding nolint or disabling this linting rule altogether tomorrow. I am not a big fan of inline linting exceptions, but also do not have very strong objections against them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated: added //nolint:unparam to both

bundle.Status.ObservedGeneration = bundle.Generation

Expand Down
7 changes: 5 additions & 2 deletions internal/controllers/bundledeployment/bundledeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ func SetupWithManager(mgr manager.Manager, opts ...Option) error {
}

controllerName := fmt.Sprintf("controller.bundledeployment.%s", c.provisionerID)
l := mgr.GetLogger().WithName(controllerName)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused

controller, err := ctrl.NewControllerManagedBy(mgr).
Named(controllerName).
For(&rukpakv1alpha1.BundleDeployment{}, builder.WithPredicates(
util.BundleDeploymentProvisionerFilter(c.provisionerID)),
).
Watches(&source.Kind{Type: &rukpakv1alpha1.Bundle{}}, handler.EnqueueRequestsFromMapFunc(
util.MapBundleToBundleDeploymentHandler(context.Background(), mgr.GetClient(), l, c.provisionerID)),
util.MapBundleToBundleDeploymentHandler(context.Background(), mgr.GetClient(), c.provisionerID)),
).
Build(c)
if err != nil {
Expand Down Expand Up @@ -193,6 +192,10 @@ func (c *controller) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return res, reconcileErr
}

// nolint:unparam
// Today we always return ctrl.Result{} and an error.
// But in the future we might update this function
// to return different results (e.g. requeue).
func (c *controller) reconcile(ctx context.Context, bd *rukpakv1alpha1.BundleDeployment) (ctrl.Result, error) {
bd.Status.ObservedGeneration = bd.Generation

Expand Down
16 changes: 8 additions & 8 deletions internal/helm-operator-plugins/predicate/depedent.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ func DependentPredicateFuncs() crtpredicate.Funcs {
// necessary. Ignore updates that only change the status and
// resourceVersion.
UpdateFunc: func(e event.UpdateEvent) bool {
old := e.ObjectOld.(*unstructured.Unstructured).DeepCopy()
new := e.ObjectNew.(*unstructured.Unstructured).DeepCopy()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New was shadowing built-in new. Renamed old into oldObj for consistency.

oldObj := e.ObjectOld.(*unstructured.Unstructured).DeepCopy()
newObj := e.ObjectNew.(*unstructured.Unstructured).DeepCopy()

delete(old.Object, "status")
delete(new.Object, "status")
old.SetResourceVersion("")
new.SetResourceVersion("")
delete(oldObj.Object, "status")
delete(newObj.Object, "status")
oldObj.SetResourceVersion("")
newObj.SetResourceVersion("")

if reflect.DeepEqual(old.Object, new.Object) {
if reflect.DeepEqual(oldObj.Object, newObj.Object) {
return false
}
log.V(1).Info("Reconciling due to dependent resource update", "name", new.GetName(), "namespace", new.GetNamespace(), "apiVersion", new.GroupVersionKind().GroupVersion(), "kind", new.GroupVersionKind().Kind)
log.V(1).Info("Reconciling due to dependent resource update", "name", newObj.GetName(), "namespace", newObj.GetNamespace(), "apiVersion", newObj.GroupVersionKind().GroupVersion(), "kind", newObj.GroupVersionKind().Kind)
return true
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/provisioner/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
ProvisionerID = "core-rukpak-io-helm"
)

func HandleBundle(ctx context.Context, fsys fs.FS, bundle *rukpakv1alpha1.Bundle) (fs.FS, error) {
func HandleBundle(_ context.Context, fsys fs.FS, _ *rukpakv1alpha1.Bundle) (fs.FS, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in other places with _ args - we don't use args in functions, but we still need args to statisfy interfaces.

// Helm expects an FS whose root contains a single chart directory. Depending on how
// the bundle is sourced, the FS may or may not contain this single chart directory in
// its root (e.g. charts uploaded via 'rukpakctl run <bdName> <chartDir>') would not.
Expand All @@ -37,7 +37,7 @@ func HandleBundle(ctx context.Context, fsys fs.FS, bundle *rukpakv1alpha1.Bundle
return chartFS, nil
}

func HandleBundleDeployment(ctx context.Context, fsys fs.FS, bd *rukpakv1alpha1.BundleDeployment) (*chart.Chart, chartutil.Values, error) {
func HandleBundleDeployment(_ context.Context, fsys fs.FS, bd *rukpakv1alpha1.BundleDeployment) (*chart.Chart, chartutil.Values, error) {
values, err := loadValues(bd)
if err != nil {
return nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/source/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,6 @@ func (d *billyDirFile) ReadDir(n int) ([]fs.DirEntry, error) {
return entries[:n], err
}

func (d billyDirFile) Read(data []byte) (int, error) {
func (d billyDirFile) Read(_ []byte) (int, error) {
return 0, &fs.PathError{Op: "read", Path: d.path, Err: syscall.EISDIR}
}
5 changes: 1 addition & 4 deletions internal/util/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,5 @@ func FSToTarGZ(w io.Writer, fsys fs.FS) error {
if err := tw.Close(); err != nil {
return err
}
if err := gzw.Close(); err != nil {
return err
}
return nil
return gzw.Close()
}
2 changes: 1 addition & 1 deletion internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func MapBundleToBundleDeployment(ctx context.Context, c client.Client, b rukpakv
// standalone resource, then no BundleDeployment will be returned as static creation of Bundle
// resources is not a supported workflow right now. The provisionerClassName parameter is used
// to filter out BundleDeployments that the caller shouldn't be watching.
func MapBundleToBundleDeploymentHandler(ctx context.Context, cl client.Client, log logr.Logger, provisionerClassName string) handler.MapFunc {
func MapBundleToBundleDeploymentHandler(ctx context.Context, cl client.Client, provisionerClassName string) handler.MapFunc {
return func(object client.Object) []reconcile.Request {
b := object.(*rukpakv1alpha1.Bundle)

Expand Down