mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
openapi: Use "group" to look for resources
This commit is contained in:
parent
b7b5457050
commit
aa1c79f32b
@ -51,7 +51,7 @@ func (v *SchemaValidation) ValidateBytes(data []byte) error {
|
|||||||
|
|
||||||
resource := v.resources.LookupResource(gvk)
|
resource := v.resources.LookupResource(gvk)
|
||||||
if resource == nil {
|
if resource == nil {
|
||||||
return fmt.Errorf("unknown object type %q", gvk)
|
return fmt.Errorf("unknown object type %#v", gvk)
|
||||||
}
|
}
|
||||||
|
|
||||||
rootValidation, err := itemFactory(openapi.NewPath(gvk.Kind), obj)
|
rootValidation, err := itemFactory(openapi.NewPath(gvk.Kind), obj)
|
||||||
@ -91,6 +91,7 @@ func getObjectKind(object interface{}) (schema.GroupVersionKind, error) {
|
|||||||
return schema.GroupVersionKind{}, errors.New("apiVersion isn't string type")
|
return schema.GroupVersionKind{}, errors.New("apiVersion isn't string type")
|
||||||
}
|
}
|
||||||
version := apiutil.GetVersion(apiVersion.(string))
|
version := apiutil.GetVersion(apiVersion.(string))
|
||||||
|
group := apiutil.GetGroup(apiVersion.(string))
|
||||||
kind := fields["kind"]
|
kind := fields["kind"]
|
||||||
if kind == nil {
|
if kind == nil {
|
||||||
return schema.GroupVersionKind{}, errors.New("kind not set")
|
return schema.GroupVersionKind{}, errors.New("kind not set")
|
||||||
@ -99,5 +100,5 @@ func getObjectKind(object interface{}) (schema.GroupVersionKind, error) {
|
|||||||
return schema.GroupVersionKind{}, errors.New("kind isn't string type")
|
return schema.GroupVersionKind{}, errors.New("kind isn't string type")
|
||||||
}
|
}
|
||||||
|
|
||||||
return schema.GroupVersionKind{Kind: kind.(string), Version: version}, nil
|
return schema.GroupVersionKind{Group: group, Version: version, Kind: kind.(string)}, nil
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,28 @@ var _ = Describe("resource validation using OpenAPI Schema", func() {
|
|||||||
Expect(validator).ToNot(BeNil())
|
Expect(validator).ToNot(BeNil())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("finds Deployment in Schema and validates it", func() {
|
||||||
|
err := validator.ValidateBytes([]byte(`
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
name: redis-master
|
||||||
|
name: name
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: redis
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: redis
|
||||||
|
name: redis
|
||||||
|
`))
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
})
|
||||||
|
|
||||||
It("validates a valid pod", func() {
|
It("validates a valid pod", func() {
|
||||||
err := validator.ValidateBytes([]byte(`
|
err := validator.ValidateBytes([]byte(`
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
Loading…
Reference in New Issue
Block a user