Skip to content

Commit edc5f4d

Browse files
authored
Upgrade golangci-lint to 2.15.0 (#4875)
* 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 <aravindhan.a@est.tech> * ci: trigger build-test on make/** and .golangci.yml changes Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech> --------- Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
1 parent 5c6b7fb commit edc5f4d

9 files changed

Lines changed: 59 additions & 37 deletions

File tree

‎.github/workflows/go.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jobs:
4848
- 'mdtogo/**'
4949
- 'scripts/**'
5050
- 'Makefile'
51+
- 'make/**'
52+
- '.golangci.yml'
5153
- 'go.mod'
5254
- 'go.sum'
5355
- '.github/workflows/go.yml'

‎cli/alpha/live/plan/command.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ func findAndPrintDiff(before, after *unstructured.Unstructured, prefix string, i
220220
}
221221

222222
switch d.Type {
223-
case "LeftAdd":
223+
case DiffTypeLeftAdd:
224224
txt := print.SprintfWithColor(print.RED, "%s-%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Left)))
225225
fmt.Fprint(ioStreams.Out, txt)
226-
case "RightAdd":
226+
case DiffTypeRightAdd:
227227
txt := print.SprintfWithColor(print.GREEN, "%s+%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Right)))
228228
fmt.Fprint(ioStreams.Out, txt)
229-
case "Change":
229+
case DiffTypeChange:
230230
txt1 := print.SprintfWithColor(print.RED, "%s-%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Left)))
231231
fmt.Fprint(ioStreams.Out, txt1)
232232
txt2 := print.SprintfWithColor(print.GREEN, "%s+%s: %s\n", prefix, d.Path, strings.TrimSpace(fmt.Sprintf("%v", d.Right)))

‎cli/alpha/live/plan/diff.go‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ type Diff struct {
2828
Path string
2929
}
3030

31+
// Diff.Type values.
32+
const (
33+
DiffTypeLeftAdd = "LeftAdd"
34+
DiffTypeRightAdd = "RightAdd"
35+
DiffTypeChange = "Change"
36+
)
37+
3138
func diffObjects(b, a *unstructured.Unstructured) ([]Diff, error) {
3239
diffs, err := diffMaps("", b.Object, a.Object)
3340
if err != nil {
@@ -43,7 +50,7 @@ func diffMaps(prefix string, l, r map[string]any) ([]Diff, error) {
4350

4451
rv, ok := r[k]
4552
if !ok {
46-
diffs = append(diffs, Diff{Type: "LeftAdd", Path: childPrefix, Left: lv, Right: rv})
53+
diffs = append(diffs, Diff{Type: DiffTypeLeftAdd, Path: childPrefix, Left: lv, Right: rv})
4754
continue
4855
}
4956
childDiffs, err := diffValue(childPrefix, lv, rv)
@@ -58,7 +65,7 @@ func diffMaps(prefix string, l, r map[string]any) ([]Diff, error) {
5865

5966
lv, ok := l[k]
6067
if !ok {
61-
diffs = append(diffs, Diff{Type: "RightAdd", Path: childPrefix, Left: lv, Right: rv})
68+
diffs = append(diffs, Diff{Type: DiffTypeRightAdd, Path: childPrefix, Left: lv, Right: rv})
6269
continue
6370
}
6471
}
@@ -72,7 +79,7 @@ func diffSlices(prefix string, l, r []any) ([]Diff, error) {
7279
childPrefix := prefix + "." + strconv.Itoa(i)
7380

7481
if len(r) <= i {
75-
diffs = append(diffs, Diff{Type: "LeftAdd", Path: childPrefix, Left: l[i], Right: nil})
82+
diffs = append(diffs, Diff{Type: DiffTypeLeftAdd, Path: childPrefix, Left: l[i], Right: nil})
7683
continue
7784
}
7885
rv := r[i]
@@ -87,7 +94,7 @@ func diffSlices(prefix string, l, r []any) ([]Diff, error) {
8794
childPrefix := prefix + "." + strconv.Itoa(i)
8895

8996
if len(l) <= i {
90-
diffs = append(diffs, Diff{Type: "RightAdd", Path: childPrefix, Left: nil, Right: rv})
97+
diffs = append(diffs, Diff{Type: DiffTypeRightAdd, Path: childPrefix, Left: nil, Right: rv})
9198
continue
9299
}
93100
}
@@ -110,20 +117,20 @@ func diffValue(path string, lv, rv any) ([]Diff, error) {
110117
case map[string]any:
111118
rvMap, ok := rv.(map[string]any)
112119
if !ok {
113-
return []Diff{{Type: "Change", Path: path, Left: lv, Right: rv}}, nil
120+
return []Diff{{Type: DiffTypeChange, Path: path, Left: lv, Right: rv}}, nil
114121
}
115122
return diffMaps(path, lv, rvMap)
116123

117124
case []any:
118125
rvSlice, ok := rv.([]any)
119126
if !ok {
120-
return []Diff{{Type: "Change", Path: path, Left: lv, Right: rv}}, nil
127+
return []Diff{{Type: DiffTypeChange, Path: path, Left: lv, Right: rv}}, nil
121128
}
122129
return diffSlices(path, lv, rvSlice)
123130

124131
default:
125132
if !reflect.DeepEqual(lv, rv) {
126-
return []Diff{{Type: "Change", Path: path, Left: lv, Right: rv}}, nil
133+
return []Diff{{Type: DiffTypeChange, Path: path, Left: lv, Right: rv}}, nil
127134
}
128135
return nil, nil
129136
}

‎cli/fn/cmdeval/cmdeval.go‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func GetEvalFnRunner(ctx context.Context, parent string) *EvalFnRunner {
7171
r.Command.Flags().StringVarP(&r.FnType, "type", "t", "",
7272
"`mutator` (default) or `validator`. tell the function type for autocompletion and `--save` flag")
7373
_ = r.Command.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
74-
return []string{"mutator", "validator"}, cobra.ShellCompDirectiveDefault
74+
return []string{fnTypeMutator, fnTypeValidator}, cobra.ShellCompDirectiveDefault
7575
})
7676
r.Command.Flags().BoolVarP(
7777
&r.SaveFn, "save", "s", false,
@@ -147,6 +147,12 @@ func EvalCommand(ctx context.Context, name string) *cobra.Command {
147147
return GetEvalFnRunner(ctx, name).Command
148148
}
149149

150+
// Function type values accepted by the --type flag.
151+
const (
152+
fnTypeMutator = "mutator"
153+
fnTypeValidator = "validator"
154+
)
155+
150156
// EvalFnRunner contains the run function
151157
type EvalFnRunner struct {
152158
Command *cobra.Command
@@ -291,9 +297,9 @@ func (r *EvalFnRunner) SaveFnToKptfile() {
291297
}
292298
var usrMsg string
293299
switch r.FnType {
294-
case "mutator":
300+
case fnTypeMutator:
295301
kf.Pipeline.Mutators, usrMsg = r.updateFnList(kf.Pipeline.Mutators)
296-
case "validator":
302+
case fnTypeValidator:
297303
kf.Pipeline.Validators, usrMsg = r.updateFnList(kf.Pipeline.Validators)
298304
}
299305

@@ -458,7 +464,7 @@ func (r *EvalFnRunner) validateOptionalFlags() error {
458464
if r.FnType == "" {
459465
return fmt.Errorf("--type must be specified if saving functions to Kptfile (--save=true)")
460466
}
461-
if r.FnType != "mutator" && r.FnType != "validator" {
467+
if r.FnType != fnTypeMutator && r.FnType != fnTypeValidator {
462468
return fmt.Errorf("--type must be either `mutator` or `validator`")
463469
}
464470
}

‎make/info.mk‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
GOLANG_VERSION := 1.26.3
16-
GOLANGCI_LINT_VERSION := 2.11.4
16+
GOLANGCI_LINT_VERSION := 2.15.0
1717
SWAGGER_VERSION := v0.33.1
1818

1919
GORELEASER_CONFIG = release/tag/goreleaser.yaml

‎pkg/live/inventoryrg.go‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const (
4848
applyRGPollInterval = 2 * time.Second
4949
)
5050

51+
// Field names used in constructing unstructured inventory objects.
52+
const (
53+
fieldKind = "kind"
54+
fieldName = "name"
55+
fieldNamespace = "namespace"
56+
)
57+
5158
// ResourceGroupGVK is the group/version/kind of the custom
5259
// resource used to store inventory.
5360
var ResourceGroupGVK = schema.GroupVersionKind{
@@ -156,19 +163,19 @@ func (icm *InventoryResourceGroup) Load() (object.ObjMetadataSet, error) {
156163
klog.V(4).Infof("loading %d inventory items", len(items))
157164
for _, itemUncast := range items {
158165
item := itemUncast.(map[string]any)
159-
namespace, _, err := unstructured.NestedString(item, "namespace")
166+
namespace, _, err := unstructured.NestedString(item, fieldNamespace)
160167
if err != nil {
161168
return []object.ObjMetadata{}, err
162169
}
163-
name, _, err := unstructured.NestedString(item, "name")
170+
name, _, err := unstructured.NestedString(item, fieldName)
164171
if err != nil {
165172
return []object.ObjMetadata{}, err
166173
}
167174
group, _, err := unstructured.NestedString(item, "group")
168175
if err != nil {
169176
return []object.ObjMetadata{}, err
170177
}
171-
kind, _, err := unstructured.NestedString(item, "kind")
178+
kind, _, err := unstructured.NestedString(item, fieldKind)
172179
if err != nil {
173180
return []object.ObjMetadata{}, err
174181
}
@@ -213,10 +220,10 @@ func (icm *InventoryResourceGroup) GetObject() (*unstructured.Unstructured, erro
213220
for _, objMeta := range icm.objMetas {
214221
klog.V(4).Infof("storing inventory obj refercence: %s/%s", objMeta.Namespace, objMeta.Name)
215222
objs = append(objs, map[string]any{
216-
"group": objMeta.GroupKind.Group,
217-
"kind": objMeta.GroupKind.Kind,
218-
"namespace": objMeta.Namespace,
219-
"name": objMeta.Name,
223+
"group": objMeta.GroupKind.Group,
224+
fieldKind: objMeta.GroupKind.Kind,
225+
fieldNamespace: objMeta.Namespace,
226+
fieldName: objMeta.Name,
220227
})
221228
}
222229
klog.V(4).Infof("Creating list of %d resources status", len(icm.objMetas))
@@ -226,14 +233,14 @@ func (icm *InventoryResourceGroup) GetObject() (*unstructured.Unstructured, erro
226233
if found {
227234
klog.V(4).Infof("storing inventory obj refercence and its status: %s/%s", objMeta.Namespace, objMeta.Name)
228235
objStatus = append(objStatus, map[string]any{
229-
"group": objMeta.GroupKind.Group,
230-
"kind": objMeta.GroupKind.Kind,
231-
"namespace": objMeta.Namespace,
232-
"name": objMeta.Name,
233-
"status": "Unknown",
234-
"strategy": status.Strategy.String(),
235-
"actuation": status.Actuation.String(),
236-
"reconcile": status.Reconcile.String(),
236+
"group": objMeta.GroupKind.Group,
237+
fieldKind: objMeta.GroupKind.Kind,
238+
fieldNamespace: objMeta.Namespace,
239+
fieldName: objMeta.Name,
240+
"status": "Unknown",
241+
"strategy": status.Strategy.String(),
242+
"actuation": status.Actuation.String(),
243+
"reconcile": status.Reconcile.String(),
237244
})
238245
}
239246
}

‎pkg/live/load.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ func validateInventory(inventory kptfilev1.Inventory) error {
289289
var violations errors.Violations
290290
if inventory.Name == "" {
291291
violations = append(violations, errors.Violation{
292-
Field: "name",
292+
Field: fieldName,
293293
Value: inventory.Name,
294294
Type: errors.Missing,
295295
Reason: "\"inventory.name\" must not be empty",
296296
})
297297
}
298298
if inventory.Namespace == "" {
299299
violations = append(violations, errors.Violation{
300-
Field: "namespace",
300+
Field: fieldNamespace,
301301
Value: inventory.Namespace,
302302
Type: errors.Missing,
303303
Reason: "\"inventory.namespace\" must not be empty",
@@ -345,10 +345,10 @@ func generateInventoryObj(inv kptfilev1.Inventory) *unstructured.Unstructured {
345345
var inventoryObj = &unstructured.Unstructured{
346346
Object: map[string]any{
347347
"apiVersion": groupVersion,
348-
"kind": ResourceGroupGVK.Kind,
348+
fieldKind: ResourceGroupGVK.Kind,
349349
"metadata": map[string]any{
350-
"name": inv.Name,
351-
"namespace": inv.Namespace,
350+
fieldName: inv.Name,
351+
fieldNamespace: inv.Namespace,
352352
"labels": map[string]any{
353353
common.InventoryLabel: inv.InventoryID,
354354
},

‎scripts/go-upgrade/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ FORK_OWNER=kptdev ./upgrade.sh all --push --force # ← allowed
8787

8888
```bash
8989
TARGET_GO_VERSION="1.26.9"
90-
TARGET_GOLANGCI_LINT_VERSION="2.12.2"
90+
TARGET_GOLANGCI_LINT_VERSION="2.15.0"
9191
```
9292

9393
### Repository Format

‎scripts/go-upgrade/config.env‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ FORK_OWNER="${FORK_OWNER:-Nordix}"
2222

2323
# --- Target versions ---
2424
TARGET_GO_VERSION="1.26.9"
25-
TARGET_GOLANGCI_LINT_VERSION="2.12.1"
25+
TARGET_GOLANGCI_LINT_VERSION="2.15.0"
2626

2727
# --- Workspace ---
2828
WORKSPACE_DIR="workspace"

0 commit comments

Comments
 (0)