Skip to content

Commit b111e50

Browse files
authored
chore: enable errorlint (#673)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 3ef5ab1 commit b111e50

17 files changed

+41
-40
lines changed

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ issues:
88
linters:
99
enable:
1010
- errcheck
11-
# - errorlint
11+
- errorlint
1212
- gocritic
1313
- gofumpt
1414
- goimports

agent/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (s *settings) parseManifests() ([]*unstructured.Unstructured, string, error
8484
}
8585
items, err := kube.SplitYAML(data)
8686
if err != nil {
87-
return fmt.Errorf("failed to parse %s: %v", path, err)
87+
return fmt.Errorf("failed to parse %s: %w", path, err)
8888
}
8989
res = append(res, items...)
9090
return nil

pkg/cache/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ func (c *clusterCache) sync() error {
977977
})
978978
if err != nil {
979979
c.log.Error(err, "Failed to sync cluster")
980-
return fmt.Errorf("failed to sync cluster %s: %v", c.config.Host, err)
980+
return fmt.Errorf("failed to sync cluster %s: %w", c.config.Host, err)
981981
}
982982

983983
c.log.Info("Cluster successfully synced")

pkg/diff/diff.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func removeWebhookMutation(predictedLive, live *unstructured.Unstructured, gvkPa
234234
mfs := &fieldpath.Set{}
235235
err := mfs.FromJSON(bytes.NewReader(mfEntry.FieldsV1.Raw))
236236
if err != nil {
237-
return nil, fmt.Errorf("error building managedFields set: %s", err)
237+
return nil, fmt.Errorf("error building managedFields set: %w", err)
238238
}
239239
if comparison.Added != nil && !comparison.Added.Empty() {
240240
// exclude the added fields owned by this manager from the comparison
@@ -262,7 +262,7 @@ func removeWebhookMutation(predictedLive, live *unstructured.Unstructured, gvkPa
262262
// revert modified fields not owned by any manager
263263
typedPredictedLive, err = typedPredictedLive.Merge(liveModValues)
264264
if err != nil {
265-
return nil, fmt.Errorf("error reverting webhook modified fields in predicted live resource: %s", err)
265+
return nil, fmt.Errorf("error reverting webhook modified fields in predicted live resource: %w", err)
266266
}
267267
}
268268

@@ -271,7 +271,7 @@ func removeWebhookMutation(predictedLive, live *unstructured.Unstructured, gvkPa
271271
// revert removed fields not owned by any manager
272272
typedPredictedLive, err = typedPredictedLive.Merge(liveRmValues)
273273
if err != nil {
274-
return nil, fmt.Errorf("error reverting webhook removed fields in predicted live resource: %s", err)
274+
return nil, fmt.Errorf("error reverting webhook removed fields in predicted live resource: %w", err)
275275
}
276276
}
277277

@@ -287,7 +287,7 @@ func jsonStrToUnstructured(jsonString string) (*unstructured.Unstructured, error
287287
res := make(map[string]any)
288288
err := json.Unmarshal([]byte(jsonString), &res)
289289
if err != nil {
290-
return nil, fmt.Errorf("unmarshal error: %s", err)
290+
return nil, fmt.Errorf("unmarshal error: %w", err)
291291
}
292292
return &unstructured.Unstructured{Object: res}, nil
293293
}
@@ -770,7 +770,7 @@ func GetLastAppliedConfigAnnotation(live *unstructured.Unstructured) (*unstructu
770770
var obj unstructured.Unstructured
771771
err := json.Unmarshal([]byte(lastAppliedStr), &obj)
772772
if err != nil {
773-
return nil, fmt.Errorf("failed to unmarshal %s in %s: %v", corev1.LastAppliedConfigAnnotation, live.GetName(), err)
773+
return nil, fmt.Errorf("failed to unmarshal %s in %s: %w", corev1.LastAppliedConfigAnnotation, live.GetName(), err)
774774
}
775775
return &obj, nil
776776
}
@@ -1027,7 +1027,7 @@ func HideSecretData(target *unstructured.Unstructured, live *unstructured.Unstru
10271027
} else {
10281028
lastAppliedData, err := json.Marshal(liveLastAppliedAnnotation)
10291029
if err != nil {
1030-
return nil, nil, fmt.Errorf("error marshaling json: %s", err)
1030+
return nil, nil, fmt.Errorf("error marshaling json: %w", err)
10311031
}
10321032
annotations[corev1.LastAppliedConfigAnnotation] = string(lastAppliedData)
10331033
}
@@ -1055,7 +1055,7 @@ func hide(target, live, liveLastAppliedAnnotation *unstructured.Unstructured, ke
10551055
var err error
10561056
data, _, err = unstructured.NestedMap(obj.Object, fields...)
10571057
if err != nil {
1058-
return nil, nil, nil, fmt.Errorf("unstructured.NestedMap error: %s", err)
1058+
return nil, nil, nil, fmt.Errorf("unstructured.NestedMap error: %w", err)
10591059
}
10601060
}
10611061
if data == nil {
@@ -1075,7 +1075,7 @@ func hide(target, live, liveLastAppliedAnnotation *unstructured.Unstructured, ke
10751075
data[k] = replacement
10761076
err := unstructured.SetNestedField(obj.Object, data, fields...)
10771077
if err != nil {
1078-
return nil, nil, nil, fmt.Errorf("unstructured.SetNestedField error: %s", err)
1078+
return nil, nil, nil, fmt.Errorf("unstructured.SetNestedField error: %w", err)
10791079
}
10801080
}
10811081
}

pkg/health/health_apiservice.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ func getAPIServiceHealth(obj *unstructured.Unstructured) (*HealthStatus, error)
1818
var apiService apiregistrationv1.APIService
1919
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &apiService)
2020
if err != nil {
21-
return nil, fmt.Errorf("failed to convert unstructured APIService to typed: %v", err)
21+
return nil, fmt.Errorf("failed to convert unstructured APIService to typed: %w", err)
2222
}
2323
return getApiregistrationv1APIServiceHealth(&apiService)
2424
case apiregistrationv1beta1.SchemeGroupVersion.WithKind(kube.APIServiceKind):
2525
var apiService apiregistrationv1beta1.APIService
2626
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &apiService)
2727
if err != nil {
28-
return nil, fmt.Errorf("failed to convert unstructured APIService to typed: %v", err)
28+
return nil, fmt.Errorf("failed to convert unstructured APIService to typed: %w", err)
2929
}
3030
return getApiregistrationv1beta1APIServiceHealth(&apiService)
3131
default:

pkg/health/health_daemonset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func getDaemonSetHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
1717
var daemon appsv1.DaemonSet
1818
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &daemon)
1919
if err != nil {
20-
return nil, fmt.Errorf("failed to convert unstructured DaemonSet to typed: %v", err)
20+
return nil, fmt.Errorf("failed to convert unstructured DaemonSet to typed: %w", err)
2121
}
2222
return getAppsv1DaemonSetHealth(&daemon)
2323
default:

pkg/health/health_deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func getDeploymentHealth(obj *unstructured.Unstructured) (*HealthStatus, error)
1717
var deployment appsv1.Deployment
1818
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &deployment)
1919
if err != nil {
20-
return nil, fmt.Errorf("failed to convert unstructured Deployment to typed: %v", err)
20+
return nil, fmt.Errorf("failed to convert unstructured Deployment to typed: %w", err)
2121
}
2222
return getAppsv1DeploymentHealth(&deployment)
2323
default:

pkg/health/health_job.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func getJobHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
1919
var job batchv1.Job
2020
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &job)
2121
if err != nil {
22-
return nil, fmt.Errorf("failed to convert unstructured Job to typed: %v", err)
22+
return nil, fmt.Errorf("failed to convert unstructured Job to typed: %w", err)
2323
}
2424
return getBatchv1JobHealth(&job)
2525
default:

pkg/health/health_pod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func getPodHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
1919
var pod corev1.Pod
2020
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &pod)
2121
if err != nil {
22-
return nil, fmt.Errorf("failed to convert unstructured Pod to typed: %v", err)
22+
return nil, fmt.Errorf("failed to convert unstructured Pod to typed: %w", err)
2323
}
2424
return getCorev1PodHealth(&pod)
2525
default:

pkg/health/health_pvc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func getPVCHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
1717
var pvc corev1.PersistentVolumeClaim
1818
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &pvc)
1919
if err != nil {
20-
return nil, fmt.Errorf("failed to convert unstructured PersistentVolumeClaim to typed: %v", err)
20+
return nil, fmt.Errorf("failed to convert unstructured PersistentVolumeClaim to typed: %w", err)
2121
}
2222
return getCorev1PVCHealth(&pvc)
2323
default:

0 commit comments

Comments
 (0)