Skip to content

Commit 81bf947

Browse files
Merge pull request #786 from cert-manager/fix_modernize
Fix modernize linter errors
2 parents 9527899 + 7a2fd4b commit 81bf947

File tree

11 files changed

+42
-45
lines changed

11 files changed

+42
-45
lines changed

.golangci.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ linters:
44
exclusions:
55
generated: lax
66
presets: [comments, common-false-positives, legacy, std-error-handling]
7-
rules:
8-
- linters:
9-
- modernize
10-
text: .*
117
paths: [third_party, builtin$, examples$]
128
warn-unused: true
139
settings:

deploy/charts/trust-manager/templates/crd-trust.cert-manager.io_bundles.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ spec:
237237
JKS requests a JKS-formatted binary trust bundle to be written to the target.
238238
The bundle has "changeit" as the default password.
239239
For more information refer to this link https://cert-manager.io/docs/faq/#keystore-passwords
240-
Deprecated: Writing JKS is subject for removal. Please migrate to PKCS12.
240+
Format is deprecated: Writing JKS is subject for removal. Please migrate to PKCS12.
241241
PKCS#12 trust stores created by trust-manager are compatible with Java.
242242
properties:
243243
key:

pkg/apis/trust/v1alpha1/conversion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func TestFuzzyConversion(t *testing.T) {
3737
}))
3838
}
3939

40-
func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
41-
return []interface{}{
40+
func fuzzFuncs(_ runtimeserializer.CodecFactory) []any {
41+
return []any{
4242
spokeBundleSpecFuzzer,
4343
spokeSourceObjectKeySelectorFuzzer,
4444
spokeBundleTargetFuzzer,

pkg/apis/trust/v1alpha1/types_bundle.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ var BundleHashAnnotationKey = "trust.cert-manager.io/hash"
3737
// +genclient:nonNamespaced
3838

3939
type Bundle struct {
40-
metav1.TypeMeta `json:",inline"`
41-
metav1.ObjectMeta `json:"metadata,omitempty"`
40+
metav1.TypeMeta `json:",inline"`
41+
// +optional
42+
metav1.ObjectMeta `json:"metadata"`
4243

4344
// Desired state of the Bundle resource.
4445
Spec BundleSpec `json:"spec"`

pkg/apis/trustmanager/v1alpha2/types_cluster_bundle.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ var BundleHashAnnotationKey = "trust-manager.io/hash"
3737
// +genclient:nonNamespaced
3838

3939
type ClusterBundle struct {
40-
metav1.TypeMeta `json:",inline"`
41-
metav1.ObjectMeta `json:"metadata,omitempty"`
40+
metav1.TypeMeta `json:",inline"`
41+
// +optional
42+
metav1.ObjectMeta `json:"metadata"`
4243

4344
// Desired state of the Bundle resource.
4445
Spec BundleSpec `json:"spec"`

pkg/bundle/bundle_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func Test_Reconcile(t *testing.T) {
295295
disableSecretTargets bool
296296
expResult ctrl.Result
297297
expError bool
298-
expPatches []interface{}
298+
expPatches []any
299299
expBundlePatch *trustapi.BundleStatus
300300
expEvent string
301301
targetNamespaces []string
@@ -405,7 +405,7 @@ func Test_Reconcile(t *testing.T) {
405405
},
406406
existingSecrets: []client.Object{sourceSecret},
407407
expError: false,
408-
expPatches: []interface{}{
408+
expPatches: []any{
409409
configMapPatch(baseBundle.Name, trustNamespace, map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
410410
configMapPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
411411
configMapPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
@@ -458,7 +458,7 @@ func Test_Reconcile(t *testing.T) {
458458
),
459459
},
460460
expError: false,
461-
expPatches: []interface{}{
461+
expPatches: []any{
462462
secretPatch(baseBundle.Name, trustNamespace, map[string]string{targetKey: dummy.DefaultJoinedCerts()}, ptr.To(targetKey), nil),
463463
secretPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, ptr.To(targetKey), nil),
464464
secretPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, ptr.To(targetKey), nil),
@@ -511,7 +511,7 @@ func Test_Reconcile(t *testing.T) {
511511
gen.SetBundleTargetAdditionalFormats(pkcs12DefaultAdditionalFormats),
512512
)},
513513
expError: false,
514-
expPatches: []interface{}{
514+
expPatches: []any{
515515
configMapPatch(baseBundle.Name, "trust-namespace", map[string]string{
516516
targetKey: dummy.DefaultJoinedCerts(),
517517
}, map[string][]byte{
@@ -577,7 +577,7 @@ func Test_Reconcile(t *testing.T) {
577577
),
578578
},
579579
expError: false,
580-
expPatches: []interface{}{
580+
expPatches: []any{
581581
configMapPatch(baseBundle.Name, "trust-namespace", map[string]string{
582582
targetKey: dummy.DefaultJoinedCerts(),
583583
}, map[string][]byte{
@@ -652,7 +652,7 @@ func Test_Reconcile(t *testing.T) {
652652
),
653653
},
654654
expError: false,
655-
expPatches: []interface{}{},
655+
expPatches: []any{},
656656
expBundlePatch: &trustapi.BundleStatus{
657657
Conditions: []metav1.Condition{
658658
{
@@ -711,7 +711,7 @@ func Test_Reconcile(t *testing.T) {
711711
),
712712
},
713713
expError: false,
714-
expPatches: []interface{}{
714+
expPatches: []any{
715715
configMapPatch(baseBundle.Name, "trust-namespace", map[string]string{
716716
targetKey: dummy.DefaultJoinedCerts(),
717717
}, map[string][]byte{
@@ -748,7 +748,7 @@ func Test_Reconcile(t *testing.T) {
748748
},
749749
)},
750750
expError: false,
751-
expPatches: []interface{}{
751+
expPatches: []any{
752752
configMapPatch(baseBundle.Name, trustNamespace, map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
753753
configMapPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
754754
configMapPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
@@ -782,7 +782,7 @@ func Test_Reconcile(t *testing.T) {
782782
existingSecrets: []client.Object{sourceSecret},
783783
existingBundles: []client.Object{gen.BundleFrom(baseBundle)},
784784
expError: false,
785-
expPatches: []interface{}{
785+
expPatches: []any{
786786
configMapPatch(baseBundle.Name, trustNamespace, map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
787787
configMapPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
788788
configMapPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
@@ -821,7 +821,7 @@ func Test_Reconcile(t *testing.T) {
821821
existingBundles: []client.Object{gen.BundleFrom(baseBundle,
822822
gen.SetBundleTargetNamespaceSelectorMatchLabels(map[string]string{"foo": "bar"}))},
823823
expError: false,
824-
expPatches: []interface{}{
824+
expPatches: []any{
825825
configMapPatch(baseBundle.Name, "random-namespace", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
826826
configMapPatch(baseBundle.Name, "another-random-namespace", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
827827
},
@@ -873,7 +873,7 @@ func Test_Reconcile(t *testing.T) {
873873
gen.SetBundleTargetNamespaceSelectorMatchLabels(map[string]string{"foo": "bar"}),
874874
)},
875875
expError: false,
876-
expPatches: []interface{}{
876+
expPatches: []any{
877877
configMapPatch(baseBundle.Name, trustNamespace, map[string]string{}, nil, nil, nil),
878878
configMapPatch(baseBundle.Name, "ns-1", map[string]string{}, nil, nil, nil),
879879
configMapPatch(baseBundle.Name, "ns-2", map[string]string{}, nil, nil, nil),
@@ -938,7 +938,7 @@ func Test_Reconcile(t *testing.T) {
938938
})),
939939
},
940940
expError: false,
941-
expPatches: []interface{}{
941+
expPatches: []any{
942942
configMapPatch(baseBundle.Name, trustNamespace, map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
943943
configMapPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
944944
configMapPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
@@ -1130,7 +1130,7 @@ func Test_Reconcile(t *testing.T) {
11301130
},
11311131
configureDefaultPackage: true,
11321132
expError: false,
1133-
expPatches: []interface{}{
1133+
expPatches: []any{
11341134
configMapPatch(baseBundle.Name, trustNamespace, map[string]string{targetKey: dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate3, dummy.TestCertificate5)}, nil, ptr.To(targetKey), nil),
11351135
configMapPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate3, dummy.TestCertificate5)}, nil, ptr.To(targetKey), nil),
11361136
configMapPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate3, dummy.TestCertificate5)}, nil, ptr.To(targetKey), nil),
@@ -1199,7 +1199,7 @@ func Test_Reconcile(t *testing.T) {
11991199
)},
12001200
configureDefaultPackage: true,
12011201
expError: false,
1202-
expPatches: []interface{}{
1202+
expPatches: []any{
12031203
configMapPatch(baseBundle.Name, trustNamespace, map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
12041204
configMapPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
12051205
configMapPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
@@ -1271,7 +1271,7 @@ func Test_Reconcile(t *testing.T) {
12711271
)},
12721272
configureDefaultPackage: true,
12731273
expError: false,
1274-
expPatches: []interface{}{
1274+
expPatches: []any{
12751275
configMapPatch(baseBundle.Name, trustNamespace, nil, nil, nil, nil),
12761276
configMapPatch(baseBundle.Name, "ns-1", nil, nil, nil, nil),
12771277
configMapPatch(baseBundle.Name, "ns-2", nil, nil, nil, nil),
@@ -1346,7 +1346,7 @@ func Test_Reconcile(t *testing.T) {
13461346
)},
13471347
configureDefaultPackage: true,
13481348
expError: false,
1349-
expPatches: []interface{}{
1349+
expPatches: []any{
13501350
secretPatch(baseBundle.Name, trustNamespace, map[string]string{targetKey: dummy.DefaultJoinedCerts()}, ptr.To(targetKey), nil),
13511351
secretPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, ptr.To(targetKey), nil),
13521352
secretPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, ptr.To(targetKey), nil),
@@ -1394,7 +1394,7 @@ func Test_Reconcile(t *testing.T) {
13941394
)},
13951395
configureDefaultPackage: true,
13961396
expError: false,
1397-
expPatches: []interface{}{},
1397+
expPatches: []any{},
13981398
expBundlePatch: &trustapi.BundleStatus{
13991399
Conditions: []metav1.Condition{
14001400
{
@@ -1457,7 +1457,7 @@ func Test_Reconcile(t *testing.T) {
14571457
}),
14581458
)},
14591459
expError: false,
1460-
expPatches: []interface{}{
1460+
expPatches: []any{
14611461
configMapPatch(baseBundle.Name, trustNamespace, map[string]string{targetKey: dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate3)}, nil, ptr.To(targetKey), nil),
14621462
configMapPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate3)}, nil, ptr.To(targetKey), nil),
14631463
configMapPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.JoinCerts(dummy.TestCertificate2, dummy.TestCertificate1, dummy.TestCertificate3)}, nil, ptr.To(targetKey), nil),
@@ -1488,7 +1488,7 @@ func Test_Reconcile(t *testing.T) {
14881488
},
14891489
targetNamespaces: []string{"ns-1", "ns-2"},
14901490
expError: false,
1491-
expPatches: []interface{}{
1491+
expPatches: []any{
14921492
configMapPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
14931493
configMapPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
14941494
},
@@ -1548,7 +1548,7 @@ func Test_Reconcile(t *testing.T) {
15481548
},
15491549
targetNamespaces: []string{"ns-1", "ns-2"},
15501550
expError: false,
1551-
expPatches: []interface{}{
1551+
expPatches: []any{
15521552
configMapPatch(baseBundle.Name, "ns-1", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
15531553
configMapPatch(baseBundle.Name, "ns-2", map[string]string{targetKey: dummy.DefaultJoinedCerts()}, nil, ptr.To(targetKey), nil),
15541554
},
@@ -1594,7 +1594,7 @@ func Test_Reconcile(t *testing.T) {
15941594

15951595
var (
15961596
logMutex sync.Mutex
1597-
resourcePatches []interface{}
1597+
resourcePatches []any
15981598
)
15991599

16001600
_, ctx := ktesting.NewTestContext(t)
@@ -1615,7 +1615,7 @@ func Test_Reconcile(t *testing.T) {
16151615
targetReconciler: &target.Reconciler{
16161616
Client: fakeClient,
16171617
Cache: fakeClient,
1618-
PatchResourceOverwrite: func(ctx context.Context, obj interface{}) error {
1618+
PatchResourceOverwrite: func(ctx context.Context, obj any) error {
16191619
logMutex.Lock()
16201620
defer logMutex.Unlock()
16211621

pkg/bundle/internal/target/target.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"encoding/hex"
2424
"errors"
2525
"fmt"
26+
"maps"
2627
"strings"
2728

2829
corev1 "k8s.io/api/core/v1"
@@ -55,7 +56,7 @@ type Reconciler struct {
5556

5657
// PatchResourceOverwrite allows use to override the patchResource function
5758
// it is used for testing purposes
58-
PatchResourceOverwrite func(ctx context.Context, obj interface{}) error
59+
PatchResourceOverwrite func(ctx context.Context, obj any) error
5960
}
6061

6162
// CleanupTarget ensures the obsolete bundle target is cleanup up.
@@ -222,9 +223,7 @@ func (r *Reconciler) applySecret(
222223
if err != nil {
223224
return false, err
224225
}
225-
for k, v := range binData {
226-
data[k] = v
227-
}
226+
maps.Copy(data, binData)
228227

229228
patch := prepareTargetPatch(coreapplyconfig.Secret(target.Name, target.Namespace), *bundle).
230229
WithAnnotations(bundleTarget.Secret.GetAnnotations()).

pkg/bundle/internal/target/target_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,13 @@ func Test_ApplyTarget_ConfigMap(t *testing.T) {
452452

453453
var (
454454
logMutex sync.Mutex
455-
resourcePatches []interface{}
455+
resourcePatches []any
456456
)
457457

458458
r := &Reconciler{
459459
Client: fakeClient,
460460
Cache: fakeClient,
461-
PatchResourceOverwrite: func(ctx context.Context, obj interface{}) error {
461+
PatchResourceOverwrite: func(ctx context.Context, obj any) error {
462462
logMutex.Lock()
463463
defer logMutex.Unlock()
464464

@@ -904,13 +904,13 @@ func Test_ApplyTarget_Secret(t *testing.T) {
904904

905905
var (
906906
logMutex sync.Mutex
907-
resourcePatches []interface{}
907+
resourcePatches []any
908908
)
909909

910910
r := &Reconciler{
911911
Client: fakeClient,
912912
Cache: fakeClient,
913-
PatchResourceOverwrite: func(ctx context.Context, obj interface{}) error {
913+
PatchResourceOverwrite: func(ctx context.Context, obj any) error {
914914
logMutex.Lock()
915915
defer logMutex.Unlock()
916916

pkg/util/conversion/conversion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import (
3737
func GetFuzzer(scheme *runtime.Scheme, funcs ...fuzzer.FuzzerFuncs) *randfill.Filler {
3838
funcs = append([]fuzzer.FuzzerFuncs{
3939
metafuzzer.Funcs,
40-
func(_ runtimeserializer.CodecFactory) []interface{} {
41-
return []interface{}{
40+
func(_ runtimeserializer.CodecFactory) []any {
41+
return []any{
4242
// Custom fuzzer for metav1.Time pointers which weren't
4343
// fuzzed and always resulted in `nil` values.
4444
// This implementation is somewhat similar to the one provided

pkg/util/pem_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func TestAddCertsFromPEM(t *testing.T) {
144144
t.Errorf("expected sanitizedBundle not to end with a newline")
145145
}
146146

147-
for _, line := range strings.Split(sanitizedBundle, "\n") {
147+
for line := range strings.SplitSeq(sanitizedBundle, "\n") {
148148
// Check that each "encapsulation boundary" (-----BEGIN/END <x>-----) is on its
149149
// own line. ("Encapsulation boundary" is apparently the name according to rfc7468)
150150
if !strings.HasPrefix(line, "-----") {

0 commit comments

Comments
 (0)