diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index af2a52c4960..f5e17ca1da7 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -4,7 +4,6 @@ cmd/kube-controller-manager/app cmd/kube-proxy/app cmd/linkcheck cmd/preferredimports -hack/make-rules/helpers/go2make/testdata/dir-with-gofiles pkg/client/tests pkg/controller/daemon pkg/controller/deployment @@ -75,8 +74,6 @@ pkg/volume/util/fsquota/common pkg/volume/util/operationexecutor pkg/volume/util/subpath pkg/volume/vsphere_volume -plugin/pkg/admission/imagepolicy -plugin/pkg/admission/podnodeselector test/e2e/apimachinery test/e2e/apps test/e2e/auth diff --git a/hack/make-rules/helpers/go2make/testdata/dir-with-gofiles/bar.go b/hack/make-rules/helpers/go2make/testdata/dir-with-gofiles/bar.go index ce91c95ae93..7e52fa5039d 100644 --- a/hack/make-rules/helpers/go2make/testdata/dir-with-gofiles/bar.go +++ b/hack/make-rules/helpers/go2make/testdata/dir-with-gofiles/bar.go @@ -16,5 +16,5 @@ limitations under the License. package gofiles -func bar() { +func Bar() { } diff --git a/hack/make-rules/helpers/go2make/testdata/dir-with-gofiles/foo.go b/hack/make-rules/helpers/go2make/testdata/dir-with-gofiles/foo.go index 57690637d17..4b6f08251ea 100644 --- a/hack/make-rules/helpers/go2make/testdata/dir-with-gofiles/foo.go +++ b/hack/make-rules/helpers/go2make/testdata/dir-with-gofiles/foo.go @@ -16,5 +16,5 @@ limitations under the License. package gofiles -func foo() { +func Foo() { } diff --git a/pkg/apis/scheduling/v1alpha1/defaults.go b/pkg/apis/scheduling/v1alpha1/defaults.go index 5c04a24c6a9..016407c532d 100644 --- a/pkg/apis/scheduling/v1alpha1/defaults.go +++ b/pkg/apis/scheduling/v1alpha1/defaults.go @@ -19,10 +19,15 @@ package v1alpha1 import ( apiv1 "k8s.io/api/core/v1" "k8s.io/api/scheduling/v1alpha1" + runtime "k8s.io/apimachinery/pkg/runtime" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/kubernetes/pkg/features" ) +func addDefaultingFuncs(scheme *runtime.Scheme) error { + return RegisterDefaults(scheme) +} + // SetDefaults_PriorityClass sets additional defaults compared to its counterpart // in extensions. func SetDefaults_PriorityClass(obj *v1alpha1.PriorityClass) { diff --git a/pkg/apis/scheduling/v1alpha1/register.go b/pkg/apis/scheduling/v1alpha1/register.go index 1cd870af176..ed40537986d 100644 --- a/pkg/apis/scheduling/v1alpha1/register.go +++ b/pkg/apis/scheduling/v1alpha1/register.go @@ -42,5 +42,5 @@ func init() { // We only register manually written functions here. The registration of the // generated functions takes place in the generated files. The separation // makes the code compile even when the generated files are missing. - localSchemeBuilder.Register(RegisterDefaults) + localSchemeBuilder.Register(addDefaultingFuncs) } diff --git a/pkg/apis/scheduling/v1beta1/defaults.go b/pkg/apis/scheduling/v1beta1/defaults.go index bbf217261fc..6ffb8a669ec 100644 --- a/pkg/apis/scheduling/v1beta1/defaults.go +++ b/pkg/apis/scheduling/v1beta1/defaults.go @@ -19,10 +19,15 @@ package v1beta1 import ( apiv1 "k8s.io/api/core/v1" "k8s.io/api/scheduling/v1beta1" + runtime "k8s.io/apimachinery/pkg/runtime" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/kubernetes/pkg/features" ) +func addDefaultingFuncs(scheme *runtime.Scheme) error { + return RegisterDefaults(scheme) +} + // SetDefaults_PriorityClass sets additional defaults compared to its counterpart // in extensions. func SetDefaults_PriorityClass(obj *v1beta1.PriorityClass) { diff --git a/pkg/apis/scheduling/v1beta1/register.go b/pkg/apis/scheduling/v1beta1/register.go index 114e084cbe6..a786bd47452 100644 --- a/pkg/apis/scheduling/v1beta1/register.go +++ b/pkg/apis/scheduling/v1beta1/register.go @@ -42,5 +42,5 @@ func init() { // We only register manually written functions here. The registration of the // generated functions takes place in the generated files. The separation // makes the code compile even when the generated files are missing. - localSchemeBuilder.Register(RegisterDefaults) + localSchemeBuilder.Register(addDefaultingFuncs) } diff --git a/plugin/pkg/admission/imagepolicy/admission.go b/plugin/pkg/admission/imagepolicy/admission.go index 6271043b6be..2dc84a46499 100644 --- a/plugin/pkg/admission/imagepolicy/admission.go +++ b/plugin/pkg/admission/imagepolicy/admission.go @@ -84,7 +84,6 @@ type Plugin struct { responseCache *cache.LRUExpireCache allowTTL time.Duration denyTTL time.Duration - retryBackoff time.Duration defaultAllow bool } diff --git a/plugin/pkg/admission/imagepolicy/admission_test.go b/plugin/pkg/admission/imagepolicy/admission_test.go index 4d9f5ad870b..d1f81d51950 100644 --- a/plugin/pkg/admission/imagepolicy/admission_test.go +++ b/plugin/pkg/admission/imagepolicy/admission_test.go @@ -984,6 +984,7 @@ func TestReturnedAnnotationAdd(t *testing.T) { pod *api.Pod verifierAnnotations map[string]string expectedAnnotations map[string]string + wantErr bool }{ { test: "Add valid response annotations", @@ -1029,6 +1030,7 @@ func TestReturnedAnnotationAdd(t *testing.T) { expectedAnnotations: map[string]string{ "imagepolicywebhook.image-policy.k8s.io/foo-test": "false", }, + wantErr: true, }, } for _, tt := range tests { @@ -1058,6 +1060,14 @@ func TestReturnedAnnotationAdd(t *testing.T) { attr = &fakeAttributes{attr, annotations} err = wh.Validate(context.TODO(), attr, nil) + if tt.wantErr { + if err == nil { + t.Errorf("%s: expected error making admission request: %v", tt.test, err) + } + } else if err != nil { + t.Errorf("%s: failed to admit: %v", tt.test, err) + } + if !reflect.DeepEqual(annotations, tt.expectedAnnotations) { t.Errorf("got audit annotations: %v; want: %v", annotations, tt.expectedAnnotations) } diff --git a/plugin/pkg/admission/imagepolicy/certs_test.go b/plugin/pkg/admission/imagepolicy/certs_test.go index 2a9177ee32f..62087c3e7ea 100644 --- a/plugin/pkg/admission/imagepolicy/certs_test.go +++ b/plugin/pkg/admission/imagepolicy/certs_test.go @@ -17,6 +17,8 @@ limitations under the License. // This file was generated using openssl by the gencerts.sh script // and holds raw certificates for the imagepolicy webhook tests. +//lint:file-ignore U1000 Ignore all unused code, it's generated + package imagepolicy var caKey = []byte(`-----BEGIN RSA PRIVATE KEY----- diff --git a/plugin/pkg/admission/imagepolicy/gencerts.sh b/plugin/pkg/admission/imagepolicy/gencerts.sh index 46e0ea858a9..ac8758c0c87 100755 --- a/plugin/pkg/admission/imagepolicy/gencerts.sh +++ b/plugin/pkg/admission/imagepolicy/gencerts.sh @@ -86,6 +86,8 @@ limitations under the License. // This file was generated using openssl by the gencerts.sh script // and holds raw certificates for the imagepolicy webhook tests. +//lint:file-ignore U1000 Ignore all unused code, it's generated + package imagepolicy EOF diff --git a/plugin/pkg/admission/podnodeselector/admission.go b/plugin/pkg/admission/podnodeselector/admission.go index 2c5c4aa96f8..65e3cf75ba8 100644 --- a/plugin/pkg/admission/podnodeselector/admission.go +++ b/plugin/pkg/admission/podnodeselector/admission.go @@ -232,13 +232,12 @@ func (p *Plugin) defaultGetNamespace(name string) (*corev1.Namespace, error) { func (p *Plugin) getNodeSelectorMap(namespace *corev1.Namespace) (labels.Set, error) { selector := labels.Set{} - labelsMap := labels.Set{} var err error found := false if len(namespace.ObjectMeta.Annotations) > 0 { for _, annotation := range NamespaceNodeSelectors { if ns, ok := namespace.ObjectMeta.Annotations[annotation]; ok { - labelsMap, err = labels.ConvertSelectorToLabelsMap(ns) + labelsMap, err := labels.ConvertSelectorToLabelsMap(ns) if err != nil { return labels.Set{}, err }