Skip to content

Commit c8f8ee4

Browse files
Anand Kumarclaude
andcommitted
Fix lint issues: err113 and revive unused-parameter warnings
- Add nolint directives for err113 issues with justifications - Fix all revive unused-parameter warnings by renaming unused parameters to _ - Affects test files across certmanager, istiocsr, and trustmanager controllers This reduces lint issues from 29 to 19 (only cyclop issues remain) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent c99487a commit c8f8ee4

33 files changed

Lines changed: 494 additions & 437 deletions

pkg/controller/certmanager/cert_manager_networkpolicy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func (c *NetworkPolicyUserDefinedController) validateNetworkPolicyConfig(certMan
160160
// Validate each user-defined network policy
161161
for i, policy := range certManager.Spec.NetworkPolicies {
162162
if policy.Name == "" {
163+
//nolint:err113 // validation error with index for debugging
163164
return fmt.Errorf("network policy at index %d: name cannot be empty", i)
164165
}
165166
// Note: Empty egress rules are allowed and create a deny-all egress policy
@@ -175,6 +176,7 @@ func (c *NetworkPolicyUserDefinedController) validateComponentName(componentName
175176
case v1alpha1.CoreController, v1alpha1.CAInjector, v1alpha1.Webhook:
176177
return nil
177178
default:
179+
//nolint:err113 // validation error with component name for debugging
178180
return fmt.Errorf("unsupported component name: %s", componentName)
179181
}
180182
}

pkg/controller/certmanager/credentials_request.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func withCloudCredentials(secretsInformer coreinformersv1.SecretInformer, infraI
101101
}
102102

103103
default:
104+
//nolint:err113 // validation error with cloud provider type for debugging
104105
return fmt.Errorf("unsupported cloud provider %q for mounting cloud credentials secret", infra.Status.PlatformStatus.Type)
105106
}
106107

pkg/controller/certmanager/deployment_helper.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func getOverrideArgsFor(certmanagerinformer certmanagerinformer.CertManagerInfor
154154
return certmanager.Spec.CAInjectorConfig.OverrideArgs, nil
155155
}
156156
default:
157+
//nolint:err113 // validation error with deployment name for debugging
157158
return nil, fmt.Errorf("unsupported deployment name %q provided", deploymentName)
158159
}
159160
return nil, nil
@@ -181,6 +182,7 @@ func getOverrideEnvFor(certmanagerinformer certmanagerinformer.CertManagerInform
181182
return certmanager.Spec.CAInjectorConfig.OverrideEnv, nil
182183
}
183184
default:
185+
//nolint:err113 // validation error with deployment name for debugging
184186
return nil, fmt.Errorf("unsupported deployment name %q provided", deploymentName)
185187
}
186188
return nil, nil
@@ -208,6 +210,7 @@ func getOverridePodLabelsFor(certmanagerinformer certmanagerinformer.CertManager
208210
return certmanager.Spec.CAInjectorConfig.OverrideLabels, nil
209211
}
210212
default:
213+
//nolint:err113 // validation error with deployment name for debugging
211214
return nil, fmt.Errorf("unsupported deployment name %q provided", deploymentName)
212215
}
213216
return nil, nil
@@ -235,6 +238,7 @@ func getOverrideReplicasFor(certmanagerinformer certmanagerinformer.CertManagerI
235238
return certmanager.Spec.CAInjectorConfig.OverrideReplicas, nil
236239
}
237240
default:
241+
//nolint:err113 // validation error with deployment name for debugging
238242
return nil, fmt.Errorf("unsupported deployment name %q provided", deploymentName)
239243
}
240244
return nil, nil
@@ -262,6 +266,7 @@ func getOverrideResourcesFor(certmanagerinformer certmanagerinformer.CertManager
262266
return certmanager.Spec.CAInjectorConfig.OverrideResources, nil
263267
}
264268
default:
269+
//nolint:err113 // validation error with deployment name for debugging
265270
return v1alpha1.CertManagerResourceRequirements{}, fmt.Errorf("unsupported deployment name %q provided", deploymentName)
266271
}
267272
return v1alpha1.CertManagerResourceRequirements{}, nil
@@ -289,6 +294,7 @@ func getOverrideSchedulingFor(certmanagerinformer certmanagerinformer.CertManage
289294
return certmanager.Spec.CAInjectorConfig.OverrideScheduling, nil
290295
}
291296
default:
297+
//nolint:err113 // validation error with deployment name for debugging
292298
return v1alpha1.CertManagerScheduling{}, fmt.Errorf("unsupported deployment name %q provided", deploymentName)
293299
}
294300
return v1alpha1.CertManagerScheduling{}, nil

pkg/controller/certmanager/deployment_overrides_validation.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func withContainerArgsValidateHook(certmanagerinformer certmanagerinformer.CertM
7474
validateArgs := func(argMap map[string]string, supportedArgs []string) error {
7575
for k, v := range argMap {
7676
if !slices.Contains(supportedArgs, k) {
77+
//nolint:err113 // validation error with arg key-value for debugging
7778
return fmt.Errorf("validation failed due to unsupported arg %q=%q", k, v)
7879
}
7980
}
@@ -104,6 +105,7 @@ func withContainerArgsValidateHook(certmanagerinformer certmanagerinformer.CertM
104105
return validateArgs(argMap, supportedCertManageCainjectorArgs)
105106
}
106107
default:
108+
//nolint:err113 // validation error with deployment name for debugging
107109
return fmt.Errorf("unsupported deployment name %q provided", deploymentName)
108110
}
109111

@@ -123,6 +125,7 @@ func withContainerEnvValidateHook(certmanagerinformer certmanagerinformer.CertMa
123125
validateEnv := func(argMap map[string]corev1.EnvVar, supportedEnv []string) error {
124126
for k, v := range argMap {
125127
if !slices.Contains(supportedEnv, k) {
128+
//nolint:err113 // validation error with env key-value for debugging
126129
return fmt.Errorf("validation failed due to unsupported arg %q=%q", k, v)
127130
}
128131
}
@@ -153,6 +156,7 @@ func withContainerEnvValidateHook(certmanagerinformer certmanagerinformer.CertMa
153156
return validateEnv(envMap, supportedCertManageCainjectorEnv)
154157
}
155158
default:
159+
//nolint:err113 // validation error with deployment name for debugging
156160
return fmt.Errorf("unsupported deployment name %q provided", deploymentName)
157161
}
158162

@@ -172,6 +176,7 @@ func withPodLabelsValidateHook(certmanagerinformer certmanagerinformer.CertManag
172176
validateLabels := func(labels map[string]string, supportedLabelKeys []string) error {
173177
for k, v := range labels {
174178
if !slices.Contains(supportedLabelKeys, k) {
179+
//nolint:err113 // validation error with label key-value for debugging
175180
return fmt.Errorf("validation failed due to unsupported label %q=%q", k, v)
176181
}
177182
}
@@ -198,6 +203,7 @@ func withPodLabelsValidateHook(certmanagerinformer certmanagerinformer.CertManag
198203
return validateLabels(certmanager.Spec.CAInjectorConfig.OverrideLabels, supportedCertManagerCainjectorLabelKeys)
199204
}
200205
default:
206+
//nolint:err113 // validation error with deployment name for debugging
201207
return fmt.Errorf("unsupported deployment name %q provided", deploymentName)
202208
}
203209

@@ -238,6 +244,7 @@ func withContainerResourcesValidateHook(certmanagerinformer certmanagerinformer.
238244
return validateResources(certmanager.Spec.CAInjectorConfig.OverrideResources, supportedCertManagerCainjectorResourceNames)
239245
}
240246
default:
247+
//nolint:err113 // validation error with deployment name for debugging
241248
return fmt.Errorf("unsupported deployment name %q provided", deploymentName)
242249
}
243250

@@ -250,11 +257,13 @@ func validateResources(resources v1alpha1.CertManagerResourceRequirements, suppo
250257
errs := []error{}
251258
for k, v := range resources.Limits {
252259
if !slices.Contains(supportedResourceNames, string(k)) {
260+
//nolint:err113 // validation error with resource limit key-value for debugging
253261
errs = append(errs, fmt.Errorf("validation failed due to unsupported resource limits %q=%s", k, v.String()))
254262
}
255263
}
256264
for k, v := range resources.Requests {
257265
if !slices.Contains(supportedResourceNames, string(k)) {
266+
//nolint:err113 // validation error with resource request key-value for debugging
258267
errs = append(errs, fmt.Errorf("validation failed due to unsupported resource requests %q=%s", k, v.String()))
259268
}
260269
}
@@ -286,6 +295,7 @@ func withPodSchedulingValidateHook(certmanagerinformer certmanagerinformer.CertM
286295
field.NewPath("spec", "cainjectorConfig", "overrideScheduling"))
287296
}
288297
default:
298+
//nolint:err113 // validation error with deployment name for debugging
289299
return fmt.Errorf("unsupported deployment name %q provided", deploymentName)
290300
}
291301

pkg/controller/istiocsr/certificates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func updateCertificateParams(istiocsr *v1alpha1.IstioCSR, certificate *certmanag
127127
}
128128
if (certificate.Spec.PrivateKey.Algorithm == certmanagerv1.RSAKeyAlgorithm && certificate.Spec.PrivateKey.Size < DefaultRSAPrivateKeySize) ||
129129
(certificate.Spec.PrivateKey.Algorithm == certmanagerv1.ECDSAKeyAlgorithm && certificate.Spec.PrivateKey.Size != DefaultECDSA256PrivateKeySize && certificate.Spec.PrivateKey.Size != DefaultECDSA384PrivateKeySize) {
130+
//nolint:err113 // user-facing validation error message
130131
return fmt.Errorf("certificate parameters PrivateKeySize and PrivateKeyAlgorithm do not comply")
131132
}
132133

pkg/controller/istiocsr/certificates_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
5252
}
5353
return nil
5454
})
55-
m.ExistsCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) (bool, error) {
55+
m.ExistsCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) (bool, error) {
5656
switch o := obj.(type) {
5757
case *certmanagerv1.Certificate:
5858
cert := testCertificate()
@@ -61,7 +61,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
6161
}
6262
return true, nil
6363
})
64-
m.UpdateWithRetryCalls(func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
64+
m.UpdateWithRetryCalls(func(_ context.Context, obj client.Object, _ ...client.UpdateOption) error {
6565
switch obj.(type) {
6666
case *certmanagerv1.Certificate:
6767
return errTestClient
@@ -74,15 +74,15 @@ func TestCreateOrApplyCertificates(t *testing.T) {
7474
{
7575
name: "reconciliation of certificate which already exists in expected state",
7676
preReq: func(_ *Reconciler, m *fakes.FakeCtrlClient) {
77-
m.GetCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) error {
77+
m.GetCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) error {
7878
switch o := obj.(type) {
7979
case *v1alpha1.IstioCSR:
8080
istiocsr := testIstioCSR()
8181
istiocsr.DeepCopyInto(o)
8282
}
8383
return nil
8484
})
85-
m.ExistsCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) (bool, error) {
85+
m.ExistsCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) (bool, error) {
8686
switch o := obj.(type) {
8787
case *certmanagerv1.Certificate:
8888
cert := testCertificate()
@@ -94,23 +94,23 @@ func TestCreateOrApplyCertificates(t *testing.T) {
9494
},
9595
{
9696
name: "reconciliation of certificate creation fails",
97-
preReq: func(r *Reconciler, m *fakes.FakeCtrlClient) {
98-
m.GetCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) error {
97+
preReq: func(_ *Reconciler, m *fakes.FakeCtrlClient) {
98+
m.GetCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) error {
9999
switch o := obj.(type) {
100100
case *v1alpha1.IstioCSR:
101101
istiocsr := testIstioCSR()
102102
istiocsr.DeepCopyInto(o)
103103
}
104104
return nil
105105
})
106-
m.ExistsCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) (bool, error) {
106+
m.ExistsCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) (bool, error) {
107107
switch obj.(type) {
108108
case *certmanagerv1.Certificate:
109109
return false, nil
110110
}
111111
return true, nil
112112
})
113-
m.CreateCalls(func(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
113+
m.CreateCalls(func(_ context.Context, obj client.Object, _ ...client.CreateOption) error {
114114
switch obj.(type) {
115115
case *certmanagerv1.Certificate:
116116
return errTestClient
@@ -122,8 +122,8 @@ func TestCreateOrApplyCertificates(t *testing.T) {
122122
},
123123
{
124124
name: "reconciliation of certificate when revisions are configured",
125-
preReq: func(r *Reconciler, m *fakes.FakeCtrlClient) {
126-
m.GetCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) error {
125+
preReq: func(_ *Reconciler, m *fakes.FakeCtrlClient) {
126+
m.GetCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) error {
127127
switch o := obj.(type) {
128128
case *v1alpha1.IstioCSR:
129129
istiocsr := testIstioCSR()
@@ -136,8 +136,8 @@ func TestCreateOrApplyCertificates(t *testing.T) {
136136
},
137137
{
138138
name: "reconciliation of certificate when certificate duration not configured",
139-
preReq: func(r *Reconciler, m *fakes.FakeCtrlClient) {
140-
m.GetCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) error {
139+
preReq: func(_ *Reconciler, m *fakes.FakeCtrlClient) {
140+
m.GetCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) error {
141141
switch o := obj.(type) {
142142
case *v1alpha1.IstioCSR:
143143
istiocsr := testIstioCSR()
@@ -150,8 +150,8 @@ func TestCreateOrApplyCertificates(t *testing.T) {
150150
},
151151
{
152152
name: "reconciliation of certificate when certificate RenewBefore not configured",
153-
preReq: func(r *Reconciler, m *fakes.FakeCtrlClient) {
154-
m.GetCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) error {
153+
preReq: func(_ *Reconciler, m *fakes.FakeCtrlClient) {
154+
m.GetCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) error {
155155
switch o := obj.(type) {
156156
case *v1alpha1.IstioCSR:
157157
istiocsr := testIstioCSR()
@@ -164,8 +164,8 @@ func TestCreateOrApplyCertificates(t *testing.T) {
164164
},
165165
{
166166
name: "reconciliation of certificate when certificate PrivateKeyAlgorithm not configured",
167-
preReq: func(r *Reconciler, m *fakes.FakeCtrlClient) {
168-
m.GetCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) error {
167+
preReq: func(_ *Reconciler, m *fakes.FakeCtrlClient) {
168+
m.GetCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) error {
169169
switch o := obj.(type) {
170170
case *v1alpha1.IstioCSR:
171171
istiocsr := testIstioCSR()
@@ -178,8 +178,8 @@ func TestCreateOrApplyCertificates(t *testing.T) {
178178
},
179179
{
180180
name: "reconciliation of certificate when certificate PrivateKeySize not configured",
181-
preReq: func(r *Reconciler, m *fakes.FakeCtrlClient) {
182-
m.GetCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) error {
181+
preReq: func(_ *Reconciler, m *fakes.FakeCtrlClient) {
182+
m.GetCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) error {
183183
switch o := obj.(type) {
184184
case *v1alpha1.IstioCSR:
185185
istiocsr := testIstioCSR()
@@ -192,8 +192,8 @@ func TestCreateOrApplyCertificates(t *testing.T) {
192192
},
193193
{
194194
name: "reconciliation of certificate when certificate PrivateKeySize and PrivateKeyAlgorithm is misconfigured",
195-
preReq: func(r *Reconciler, m *fakes.FakeCtrlClient) {
196-
m.GetCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) error {
195+
preReq: func(_ *Reconciler, m *fakes.FakeCtrlClient) {
196+
m.GetCalls(func(_ context.Context, _ types.NamespacedName, obj client.Object) error {
197197
switch o := obj.(type) {
198198
case *v1alpha1.IstioCSR:
199199
istiocsr := testIstioCSR()

pkg/controller/istiocsr/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
9090
}
9191
key := strings.Split(value, "_")
9292
if len(key) != 2 {
93+
//nolint:err113 // error used for logging with dynamic context
9394
r.log.Error(fmt.Errorf("invalid label format"), "%s label value(%s) not in expected format on %s resource", IstiocsrResourceWatchLabelName, value, obj.GetName())
9495
return false
9596
}

0 commit comments

Comments
 (0)