Merge pull request #128062 from aramase/aramase/i/cred_provider_config_typos

credential provider config: detect typos
This commit is contained in:
Kubernetes Prow Robot 2024-10-15 02:04:35 +01:00 committed by GitHub
commit 55b83c92b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 8 deletions

View File

@ -33,7 +33,7 @@ func Test_readCredentialProviderConfigFile(t *testing.T) {
name string name string
configData string configData string
config *kubeletconfig.CredentialProviderConfig config *kubeletconfig.CredentialProviderConfig
expectErr bool expectErr string
}{ }{
{ {
name: "config with 1 plugin and 1 image matcher", name: "config with 1 plugin and 1 image matcher",
@ -293,7 +293,7 @@ providers:
- name: FOO - name: FOO
value: BAR`, value: BAR`,
config: nil, config: nil,
expectErr: true, expectErr: `no kind "WrongKind" is registered for version "kubelet.config.k8s.io/v1alpha1"`,
}, },
{ {
name: "config with wrong apiversion", name: "config with wrong apiversion",
@ -312,7 +312,27 @@ providers:
- name: FOO - name: FOO
value: BAR`, value: BAR`,
config: nil, config: nil,
expectErr: true, expectErr: `no kind "CredentialProviderConfig" is registered for version "foobar/v1alpha1`,
},
{
name: "config with invalid typo",
configData: `---
kind: CredentialProviderConfig
apiVersion: kubelet.config.k8s.io/v1
providers:
- name: test
matchImages:
- "registry.io/foobar"
defaultCacheDuration: 10m
unknownField: should not be here # this field should not be here
apiVersion: credentialprovider.kubelet.k8s.io/v1alpha1
args:
- --v=5
env:
- name: FOO
value: BAR`,
config: nil,
expectErr: `strict decoding error: unknown field "providers[0].unknownField"`,
}, },
} }
@ -330,12 +350,12 @@ providers:
} }
authConfig, err := readCredentialProviderConfigFile(file.Name()) authConfig, err := readCredentialProviderConfigFile(file.Name())
if err != nil && !testcase.expectErr { if err != nil && len(testcase.expectErr) == 0 {
t.Fatal(err) t.Fatal(err)
} }
if err == nil && testcase.expectErr { if err == nil && len(testcase.expectErr) > 0 {
t.Error("expected error but got none") t.Fatalf("expected error %q but got none", testcase.expectErr)
} }
if !reflect.DeepEqual(authConfig, testcase.config) { if !reflect.DeepEqual(authConfig, testcase.config) {
@ -521,7 +541,6 @@ func Test_validateCredentialProviderConfig(t *testing.T) {
t.Errorf("expected error but got none") t.Errorf("expected error but got none")
} else if !testcase.shouldErr && len(errs) > 0 { } else if !testcase.shouldErr && len(errs) > 0 {
t.Errorf("expected no error but received errors: %v", errs.ToAggregate()) t.Errorf("expected no error but received errors: %v", errs.ToAggregate())
} }
}) })
} }

View File

@ -56,7 +56,7 @@ const (
var ( var (
scheme = runtime.NewScheme() scheme = runtime.NewScheme()
codecs = serializer.NewCodecFactory(scheme) codecs = serializer.NewCodecFactory(scheme, serializer.EnableStrict)
apiVersions = map[string]schema.GroupVersion{ apiVersions = map[string]schema.GroupVersion{
credentialproviderv1alpha1.SchemeGroupVersion.String(): credentialproviderv1alpha1.SchemeGroupVersion, credentialproviderv1alpha1.SchemeGroupVersion.String(): credentialproviderv1alpha1.SchemeGroupVersion,