mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-18 16:21:13 +00:00
Add validation for --storage-media-type option.
This commit is contained in:
parent
ced56a6ada
commit
cf836309dc
@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
@ -87,6 +88,12 @@ func NewEtcdOptions(backendConfig *storagebackend.Config) *EtcdOptions {
|
|||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var storageMediaTypes = sets.New(
|
||||||
|
runtime.ContentTypeJSON,
|
||||||
|
runtime.ContentTypeYAML,
|
||||||
|
runtime.ContentTypeProtobuf,
|
||||||
|
)
|
||||||
|
|
||||||
func (s *EtcdOptions) Validate() []error {
|
func (s *EtcdOptions) Validate() []error {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -120,6 +127,10 @@ func (s *EtcdOptions) Validate() []error {
|
|||||||
allErrors = append(allErrors, fmt.Errorf("--encryption-provider-config-automatic-reload must be set with --encryption-provider-config"))
|
allErrors = append(allErrors, fmt.Errorf("--encryption-provider-config-automatic-reload must be set with --encryption-provider-config"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.DefaultStorageMediaType != "" && !storageMediaTypes.Has(s.DefaultStorageMediaType) {
|
||||||
|
allErrors = append(allErrors, fmt.Errorf("--storage-media-type %q invalid, allowed values: %s", s.DefaultStorageMediaType, strings.Join(sets.List(storageMediaTypes), ", ")))
|
||||||
|
}
|
||||||
|
|
||||||
return allErrors
|
return allErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +160,40 @@ func TestEtcdOptionsValidate(t *testing.T) {
|
|||||||
EtcdServersOverrides: []string{"/events#http://127.0.0.1:4002"},
|
EtcdServersOverrides: []string{"/events#http://127.0.0.1:4002"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "empty storage-media-type",
|
||||||
|
testOptions: &EtcdOptions{
|
||||||
|
StorageConfig: storagebackend.Config{
|
||||||
|
Transport: storagebackend.TransportConfig{
|
||||||
|
ServerList: []string{"http://127.0.0.1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DefaultStorageMediaType: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "recognized storage-media-type",
|
||||||
|
testOptions: &EtcdOptions{
|
||||||
|
StorageConfig: storagebackend.Config{
|
||||||
|
Transport: storagebackend.TransportConfig{
|
||||||
|
ServerList: []string{"http://127.0.0.1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DefaultStorageMediaType: "application/json",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unrecognized storage-media-type",
|
||||||
|
testOptions: &EtcdOptions{
|
||||||
|
StorageConfig: storagebackend.Config{
|
||||||
|
Transport: storagebackend.TransportConfig{
|
||||||
|
ServerList: []string{"http://127.0.0.1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DefaultStorageMediaType: "foo/bar",
|
||||||
|
},
|
||||||
|
expectErr: `--storage-media-type "foo/bar" invalid, allowed values: application/json, application/vnd.kubernetes.protobuf, application/yaml`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range testCases {
|
for _, testcase := range testCases {
|
||||||
|
Loading…
Reference in New Issue
Block a user