Merge pull request #52742 from apelisse/validate-resource-even-if-unregistered

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

openapi: Validate unregistered type, if they can be found

**What this PR does / why we need it**:
Types that are not registered/hard-coded in kubectl won't be validated, even if they could because they are defined in openapi. If they are neither registered nor in openapi, then skip validation. 

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes nothing

**Special notes for your reviewer**:

**Release note**:
```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue
2017-10-02 07:14:02 -07:00
committed by GitHub
6 changed files with 2 additions and 149 deletions

View File

@@ -14,7 +14,6 @@ go_library(
"validation.go",
],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/util:go_default_library",
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",

View File

@@ -18,14 +18,12 @@ package validation
import (
"errors"
"fmt"
"strings"
"k8s.io/apimachinery/pkg/runtime/schema"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/kubernetes/pkg/api"
apiutil "k8s.io/kubernetes/pkg/api/util"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
)
@@ -76,15 +74,10 @@ func (v *SchemaValidation) validateList(object interface{}) []error {
}
func (v *SchemaValidation) validateResource(obj interface{}, gvk schema.GroupVersionKind) []error {
if !api.Registry.IsEnabledVersion(gvk.GroupVersion()) {
// if we don't have this in our scheme, just skip
// validation because its an object we don't recognize
return nil
}
resource := v.resources.LookupResource(gvk)
if resource == nil {
return []error{fmt.Errorf("unknown object type %#v", gvk)}
// resource is not present, let's just skip validation.
return nil
}
rootValidation, err := itemFactory(openapi.NewPath(gvk.Kind), obj)