Skip to content

Commit 55e216f

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#54957 from apelisse/update-kube-openapi
Automatic merge from submit-queue (batch tested with PRs 55004, 54957). 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>. Update kube-openapi to use validation **What this PR does / why we need it**: Moves openapi validation code to kube-openapi, so that we can move the rest of the code to apimachinery repository, so that later we can use it from both the client and the server. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #Nothing **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
2 parents 6232f36 + 8f7262e commit 55e216f

File tree

25 files changed

+354
-101
lines changed

25 files changed

+354
-101
lines changed

Godeps/Godeps.json

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/LICENSES

Lines changed: 210 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/kubectl/cmd/util/openapi/validation/BUILD

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,28 @@ load(
88

99
go_library(
1010
name = "go_default_library",
11-
srcs = [
12-
"errors.go",
13-
"types.go",
14-
"validation.go",
15-
],
11+
srcs = ["validation.go"],
1612
importpath = "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/validation",
1713
deps = [
1814
"//pkg/kubectl/cmd/util/openapi:go_default_library",
1915
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
2016
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
2117
"//vendor/k8s.io/apimachinery/pkg/util/json:go_default_library",
2218
"//vendor/k8s.io/apimachinery/pkg/util/yaml:go_default_library",
23-
"//vendor/k8s.io/kube-openapi/pkg/util/proto:go_default_library",
19+
"//vendor/k8s.io/kube-openapi/pkg/util/proto/validation:go_default_library",
2420
],
2521
)
2622

2723
go_test(
28-
name = "go_default_xtest",
24+
name = "go_default_test",
2925
srcs = [
3026
"validation_suite_test.go",
3127
"validation_test.go",
3228
],
3329
data = ["//api/openapi-spec:swagger-spec"],
34-
importpath = "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/validation_test",
30+
importpath = "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/validation",
31+
library = ":go_default_library",
3532
deps = [
36-
":go_default_library",
3733
"//pkg/api/testapi:go_default_library",
3834
"//pkg/kubectl/cmd/util/openapi:go_default_library",
3935
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
@@ -42,6 +38,7 @@ go_test(
4238
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
4339
"//vendor/github.com/onsi/gomega:go_default_library",
4440
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
41+
"//vendor/k8s.io/kube-openapi/pkg/util/proto/validation:go_default_library",
4542
],
4643
)
4744

pkg/kubectl/cmd/util/openapi/validation/validation.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,25 @@ import (
2424
utilerrors "k8s.io/apimachinery/pkg/util/errors"
2525
"k8s.io/apimachinery/pkg/util/json"
2626
"k8s.io/apimachinery/pkg/util/yaml"
27-
"k8s.io/kube-openapi/pkg/util/proto"
27+
"k8s.io/kube-openapi/pkg/util/proto/validation"
2828
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
2929
)
3030

31+
// SchemaValidation validates the object against an OpenAPI schema.
3132
type SchemaValidation struct {
3233
resources openapi.Resources
3334
}
3435

36+
// NewSchemaValidation creates a new SchemaValidation that can be used
37+
// to validate objects.
3538
func NewSchemaValidation(resources openapi.Resources) *SchemaValidation {
3639
return &SchemaValidation{
3740
resources: resources,
3841
}
3942
}
4043

44+
// ValidateBytes will validates the object against using the Resources
45+
// object.
4146
func (v *SchemaValidation) ValidateBytes(data []byte) error {
4247
obj, err := parse(data)
4348
if err != nil {
@@ -80,12 +85,7 @@ func (v *SchemaValidation) validateResource(obj interface{}, gvk schema.GroupVer
8085
return nil
8186
}
8287

83-
rootValidation, err := itemFactory(proto.NewPath(gvk.Kind), obj)
84-
if err != nil {
85-
return []error{err}
86-
}
87-
resource.Accept(rootValidation)
88-
return rootValidation.Errors()
88+
return validation.ValidateModel(obj, resource, gvk.Kind)
8989
}
9090

9191
func parse(data []byte) (interface{}, error) {

pkg/kubectl/cmd/util/openapi/validation/validation_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package validation_test
17+
package validation
1818

1919
import (
2020
. "github.com/onsi/ginkgo"

pkg/kubectl/cmd/util/openapi/validation/validation_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package validation_test
17+
package validation
1818

1919
import (
2020
"path/filepath"
@@ -23,23 +23,23 @@ import (
2323
. "github.com/onsi/gomega"
2424

2525
utilerrors "k8s.io/apimachinery/pkg/util/errors"
26+
"k8s.io/kube-openapi/pkg/util/proto/validation"
2627
// This dependency is needed to register API types.
2728
_ "k8s.io/kubernetes/pkg/api/testapi"
2829
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
2930
tst "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
30-
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/validation"
3131
)
3232

3333
var fakeSchema = tst.Fake{Path: filepath.Join("..", "..", "..", "..", "..", "..", "api", "openapi-spec", "swagger.json")}
3434

3535
var _ = Describe("resource validation using OpenAPI Schema", func() {
36-
var validator *validation.SchemaValidation
36+
var validator *SchemaValidation
3737
BeforeEach(func() {
3838
s, err := fakeSchema.OpenAPISchema()
3939
Expect(err).To(BeNil())
4040
resources, err := openapi.NewOpenAPIData(s)
4141
Expect(err).To(BeNil())
42-
validator = validation.NewSchemaValidation(resources)
42+
validator = NewSchemaValidation(resources)
4343
Expect(validator).ToNot(BeNil())
4444
})
4545

0 commit comments

Comments
 (0)