Skip to content

Commit e728a02

Browse files
committed
Bump to golangci-lint 2.x
golangci-lint 1.x is obsolete. Move with the times.
1 parent 1e46c6b commit e728a02

File tree

26 files changed

+196
-164
lines changed

26 files changed

+196
-164
lines changed

.golangci.yaml

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,72 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
modules-download-mode: vendor
4-
issues:
5-
exclude-dirs:
6-
- vendor
7-
exclude-rules:
8-
# Temporarily disable the deprecation warnings until we rewrite the code based on deprecated functionality.
9-
- linters:
10-
- staticcheck
11-
text: "SA1019: .* deprecated"
124
linters:
13-
disable-all: true
5+
default: none
146
enable:
15-
- errcheck
167
- bodyclose
17-
- gosimple
8+
- errcheck
189
- govet
1910
- ineffassign
2011
- misspell
2112
- nolintlint
2213
- nosprintfhostport
2314
- staticcheck
24-
- tenv
25-
- typecheck
2615
- unconvert
2716
- unused
2817
- wastedassign
2918
- whitespace
30-
linters-settings:
31-
errcheck:
19+
settings:
3220
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
3321
# default is false: such cases aren't reported by default.
34-
check-blank: false
35-
misspell:
22+
errcheck:
23+
check-blank: false
3624
# Do not set locale explicitly, the default is to use a neutral variety of English.
3725
# Setting locale to US will cause correcting the British spelling of 'colour' to 'color'.
3826
# locale: US
39-
ignore-words:
40-
- NTO
41-
- nto
27+
misspell:
28+
ignore-rules:
29+
- NTO
30+
- nto
31+
exclusions:
32+
generated: lax
33+
presets:
34+
- comments
35+
- common-false-positives
36+
- legacy
37+
- std-error-handling
38+
rules:
39+
# Technical debt, ReportViaDeprecatedReporter() will be removed in future ginkgo versions.
40+
- linters:
41+
- staticcheck
42+
text: "SA1019: reporters.ReportViaDeprecatedReporter is deprecated"
43+
# Dot imports shouldn't be used, unfortunately they are.
44+
- linters:
45+
- staticcheck
46+
text: 'ST1001: should not use dot imports'
47+
# sttrings.Replace(..., -1) is being used by pkg/manifests/bindata.go
48+
- linters:
49+
- staticcheck
50+
text: 'QF1004: could use strings.ReplaceAll instead'
51+
# Sometimes there's a valid reason for capitalization, such as k8s resource names.
52+
- linters:
53+
- staticcheck
54+
text: 'ST1005: error strings should not be capitalized'
55+
- linters:
56+
- staticcheck
57+
text: 'QF1011: could omit type'
58+
- linters:
59+
- staticcheck
60+
text: 'ST1023: should omit type'
61+
paths:
62+
- vendor
63+
- third_party$
64+
- builtin$
65+
- examples$
66+
formatters:
67+
exclusions:
68+
generated: lax
69+
paths:
70+
- third_party$
71+
- builtin$
72+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ PAO_CRD_APIS :=$(addprefix ./$(API_TYPES_DIR)/performanceprofile/,v2 v1 v1alpha1
5555
PAO_E2E_SUITES := $(shell hack/list-test-bin.sh)
5656

5757
# golangci-lint variables
58-
GOLANGCI_LINT_VERSION=1.64.8
58+
GOLANGCI_LINT_VERSION=2.2.1
5959
GOLANGCI_LINT_BIN=$(OUT_DIR)/golangci-lint
6060
GOLANGCI_LINT_VERSION_TAG=v${GOLANGCI_LINT_VERSION}
6161

pkg/operator/controller.go

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333

3434
tunedv1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1"
3535
ntoclient "github.com/openshift/cluster-node-tuning-operator/pkg/client"
36-
"github.com/openshift/cluster-node-tuning-operator/pkg/config"
3736
ntoconfig "github.com/openshift/cluster-node-tuning-operator/pkg/config"
3837
tunedset "github.com/openshift/cluster-node-tuning-operator/pkg/generated/clientset/versioned"
3938
tunedinformers "github.com/openshift/cluster-node-tuning-operator/pkg/generated/informers/externalversions"
@@ -383,7 +382,7 @@ func (c *Controller) sync(key wqKey) error {
383382

384383
// In HyperShift clusters, any Tuned changes should be overwritten by the tuned config
385384
// in the management cluster
386-
if config.InHyperShift() {
385+
if ntoconfig.InHyperShift() {
387386
err = c.syncHostedClusterTuneds()
388387
if err != nil {
389388
return fmt.Errorf("failed to sync hosted cluster Tuneds: %v", err)
@@ -534,7 +533,7 @@ func (c *Controller) syncDaemonSet(tuned *tunedv1.Tuned) error {
534533
var update bool
535534

536535
dsMf := ntomf.TunedDaemonSet()
537-
dsMf.ObjectMeta.OwnerReferences = getDefaultTunedRefs(tuned)
536+
dsMf.OwnerReferences = getDefaultTunedRefs(tuned)
538537

539538
ds, err := c.listers.DaemonSets.Get(dsMf.Name)
540539
if err != nil {
@@ -588,7 +587,7 @@ func (c *Controller) syncDaemonSet(tuned *tunedv1.Tuned) error {
588587

589588
func (c *Controller) syncProfile(tuned *tunedv1.Tuned, nodeName string) error {
590589
profileMf := ntomf.TunedProfile()
591-
profileMf.ObjectMeta.OwnerReferences = getDefaultTunedRefs(tuned)
590+
profileMf.OwnerReferences = getDefaultTunedRefs(tuned)
592591

593592
profileMf.Name = nodeName
594593
delete(c.bootcmdlineConflict, nodeName)
@@ -795,7 +794,7 @@ func (c *Controller) syncMachineConfig(labels map[string]string, profile *tunedv
795794

796795
if ok := c.allNodesAgreeOnBootcmdline(nodes); !ok {
797796
// Log an error and do not requeue, this is a configuration issue.
798-
klog.Errorf("not all %d Nodes in MCP %v agree on bootcmdline: %s", len(nodes), pools[0].ObjectMeta.Name, bootcmdline)
797+
klog.Errorf("not all %d Nodes in MCP %v agree on bootcmdline: %s", len(nodes), pools[0].Name, bootcmdline)
799798
return nil
800799
}
801800

@@ -816,9 +815,9 @@ func (c *Controller) syncMachineConfig(labels map[string]string, profile *tunedv
816815
mc = NewMachineConfig(name, annotations, labels, kernelArguments)
817816
_, err = c.clients.MC.MachineconfigurationV1().MachineConfigs().Create(context.TODO(), mc, metav1.CreateOptions{})
818817
if err != nil {
819-
return fmt.Errorf("failed to create MachineConfig %s: %v", mc.ObjectMeta.Name, err)
818+
return fmt.Errorf("failed to create MachineConfig %s: %v", mc.Name, err)
820819
}
821-
klog.Infof("created MachineConfig %s with%s", mc.ObjectMeta.Name, MachineConfigGenerationLogLine(len(bootcmdline) != 0, bootcmdline))
820+
klog.Infof("created MachineConfig %s with%s", mc.Name, MachineConfigGenerationLogLine(len(bootcmdline) != 0, bootcmdline))
822821
return nil
823822
}
824823
return err
@@ -829,22 +828,22 @@ func (c *Controller) syncMachineConfig(labels map[string]string, profile *tunedv
829828
kernelArgsEq := util.StringSlicesEqual(mc.Spec.KernelArguments, kernelArguments)
830829
if kernelArgsEq {
831830
// No update needed
832-
klog.V(2).Infof("syncMachineConfig(): MachineConfig %s doesn't need updating", mc.ObjectMeta.Name)
831+
klog.V(2).Infof("syncMachineConfig(): MachineConfig %s doesn't need updating", mc.Name)
833832
return nil
834833
}
835834
mc = mc.DeepCopy() // never update the objects from cache
836-
mc.ObjectMeta.Annotations = mcNew.ObjectMeta.Annotations
835+
mc.Annotations = mcNew.Annotations
837836
mc.Spec.KernelArguments = kernelArguments
838837
mc.Spec.Config = mcNew.Spec.Config
839838

840839
l := MachineConfigGenerationLogLine(!kernelArgsEq, bootcmdline)
841-
klog.V(2).Infof("syncMachineConfig(): updating MachineConfig %s with%s", mc.ObjectMeta.Name, l)
840+
klog.V(2).Infof("syncMachineConfig(): updating MachineConfig %s with%s", mc.Name, l)
842841
_, err = c.clients.MC.MachineconfigurationV1().MachineConfigs().Update(context.TODO(), mc, metav1.UpdateOptions{})
843842
if err != nil {
844-
return fmt.Errorf("failed to update MachineConfig %s: %v", mc.ObjectMeta.Name, err)
843+
return fmt.Errorf("failed to update MachineConfig %s: %v", mc.Name, err)
845844
}
846845

847-
klog.Infof("updated MachineConfig %s with%s", mc.ObjectMeta.Name, l)
846+
klog.Infof("updated MachineConfig %s with%s", mc.Name, l)
848847

849848
return nil
850849
}
@@ -857,11 +856,11 @@ func (c *Controller) allNodesAgreeOnBootcmdline(nodes []*corev1.Node) bool {
857856
}
858857

859858
match := true
860-
bootcmdline := c.pc.state.bootcmdline[nodes[0].ObjectMeta.Name]
859+
bootcmdline := c.pc.state.bootcmdline[nodes[0].Name]
861860
for _, node := range nodes[1:] {
862-
if bootcmdline != c.pc.state.bootcmdline[node.ObjectMeta.Name] {
863-
klog.V(2).Infof("found a conflicting bootcmdline %q for Node %q", c.pc.state.bootcmdline[node.ObjectMeta.Name], node.ObjectMeta.Name)
864-
c.bootcmdlineConflict[node.ObjectMeta.Name] = true
861+
if bootcmdline != c.pc.state.bootcmdline[node.Name] {
862+
klog.V(2).Infof("found a conflicting bootcmdline %q for Node %q", c.pc.state.bootcmdline[node.Name], node.Name)
863+
c.bootcmdlineConflict[node.Name] = true
865864
match = false
866865
}
867866
}
@@ -906,14 +905,14 @@ func (c *Controller) syncMachineConfigHyperShift(nodePoolName string, profile *t
906905
// put the MC into a ConfigMap and create that instead
907906
mcConfigMap, err = c.newConfigMapForMachineConfig(configMapName, nodePoolName, mc)
908907
if err != nil {
909-
klog.Errorf("failed to generate ConfigMap %s for MachineConfig %s: %v", configMapName, mc.ObjectMeta.Name, err)
908+
klog.Errorf("failed to generate ConfigMap %s for MachineConfig %s: %v", configMapName, mc.Name, err)
910909
return nil
911910
}
912911
_, err = c.clients.ManagementKube.CoreV1().ConfigMaps(ntoconfig.OperatorNamespace()).Create(context.TODO(), mcConfigMap, metav1.CreateOptions{})
913912
if err != nil {
914-
return fmt.Errorf("failed to create ConfigMap %s for MachineConfig %s: %v", configMapName, mc.ObjectMeta.Name, err)
913+
return fmt.Errorf("failed to create ConfigMap %s for MachineConfig %s: %v", configMapName, mc.Name, err)
915914
}
916-
klog.Infof("created ConfigMap %s for MachineConfig %s with%s", configMapName, mc.ObjectMeta.Name, MachineConfigGenerationLogLine(len(bootcmdline) != 0, bootcmdline))
915+
klog.Infof("created ConfigMap %s for MachineConfig %s with%s", configMapName, mc.Name, MachineConfigGenerationLogLine(len(bootcmdline) != 0, bootcmdline))
917916
return nil
918917
}
919918
return err
@@ -942,18 +941,18 @@ func (c *Controller) syncMachineConfigHyperShift(nodePoolName string, profile *t
942941
// If mcfgs are equivalent don't update
943942
if kernelArgsEq && cmLabelsAndAnnotationsCorrect {
944943
// No update needed
945-
klog.V(2).Infof("syncMachineConfigHyperShift(): MachineConfig %s doesn't need updating", mc.ObjectMeta.Name)
944+
klog.V(2).Infof("syncMachineConfigHyperShift(): MachineConfig %s doesn't need updating", mc.Name)
946945
return nil
947946
}
948947

949948
// If mcfgs are not equivalent do update
950949
mc = mc.DeepCopy() // never update the objects from cache
951-
mc.ObjectMeta.Annotations = mcNew.ObjectMeta.Annotations
950+
mc.Annotations = mcNew.Annotations
952951
mc.Spec.KernelArguments = kernelArguments
953952
mc.Spec.Config = mcNew.Spec.Config
954953

955954
l := MachineConfigGenerationLogLine(!kernelArgsEq, bootcmdline)
956-
klog.V(2).Infof("syncMachineConfigHyperShift(): updating MachineConfig %s with%s", mc.ObjectMeta.Name, l)
955+
klog.V(2).Infof("syncMachineConfigHyperShift(): updating MachineConfig %s with%s", mc.Name, l)
957956

958957
newData, err := c.serializeMachineConfig(mc)
959958
if err != nil {
@@ -973,7 +972,7 @@ func (c *Controller) syncMachineConfigHyperShift(nodePoolName string, profile *t
973972
return fmt.Errorf("failed to update ConfigMap for MachineConfig %s: %v", mcConfigMap.Name, err)
974973
}
975974

976-
klog.Infof("updated ConfigMap %s for MachineConfig %s with%s", mcConfigMap.Name, mc.ObjectMeta.Name, l)
975+
klog.Infof("updated ConfigMap %s for MachineConfig %s with%s", mcConfigMap.Name, mc.Name, l)
977976

978977
return nil
979978
}
@@ -991,25 +990,25 @@ func (c *Controller) pruneMachineConfigs() error {
991990
}
992991

993992
for _, mc := range mcList {
994-
if mc.ObjectMeta.Annotations != nil {
995-
if _, ok := mc.ObjectMeta.Annotations[GeneratedByControllerVersionAnnotationKey]; !ok {
993+
if mc.Annotations != nil {
994+
if _, ok := mc.Annotations[GeneratedByControllerVersionAnnotationKey]; !ok {
996995
continue
997996
}
998997
// mc's annotations have the controller/operator key
999998

1000-
if mcNames[mc.ObjectMeta.Name] {
999+
if mcNames[mc.Name] {
10011000
continue
10021001
}
10031002
// This MachineConfig has this operator's annotations and it is not currently used by any
10041003
// Tuned CR; remove it and let MCO roll-back any changes
10051004

1006-
klog.V(2).Infof("pruneMachineConfigs(): deleting MachineConfig %s", mc.ObjectMeta.Name)
1007-
err = c.clients.MC.MachineconfigurationV1().MachineConfigs().Delete(context.TODO(), mc.ObjectMeta.Name, metav1.DeleteOptions{})
1005+
klog.V(2).Infof("pruneMachineConfigs(): deleting MachineConfig %s", mc.Name)
1006+
err = c.clients.MC.MachineconfigurationV1().MachineConfigs().Delete(context.TODO(), mc.Name, metav1.DeleteOptions{})
10081007
if err != nil {
10091008
// Unable to delete the MachineConfig
10101009
return err
10111010
}
1012-
klog.Infof("deleted MachineConfig %s", mc.ObjectMeta.Name)
1011+
klog.Infof("deleted MachineConfig %s", mc.Name)
10131012
}
10141013
}
10151014

@@ -1032,24 +1031,24 @@ func (c *Controller) pruneMachineConfigsHyperShift() error {
10321031
}
10331032

10341033
for _, cm := range cmList.Items {
1035-
if cm.ObjectMeta.Annotations != nil {
1036-
if _, ok := cm.ObjectMeta.Annotations[GeneratedByControllerVersionAnnotationKey]; !ok {
1034+
if cm.Annotations != nil {
1035+
if _, ok := cm.Annotations[GeneratedByControllerVersionAnnotationKey]; !ok {
10371036
continue
10381037
}
10391038
// mc's annotations have the controller/operator key
1040-
if mcNames[cm.ObjectMeta.Name] {
1039+
if mcNames[cm.Name] {
10411040
continue
10421041
}
10431042

10441043
// This ConfigMap has this operator's annotations and it is not currently used by any
10451044
// Tuned CR; remove it and let MCO roll-back any changes
1046-
klog.V(2).Infof("pruneMachineConfigsHyperShift(): deleting ConfigMap %s", cm.ObjectMeta.Name)
1047-
err = c.clients.ManagementKube.CoreV1().ConfigMaps(ntoconfig.OperatorNamespace()).Delete(context.TODO(), cm.ObjectMeta.Name, metav1.DeleteOptions{})
1045+
klog.V(2).Infof("pruneMachineConfigsHyperShift(): deleting ConfigMap %s", cm.Name)
1046+
err = c.clients.ManagementKube.CoreV1().ConfigMaps(ntoconfig.OperatorNamespace()).Delete(context.TODO(), cm.Name, metav1.DeleteOptions{})
10481047
if err != nil {
10491048
// Unable to delete the ConfigMap
10501049
return err
10511050
}
1052-
klog.Infof("deleted MachineConfig ConfigMap %s", cm.ObjectMeta.Name)
1051+
klog.Infof("deleted MachineConfig ConfigMap %s", cm.Name)
10531052
}
10541053
}
10551054

pkg/operator/hypershift.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ func (c *Controller) syncHostedClusterTuneds() error {
6060
klog.V(1).Infof("hosted cluster already contains Tuned %v from ConfigMap", tunedName)
6161
if reflect.DeepEqual(cmTuned.Spec.Profile, hcTuned.Spec.Profile) &&
6262
reflect.DeepEqual(cmTuned.Spec.Recommend, hcTuned.Spec.Recommend) &&
63-
reflect.DeepEqual(cmTuned.ObjectMeta.Labels, hcTuned.ObjectMeta.Labels) {
64-
klog.V(2).Infof("hosted cluster version of Tuned %v matches the ConfigMap %s config", tunedName, cmTuned.ObjectMeta.Name)
63+
reflect.DeepEqual(cmTuned.Labels, hcTuned.Labels) {
64+
klog.V(2).Infof("hosted cluster version of Tuned %v matches the ConfigMap %s config", tunedName, cmTuned.Name)
6565
} else {
6666
// This Tuned exists in the hosted cluster but is out-of-sync with the management configuration
6767
newTuned := hcTuned.DeepCopy() // never update the objects from cache
6868
newTuned.Spec.Profile = cmTuned.Spec.Profile
6969
newTuned.Spec.Recommend = cmTuned.Spec.Recommend
7070

71-
klog.V(2).Infof("updating Tuned %v from ConfigMap %s", tunedName, cmTuned.ObjectMeta.Name)
71+
klog.V(2).Infof("updating Tuned %v from ConfigMap %s", tunedName, cmTuned.Name)
7272
_, err = c.clients.Tuned.TunedV1().Tuneds(ntoconfig.WatchNamespace()).Update(context.TODO(), newTuned, metav1.UpdateOptions{})
7373
if err != nil {
7474
if errors.IsInvalid(err) {
@@ -83,7 +83,7 @@ func (c *Controller) syncHostedClusterTuneds() error {
8383
delete(hcTunedMap, tunedName)
8484
delete(cmTunedMap, tunedName)
8585
} else {
86-
klog.V(1).Infof("need to create Tuned %v based on ConfigMap %s", cmTuned.ObjectMeta.Name, tunedName)
86+
klog.V(1).Infof("need to create Tuned %v based on ConfigMap %s", cmTuned.Name, tunedName)
8787
// Create the Tuned in the hosted cluster from the config in ConfigMap
8888
newTuned := cmTuned.DeepCopy()
8989
_, err := c.clients.Tuned.TunedV1().Tuneds(ntoconfig.WatchNamespace()).Create(context.TODO(), newTuned, metav1.CreateOptions{})
@@ -135,31 +135,31 @@ func (c *Controller) getObjFromTunedConfigMap() ([]tunedv1.Tuned, error) {
135135
if !ok {
136136
tunedConfig, ok = cm.Data[tunedConfigMapConfigKeyDeprecated]
137137
if !ok {
138-
klog.Warningf("ConfigMap %s has no data in field %s or %s (deprecated). Expected Tuned manifests.", cm.ObjectMeta.Name, tuningConfigMapConfigKey, tunedConfigMapConfigKeyDeprecated)
138+
klog.Warningf("ConfigMap %s has no data in field %s or %s (deprecated). Expected Tuned manifests.", cm.Name, tuningConfigMapConfigKey, tunedConfigMapConfigKeyDeprecated)
139139
continue
140140
} else {
141-
klog.Infof("Deprecated key %s used in ConfigMap %s", tunedConfigMapConfigKeyDeprecated, cm.ObjectMeta.Name)
141+
klog.Infof("Deprecated key %s used in ConfigMap %s", tunedConfigMapConfigKeyDeprecated, cm.Name)
142142
}
143143
}
144144

145145
cmNodePoolNamespacedName, ok := cm.Annotations[hypershiftNodePoolLabel]
146146
if !ok {
147-
klog.Warningf("failed to parseTunedManifests in ConfigMap %s, no label %s", cm.ObjectMeta.Name, hypershiftNodePoolLabel)
147+
klog.Warningf("failed to parseTunedManifests in ConfigMap %s, no label %s", cm.Name, hypershiftNodePoolLabel)
148148
continue
149149
}
150150
nodePoolName := parseNamespacedName(cmNodePoolNamespacedName)
151151

152152
tunedsFromConfigMap, err := parseTunedManifests([]byte(tunedConfig), nodePoolName)
153153
if err != nil {
154-
klog.Warningf("failed to parseTunedManifests in ConfigMap %s: %v", cm.ObjectMeta.Name, err)
154+
klog.Warningf("failed to parseTunedManifests in ConfigMap %s: %v", cm.Name, err)
155155
continue
156156
}
157157

158158
tunedsFromConfigMapUnique := []tunedv1.Tuned{}
159159
for j, t := range tunedsFromConfigMap {
160-
tunedObjectName := tunedsFromConfigMap[j].ObjectMeta.Name
160+
tunedObjectName := tunedsFromConfigMap[j].Name
161161
if seenTunedObject[tunedObjectName] {
162-
klog.Warningf("ignoring duplicate Tuned Profile %s in ConfigMap %s", tunedObjectName, cm.ObjectMeta.Name)
162+
klog.Warningf("ignoring duplicate Tuned Profile %s in ConfigMap %s", tunedObjectName, cm.Name)
163163
continue
164164
}
165165
seenTunedObject[tunedObjectName] = true
@@ -203,7 +203,7 @@ func parseTunedManifests(data []byte, nodePoolName string) ([]tunedv1.Tuned, err
203203
}
204204
// Make Tuned names unique if a Tuned is duplicated across NodePools
205205
// for example, if one ConfigMap is referenced in multiple NodePools
206-
t.SetName(MakeTunedUniqueName(t.ObjectMeta.Name, nodePoolName))
206+
t.SetName(MakeTunedUniqueName(t.Name, nodePoolName))
207207
klog.V(2).Infof("parseTunedManifests: name: %s", t.GetName())
208208

209209
// Propagate NodePool name from ConfigMap down to Tuned object
@@ -221,7 +221,7 @@ func mcConfigMapName(name string) string {
221221

222222
func hashStruct(o interface{}) string {
223223
hash := fnv.New32a()
224-
hash.Write([]byte(fmt.Sprintf("%v", o)))
224+
fmt.Fprintf(hash, "%v", o)
225225
intHash := hash.Sum32()
226226
return fmt.Sprintf("%08x", intHash)
227227
}

0 commit comments

Comments
 (0)