test client-side validation behavior for CRD

support version-skew testing
This commit is contained in:
Haowei Cai
2019-03-01 13:58:13 -08:00
parent cf4384dde6
commit 591f00e9b3
3 changed files with 150 additions and 0 deletions

View File

@@ -24,6 +24,8 @@ import (
"k8s.io/apiextensions-apiserver/test/integration/fixtures"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
utilyaml "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/dynamic"
)
@@ -185,3 +187,14 @@ func (c *TestCrd) GetAPIVersions() []string {
func (c *TestCrd) GetV1DynamicClient() dynamic.ResourceInterface {
return c.DynamicClients["v1"]
}
// PatchSchema takes validation schema in YAML and patches it to given CRD
func (c *TestCrd) PatchSchema(schema []byte) error {
s, err := utilyaml.ToJSON(schema)
if err != nil {
return fmt.Errorf("failed to create json patch: %v", err)
}
patch := []byte(fmt.Sprintf(`{"spec":{"validation":{"openAPIV3Schema":%s}}}`, string(s)))
c.Crd, err = c.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(c.GetMetaName(), types.MergePatchType, patch)
return err
}