From 6f00b122df617432c2c2f56dca94fc26061b26c6 Mon Sep 17 00:00:00 2001 From: Carson Anderson Date: Thu, 16 Apr 2020 10:35:47 -0600 Subject: [PATCH] Refactor CRD to support K8s 1.15 specific requirements K8s 1.15 added extra validation to CRD structure when using the v1beta1 api. The CRD has been restructured to conform to the new rules. Signed-off-by: Carson Anderson --- go/vt/topo/k8stopo/VitessTopoNodes-crd.yaml | 55 ++++++++++----------- go/vt/topo/k8stopo/server_test.go | 8 +-- helm/vitess/crds/VitessTopoNodes-crd.yaml | 55 ++++++++++----------- 3 files changed, 56 insertions(+), 62 deletions(-) diff --git a/go/vt/topo/k8stopo/VitessTopoNodes-crd.yaml b/go/vt/topo/k8stopo/VitessTopoNodes-crd.yaml index c495e16a700..8bd5f805182 100644 --- a/go/vt/topo/k8stopo/VitessTopoNodes-crd.yaml +++ b/go/vt/topo/k8stopo/VitessTopoNodes-crd.yaml @@ -4,38 +4,35 @@ metadata: name: vitesstoponodes.topo.vitess.io spec: group: topo.vitess.io - versions: - - name: v1beta1 - served: true - storage: true - additionalPrinterColumns: - - name: Key - type: string - description: The full key path - jsonPath: .data.key - schema: - openAPIV3Schema: + additionalPrinterColumns: + - name: Key + type: string + description: The full key path + JSONPath: .data.key + validation: + openAPIV3Schema: + type: object + required: + - data + properties: + data: type: object required: - - data + - key + - value properties: - data: - type: object - required: - - key - - value - properties: - key: - description: A file-path like key. Must be an absolute path. Must not end with a /. - type: string - pattern: '^\/.+[^\/]$' - value: - description: A base64 encoded value. Must be a base64 encoded string or empty string. - type: string - pattern: "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$" - ephemeral: - description: Whether or not the node is considered ephemeral. True for lock and election nodes. - type: boolean + key: + description: A file-path like key. Must be an absolute path. Must not end with a /. + type: string + pattern: '^\/.+[^\/]$' + value: + description: A base64 encoded value. Must be a base64 encoded string or empty string. + type: string + pattern: "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$" + ephemeral: + description: Whether or not the node is considered ephemeral. True for lock and election nodes. + type: boolean + version: v1beta1 scope: Namespaced names: plural: vitesstoponodes diff --git a/go/vt/topo/k8stopo/server_test.go b/go/vt/topo/k8stopo/server_test.go index 3127e1ce2c6..25b8ba95391 100644 --- a/go/vt/topo/k8stopo/server_test.go +++ b/go/vt/topo/k8stopo/server_test.go @@ -29,7 +29,7 @@ import ( "testing" - extensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + extensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" kubeyaml "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/tools/clientcmd" @@ -102,16 +102,16 @@ func TestKubernetesTopo(t *testing.T) { } crdFile, err := os.Open("./VitessTopoNodes-crd.yaml") - defer crdFile.Close() if err != nil { t.Fatal(err) + defer crdFile.Close() } - crd := &extensionsv1.CustomResourceDefinition{} + crd := &extensionsv1beta1.CustomResourceDefinition{} kubeyaml.NewYAMLOrJSONDecoder(crdFile, 2048).Decode(crd) - _, err = apiextensionsClientSet.ApiextensionsV1().CustomResourceDefinitions().Create(crd) + _, err = apiextensionsClientSet.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) if err != nil { t.Fatal(err) } diff --git a/helm/vitess/crds/VitessTopoNodes-crd.yaml b/helm/vitess/crds/VitessTopoNodes-crd.yaml index 60234100206..4e29ee627ed 100644 --- a/helm/vitess/crds/VitessTopoNodes-crd.yaml +++ b/helm/vitess/crds/VitessTopoNodes-crd.yaml @@ -6,38 +6,35 @@ metadata: name: vitesstoponodes.topo.vitess.io spec: group: topo.vitess.io - versions: - - name: v1beta1 - served: true - storage: true - additionalPrinterColumns: - - name: Key - type: string - description: The full key path - jsonPath: .data.key - schema: - openAPIV3Schema: + additionalPrinterColumns: + - name: Key + type: string + description: The full key path + JSONPath: .data.key + validation: + openAPIV3Schema: + type: object + required: + - data + properties: + data: type: object required: - - data + - key + - value properties: - data: - type: object - required: - - key - - value - properties: - key: - description: A file-path like key. Must be an absolute path. Must not end with a /. - type: string - pattern: '^\/.+[^\/]$' - value: - description: A base64 encoded value. Must be a base64 encoded string or empty string. - type: string - pattern: "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$" - ephemeral: - description: Whether or not the node is considered ephemeral. True for lock and election nodes. - type: boolean + key: + description: A file-path like key. Must be an absolute path. Must not end with a /. + type: string + pattern: '^\/.+[^\/]$' + value: + description: A base64 encoded value. Must be a base64 encoded string or empty string. + type: string + pattern: "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$" + ephemeral: + description: Whether or not the node is considered ephemeral. True for lock and election nodes. + type: boolean + version: v1beta1 scope: Namespaced names: plural: vitesstoponodes