Skip to content

Commit 7db4ef2

Browse files
committed
fix modernize linter errors
Signed-off-by: Tim Ramlot <[email protected]>
1 parent 56c98ea commit 7db4ef2

File tree

8 files changed

+23
-25
lines changed

8 files changed

+23
-25
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/approver-policy/templates/crd-policy.cert-manager.io_certificaterequestpolicies.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,9 @@ spec:
11401140
- type
11411141
x-kubernetes-list-type: map
11421142
type: object
1143+
required:
1144+
- spec
1145+
- status
11431146
type: object
11441147
served: true
11451148
storage: true

deploy/crds/policy.cert-manager.io_certificaterequestpolicies.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,9 @@ spec:
11571157
- type
11581158
x-kubernetes-list-type: map
11591159
type: object
1160+
required:
1161+
- spec
1162+
- status
11601163
type: object
11611164
served: true
11621165
storage: true

pkg/apis/policy/v1alpha1/types_certificaterequestpolicy.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,22 @@ var CertificateRequestPolicyKind = "CertificateRequestPolicy"
3737
// makes decisions on whether applicable CertificateRequests should be approved
3838
// or denied.
3939
type CertificateRequestPolicy 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

43-
Spec CertificateRequestPolicySpec `json:"spec,omitempty"`
44-
Status CertificateRequestPolicyStatus `json:"status,omitempty"`
44+
Spec CertificateRequestPolicySpec `json:"spec"`
45+
Status CertificateRequestPolicyStatus `json:"status,omitzero"`
4546
}
4647

4748
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
4849
// CertificateRequestPolicyList is a list of CertificateRequestPolicies.
4950
type CertificateRequestPolicyList struct {
5051
metav1.TypeMeta `json:",inline"`
51-
metav1.ListMeta `json:"metadata,omitempty"`
52-
Items []CertificateRequestPolicy `json:"items"`
52+
// +optional
53+
metav1.ListMeta `json:"metadata"`
54+
55+
Items []CertificateRequestPolicy `json:"items"`
5356
}
5457

5558
// CertificateRequestPolicySpec defines the desired state of

pkg/internal/approver/constraints/evaluator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (c constraints) Evaluate(_ context.Context, policy *policyapi.CertificateRe
108108

109109
// decodePublicKey will return the algorithm and size of the given public key.
110110
// If the public key cannot be decoded, an error is returned.
111-
func decodePublicKey(pub interface{}) (cmapi.PrivateKeyAlgorithm, int, error) {
111+
func decodePublicKey(pub any) (cmapi.PrivateKeyAlgorithm, int, error) {
112112
switch pubKey := pub.(type) {
113113
case *rsa.PublicKey:
114114
return cmapi.RSAKeyAlgorithm, pubKey.N.BitLen(), nil

pkg/internal/approver/validation/serviceaccount.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ func ServiceAccountLib() cel.EnvOption {
4141
}
4242

4343
// ConvertToNative implements ref.Val.ConvertToNative.
44-
func (sa ServiceAccount) ConvertToNative(typeDesc reflect.Type) (interface{}, error) {
45-
if reflect.TypeOf(sa).AssignableTo(typeDesc) {
44+
func (sa ServiceAccount) ConvertToNative(typeDesc reflect.Type) (any, error) {
45+
if reflect.TypeFor[ServiceAccount]().AssignableTo(typeDesc) {
4646
return sa, nil
4747
}
48-
if reflect.TypeOf("").AssignableTo(typeDesc) {
48+
if reflect.TypeFor[string]().AssignableTo(typeDesc) {
4949
return serviceaccount.MakeUsername(sa.Namespace, sa.Name), nil
5050
}
5151
return nil, fmt.Errorf("type conversion error from 'serviceaccount' to '%v'", typeDesc)
@@ -77,7 +77,7 @@ func (sa ServiceAccount) Type() ref.Type {
7777
}
7878

7979
// Value implements ref.Val.Value.
80-
func (sa ServiceAccount) Value() interface{} {
80+
func (sa ServiceAccount) Value() any {
8181
return sa
8282
}
8383

pkg/internal/approver/validation/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (v *validator) Validate(value string, request cmapi.CertificateRequest) (bo
8686
return false, errors.New("must compile first")
8787
}
8888

89-
vars := map[string]interface{}{
89+
vars := map[string]any{
9090
varSelf: value,
9191
varRequest: &CertificateRequest{
9292
Name: request.GetName(),

pkg/internal/webhook/validator.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"slices"
2324
"sort"
2425

2526
"github.com/go-logr/logr"
@@ -75,15 +76,7 @@ func (v *validator) validate(ctx context.Context, obj runtime.Object) (admission
7576
// Ensure no plugin has been defined which is not registered.
7677
var unrecognisedNames []string
7778
for name := range policy.Spec.Plugins {
78-
var found bool
79-
for _, known := range v.registeredPlugins {
80-
if name == known {
81-
found = true
82-
break
83-
}
84-
}
85-
86-
if !found {
79+
if !slices.Contains(v.registeredPlugins, name) {
8780
unrecognisedNames = append(unrecognisedNames, name)
8881
}
8982
}

0 commit comments

Comments
 (0)