mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Merge pull request #38304 from deads2k/cli-13-fix-validate
Automatic merge from submit-queue (batch tested with PRs 36140, 38304) remove validation dependency on version negotiation Things that just need a REST client or a bit of discovery information should not attempt to perform negotiation. Doing so just limits the genericness of the client. @kubernetes/sig-cli @fabianofranz this blocks the kubernetes-discovery work.
This commit is contained in:
commit
7d8d4eb057
@ -719,34 +719,21 @@ func (f *factory) StatusViewer(mapping *meta.RESTMapping) (kubectl.StatusViewer,
|
|||||||
|
|
||||||
func (f *factory) Validator(validate bool, cacheDir string) (validation.Schema, error) {
|
func (f *factory) Validator(validate bool, cacheDir string) (validation.Schema, error) {
|
||||||
if validate {
|
if validate {
|
||||||
clientConfig, err := f.clients.ClientConfigForVersion(nil)
|
discovery, err := f.DiscoveryClient()
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
restclient, err := restclient.RESTClientFor(clientConfig)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
clientset, err := f.clients.ClientSetForVersion(nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dir := cacheDir
|
dir := cacheDir
|
||||||
if len(dir) > 0 {
|
if len(dir) > 0 {
|
||||||
version, err := clientset.Discovery().ServerVersion()
|
version, err := discovery.ServerVersion()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dir = path.Join(cacheDir, version.String())
|
dir = path.Join(cacheDir, version.String())
|
||||||
} else {
|
} else {
|
||||||
dir = "" // disable caching as a fallback
|
dir = "" // disable caching as a fallback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fedClient, err := f.clients.FederationClientForVersion(nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
swaggerSchema := &clientSwaggerSchema{
|
swaggerSchema := &clientSwaggerSchema{
|
||||||
c: restclient,
|
c: discovery.RESTClient(),
|
||||||
fedc: fedClient,
|
|
||||||
cacheDir: dir,
|
cacheDir: dir,
|
||||||
}
|
}
|
||||||
return validation.ConjunctiveSchema{
|
return validation.ConjunctiveSchema{
|
||||||
@ -759,11 +746,11 @@ func (f *factory) Validator(validate bool, cacheDir string) (validation.Schema,
|
|||||||
|
|
||||||
func (f *factory) SwaggerSchema(gvk schema.GroupVersionKind) (*swagger.ApiDeclaration, error) {
|
func (f *factory) SwaggerSchema(gvk schema.GroupVersionKind) (*swagger.ApiDeclaration, error) {
|
||||||
version := gvk.GroupVersion()
|
version := gvk.GroupVersion()
|
||||||
clientset, err := f.clients.ClientSetForVersion(&version)
|
discovery, err := f.DiscoveryClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return clientset.Discovery().SwaggerSchema(version)
|
return discovery.SwaggerSchema(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *factory) DefaultNamespace() (string, bool, error) {
|
func (f *factory) DefaultNamespace() (string, bool, error) {
|
||||||
@ -1017,8 +1004,7 @@ func getServiceProtocols(spec api.ServiceSpec) map[string]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type clientSwaggerSchema struct {
|
type clientSwaggerSchema struct {
|
||||||
c *restclient.RESTClient
|
c restclient.Interface
|
||||||
fedc *restclient.RESTClient
|
|
||||||
cacheDir string
|
cacheDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1150,12 +1136,6 @@ func (c *clientSwaggerSchema) ValidateBytes(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch gvk.Group {
|
switch gvk.Group {
|
||||||
case federation.GroupName:
|
|
||||||
if c.fedc == nil {
|
|
||||||
return errors.New("unable to validate: no federation client")
|
|
||||||
}
|
|
||||||
return getSchemaAndValidate(c.fedc, data, "apis/", gvk.GroupVersion().String(), c.cacheDir, c)
|
|
||||||
|
|
||||||
case api.GroupName:
|
case api.GroupName:
|
||||||
return getSchemaAndValidate(c.c, data, "api", gvk.GroupVersion().String(), c.cacheDir, c)
|
return getSchemaAndValidate(c.c, data, "api", gvk.GroupVersion().String(), c.cacheDir, c)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user