From 4e3e491a560eee2e722c3bc54e348da010f89265 Mon Sep 17 00:00:00 2001 From: Aravindhan Ayyanathan Date: Fri, 13 Nov 2026 12:58:54 +0000 Subject: [PATCH 1/2] Upgrade golangci-lint to 2.15.0 - golangci-lint version bumped to `2.15.0` - All modules verified (go mod tidy, go fmt, go vet, go build) Signed-off-by: Aravindhan Ayyanathan --- cli/alpha/live/plan/command.go | 6 +++--- cli/alpha/live/plan/diff.go | 21 ++++++++++++------- cli/fn/cmdeval/cmdeval.go | 14 +++++++++---- make/info.mk | 2 +- pkg/live/inventoryrg.go | 37 ++++++++++++++++++++-------------- pkg/live/load.go | 10 ++++----- scripts/go-upgrade/README.md | 2 +- scripts/go-upgrade/config.env | 2 +- 8 files changed, 57 insertions(+), 37 deletions(-) diff --git a/cli/alpha/live/plan/command.go b/cli/alpha/live/plan/command.go index 91dda2ab9e..6a2b0ccc2e 100644 --- a/cli/alpha/live/plan/command.go +++ b/cli/alpha/live/plan/command.go @@ -220,13 +220,13 @@ func findAndPrintDiff(before, after *unstructured.Unstructured, prefix string, i } switch d.Type { - case "LeftAdd": + case DiffTypeLeftAdd: txt := print.SprintfWithColor(print.RED, "%s-%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Left))) fmt.Fprint(ioStreams.Out, txt) - case "RightAdd": + case DiffTypeRightAdd: txt := print.SprintfWithColor(print.GREEN, "%s+%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Right))) fmt.Fprint(ioStreams.Out, txt) - case "Change": + case DiffTypeChange: txt1 := print.SprintfWithColor(print.RED, "%s-%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Left))) fmt.Fprint(ioStreams.Out, txt1) txt2 := print.SprintfWithColor(print.GREEN, "%s+%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Right))) diff --git a/cli/alpha/live/plan/diff.go b/cli/alpha/live/plan/diff.go index d1d7e0f7d7..928edc1837 100644 --- a/cli/alpha/live/plan/diff.go +++ b/cli/alpha/live/plan/diff.go @@ -28,6 +28,13 @@ type Diff struct { Path string } +// Diff.Type values. +const ( + DiffTypeLeftAdd = "LeftAdd" + DiffTypeRightAdd = "RightAdd" + DiffTypeChange = "Change" +) + func diffObjects(b, a *unstructured.Unstructured) ([]Diff, error) { diffs, err := diffMaps("", b.Object, a.Object) if err != nil { @@ -43,7 +50,7 @@ func diffMaps(prefix string, l, r map[string]any) ([]Diff, error) { rv, ok := r[k] if !ok { - diffs = append(diffs, Diff{Type: "LeftAdd", Path: childPrefix, Left: lv, Right: rv}) + diffs = append(diffs, Diff{Type: DiffTypeLeftAdd, Path: childPrefix, Left: lv, Right: rv}) continue } childDiffs, err := diffValue(childPrefix, lv, rv) @@ -58,7 +65,7 @@ func diffMaps(prefix string, l, r map[string]any) ([]Diff, error) { lv, ok := l[k] if !ok { - diffs = append(diffs, Diff{Type: "RightAdd", Path: childPrefix, Left: lv, Right: rv}) + diffs = append(diffs, Diff{Type: DiffTypeRightAdd, Path: childPrefix, Left: lv, Right: rv}) continue } } @@ -72,7 +79,7 @@ func diffSlices(prefix string, l, r []any) ([]Diff, error) { childPrefix := prefix + "." + strconv.Itoa(i) if len(r) <= i { - diffs = append(diffs, Diff{Type: "LeftAdd", Path: childPrefix, Left: l[i], Right: nil}) + diffs = append(diffs, Diff{Type: DiffTypeLeftAdd, Path: childPrefix, Left: l[i], Right: nil}) continue } rv := r[i] @@ -87,7 +94,7 @@ func diffSlices(prefix string, l, r []any) ([]Diff, error) { childPrefix := prefix + "." + strconv.Itoa(i) if len(l) <= i { - diffs = append(diffs, Diff{Type: "RightAdd", Path: childPrefix, Left: nil, Right: rv}) + diffs = append(diffs, Diff{Type: DiffTypeRightAdd, Path: childPrefix, Left: nil, Right: rv}) continue } } @@ -110,20 +117,20 @@ func diffValue(path string, lv, rv any) ([]Diff, error) { case map[string]any: rvMap, ok := rv.(map[string]any) if !ok { - return []Diff{{Type: "Change", Path: path, Left: lv, Right: rv}}, nil + return []Diff{{Type: DiffTypeChange, Path: path, Left: lv, Right: rv}}, nil } return diffMaps(path, lv, rvMap) case []any: rvSlice, ok := rv.([]any) if !ok { - return []Diff{{Type: "Change", Path: path, Left: lv, Right: rv}}, nil + return []Diff{{Type: DiffTypeChange, Path: path, Left: lv, Right: rv}}, nil } return diffSlices(path, lv, rvSlice) default: if !reflect.DeepEqual(lv, rv) { - return []Diff{{Type: "Change", Path: path, Left: lv, Right: rv}}, nil + return []Diff{{Type: DiffTypeChange, Path: path, Left: lv, Right: rv}}, nil } return nil, nil } diff --git a/cli/fn/cmdeval/cmdeval.go b/cli/fn/cmdeval/cmdeval.go index 44b8fb1fa6..cfd589629b 100644 --- a/cli/fn/cmdeval/cmdeval.go +++ b/cli/fn/cmdeval/cmdeval.go @@ -71,7 +71,7 @@ func GetEvalFnRunner(ctx context.Context, parent string) *EvalFnRunner { r.Command.Flags().StringVarP(&r.FnType, "type", "t", "", "`mutator` (default) or `validator`. tell the function type for autocompletion and `--save` flag") _ = r.Command.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"mutator", "validator"}, cobra.ShellCompDirectiveDefault + return []string{fnTypeMutator, fnTypeValidator}, cobra.ShellCompDirectiveDefault }) r.Command.Flags().BoolVarP( &r.SaveFn, "save", "s", false, @@ -147,6 +147,12 @@ func EvalCommand(ctx context.Context, name string) *cobra.Command { return GetEvalFnRunner(ctx, name).Command } +// Function type values accepted by the --type flag. +const ( + fnTypeMutator = "mutator" + fnTypeValidator = "validator" +) + // EvalFnRunner contains the run function type EvalFnRunner struct { Command *cobra.Command @@ -291,9 +297,9 @@ func (r *EvalFnRunner) SaveFnToKptfile() { } var usrMsg string switch r.FnType { - case "mutator": + case fnTypeMutator: kf.Pipeline.Mutators, usrMsg = r.updateFnList(kf.Pipeline.Mutators) - case "validator": + case fnTypeValidator: kf.Pipeline.Validators, usrMsg = r.updateFnList(kf.Pipeline.Validators) } @@ -458,7 +464,7 @@ func (r *EvalFnRunner) validateOptionalFlags() error { if r.FnType == "" { return fmt.Errorf("--type must be specified if saving functions to Kptfile (--save=true)") } - if r.FnType != "mutator" && r.FnType != "validator" { + if r.FnType != fnTypeMutator && r.FnType != fnTypeValidator { return fmt.Errorf("--type must be either `mutator` or `validator`") } } diff --git a/make/info.mk b/make/info.mk index 71e09f9716..1d2458c594 100644 --- a/make/info.mk +++ b/make/info.mk @@ -13,7 +13,7 @@ # limitations under the License. GOLANG_VERSION := 1.26.3 -GOLANGCI_LINT_VERSION := 2.11.4 +GOLANGCI_LINT_VERSION := 2.15.0 SWAGGER_VERSION := v0.33.1 GORELEASER_CONFIG = release/tag/goreleaser.yaml diff --git a/pkg/live/inventoryrg.go b/pkg/live/inventoryrg.go index a2ac526ed9..a27beb0482 100644 --- a/pkg/live/inventoryrg.go +++ b/pkg/live/inventoryrg.go @@ -48,6 +48,13 @@ const ( applyRGPollInterval = 2 * time.Second ) +// Field names used in constructing unstructured inventory objects. +const ( + fieldKind = "kind" + fieldName = "name" + fieldNamespace = "namespace" +) + // ResourceGroupGVK is the group/version/kind of the custom // resource used to store inventory. var ResourceGroupGVK = schema.GroupVersionKind{ @@ -156,11 +163,11 @@ func (icm *InventoryResourceGroup) Load() (object.ObjMetadataSet, error) { klog.V(4).Infof("loading %d inventory items", len(items)) for _, itemUncast := range items { item := itemUncast.(map[string]any) - namespace, _, err := unstructured.NestedString(item, "namespace") + namespace, _, err := unstructured.NestedString(item, fieldNamespace) if err != nil { return []object.ObjMetadata{}, err } - name, _, err := unstructured.NestedString(item, "name") + name, _, err := unstructured.NestedString(item, fieldName) if err != nil { return []object.ObjMetadata{}, err } @@ -168,7 +175,7 @@ func (icm *InventoryResourceGroup) Load() (object.ObjMetadataSet, error) { if err != nil { return []object.ObjMetadata{}, err } - kind, _, err := unstructured.NestedString(item, "kind") + kind, _, err := unstructured.NestedString(item, fieldKind) if err != nil { return []object.ObjMetadata{}, err } @@ -213,10 +220,10 @@ func (icm *InventoryResourceGroup) GetObject() (*unstructured.Unstructured, erro for _, objMeta := range icm.objMetas { klog.V(4).Infof("storing inventory obj refercence: %s/%s", objMeta.Namespace, objMeta.Name) objs = append(objs, map[string]any{ - "group": objMeta.GroupKind.Group, - "kind": objMeta.GroupKind.Kind, - "namespace": objMeta.Namespace, - "name": objMeta.Name, + "group": objMeta.GroupKind.Group, + fieldKind: objMeta.GroupKind.Kind, + fieldNamespace: objMeta.Namespace, + fieldName: objMeta.Name, }) } klog.V(4).Infof("Creating list of %d resources status", len(icm.objMetas)) @@ -226,14 +233,14 @@ func (icm *InventoryResourceGroup) GetObject() (*unstructured.Unstructured, erro if found { klog.V(4).Infof("storing inventory obj refercence and its status: %s/%s", objMeta.Namespace, objMeta.Name) objStatus = append(objStatus, map[string]any{ - "group": objMeta.GroupKind.Group, - "kind": objMeta.GroupKind.Kind, - "namespace": objMeta.Namespace, - "name": objMeta.Name, - "status": "Unknown", - "strategy": status.Strategy.String(), - "actuation": status.Actuation.String(), - "reconcile": status.Reconcile.String(), + "group": objMeta.GroupKind.Group, + fieldKind: objMeta.GroupKind.Kind, + fieldNamespace: objMeta.Namespace, + fieldName: objMeta.Name, + "status": "Unknown", + "strategy": status.Strategy.String(), + "actuation": status.Actuation.String(), + "reconcile": status.Reconcile.String(), }) } } diff --git a/pkg/live/load.go b/pkg/live/load.go index 7d39bcf7ea..47495543b6 100644 --- a/pkg/live/load.go +++ b/pkg/live/load.go @@ -289,7 +289,7 @@ func validateInventory(inventory kptfilev1.Inventory) error { var violations errors.Violations if inventory.Name == "" { violations = append(violations, errors.Violation{ - Field: "name", + Field: fieldName, Value: inventory.Name, Type: errors.Missing, Reason: "\"inventory.name\" must not be empty", @@ -297,7 +297,7 @@ func validateInventory(inventory kptfilev1.Inventory) error { } if inventory.Namespace == "" { violations = append(violations, errors.Violation{ - Field: "namespace", + Field: fieldNamespace, Value: inventory.Namespace, Type: errors.Missing, Reason: "\"inventory.namespace\" must not be empty", @@ -345,10 +345,10 @@ func generateInventoryObj(inv kptfilev1.Inventory) *unstructured.Unstructured { var inventoryObj = &unstructured.Unstructured{ Object: map[string]any{ "apiVersion": groupVersion, - "kind": ResourceGroupGVK.Kind, + fieldKind: ResourceGroupGVK.Kind, "metadata": map[string]any{ - "name": inv.Name, - "namespace": inv.Namespace, + fieldName: inv.Name, + fieldNamespace: inv.Namespace, "labels": map[string]any{ common.InventoryLabel: inv.InventoryID, }, diff --git a/scripts/go-upgrade/README.md b/scripts/go-upgrade/README.md index bc29c73acd..b4a5973e58 100644 --- a/scripts/go-upgrade/README.md +++ b/scripts/go-upgrade/README.md @@ -87,7 +87,7 @@ FORK_OWNER=kptdev ./upgrade.sh all --push --force # ← allowed ```bash TARGET_GO_VERSION="1.26.9" -TARGET_GOLANGCI_LINT_VERSION="2.12.2" +TARGET_GOLANGCI_LINT_VERSION="2.15.0" ``` ### Repository Format diff --git a/scripts/go-upgrade/config.env b/scripts/go-upgrade/config.env index f50591f1cc..098515655f 100644 --- a/scripts/go-upgrade/config.env +++ b/scripts/go-upgrade/config.env @@ -22,7 +22,7 @@ FORK_OWNER="${FORK_OWNER:-Nordix}" # --- Target versions --- TARGET_GO_VERSION="1.26.9" -TARGET_GOLANGCI_LINT_VERSION="2.12.1" +TARGET_GOLANGCI_LINT_VERSION="2.15.0" # --- Workspace --- WORKSPACE_DIR="workspace" From 47c38b1526eff1a62aa71f31863d4c1ac609cbbe Mon Sep 17 00:00:00 2001 From: Aravindhan Ayyanathan Date: Fri, 13 Nov 2026 13:21:24 +0000 Subject: [PATCH 2/2] ci: trigger build-test on make/** and .golangci.yml changes Signed-off-by: Aravindhan Ayyanathan --- .github/workflows/go.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ad43f3d20d..94d9f2e7a4 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -48,6 +48,8 @@ jobs: - 'mdtogo/**' - 'scripts/**' - 'Makefile' + - 'make/**' + - '.golangci.yml' - 'go.mod' - 'go.sum' - '.github/workflows/go.yml'