sigs.k8s.io/cluster-api@v1.7.1/internal/test/builder/bootstrap.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package builder 18 19 import ( 20 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" 21 "k8s.io/apimachinery/pkg/runtime/schema" 22 ) 23 24 var ( 25 // BootstrapGroupVersion is group version used for bootstrap objects. 26 BootstrapGroupVersion = schema.GroupVersion{Group: "bootstrap.cluster.x-k8s.io", Version: "v1beta1"} 27 28 // GenericBootstrapConfigKind is the Kind for the GenericBootstrapConfig. 29 GenericBootstrapConfigKind = "GenericBootstrapConfig" 30 // GenericBootstrapConfigCRD is a generic bootstrap CRD. 31 GenericBootstrapConfigCRD = untypedCRD(BootstrapGroupVersion.WithKind(GenericBootstrapConfigKind)) 32 33 // GenericBootstrapConfigTemplateKind is the Kind for the GenericBootstrapConfigTemplate. 34 GenericBootstrapConfigTemplateKind = "GenericBootstrapConfigTemplate" 35 // GenericBootstrapConfigTemplateCRD is a generic bootstrap template CRD. 36 GenericBootstrapConfigTemplateCRD = untypedCRD(BootstrapGroupVersion.WithKind(GenericBootstrapConfigTemplateKind)) 37 38 // TODO: drop generic CRDs in favour of typed test CRDs. 39 40 // TestBootstrapConfigTemplateKind is the kind for the TestBootstrapConfigTemplate type. 41 TestBootstrapConfigTemplateKind = "TestBootstrapConfigTemplate" 42 // TestBootstrapConfigTemplateCRD is a test bootstrap config template CRD. 43 TestBootstrapConfigTemplateCRD = testBootstrapConfigTemplateCRD(BootstrapGroupVersion.WithKind(TestBootstrapConfigTemplateKind)) 44 45 // TestBootstrapConfigKind is the kind for the TestBootstrapConfig type. 46 TestBootstrapConfigKind = "TestBootstrapConfig" 47 // TestBootstrapConfigCRD is a test bootstrap config CRD. 48 TestBootstrapConfigCRD = testBootstrapConfigCRD(BootstrapGroupVersion.WithKind(TestBootstrapConfigKind)) 49 ) 50 51 func testBootstrapConfigTemplateCRD(gvk schema.GroupVersionKind) *apiextensionsv1.CustomResourceDefinition { 52 return generateCRD(gvk, map[string]apiextensionsv1.JSONSchemaProps{ 53 "metadata": { 54 // NOTE: in CRD there is only a partial definition of metadata schema. 55 // Ref https://github.com/kubernetes-sigs/controller-tools/blob/59485af1c1f6a664655dad49543c474bb4a0d2a2/pkg/crd/gen.go#L185 56 Type: "object", 57 }, 58 "spec": { 59 Type: "object", 60 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 61 // Mandatory field from the Cluster API contract 62 "template": { 63 Type: "object", 64 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 65 "spec": bootstrapConfigSpecSchema, 66 }, 67 }, 68 }, 69 }, 70 }) 71 } 72 73 func testBootstrapConfigCRD(gvk schema.GroupVersionKind) *apiextensionsv1.CustomResourceDefinition { 74 return generateCRD(gvk, map[string]apiextensionsv1.JSONSchemaProps{ 75 "metadata": { 76 // NOTE: in CRD there is only a partial definition of metadata schema. 77 // Ref https://github.com/kubernetes-sigs/controller-tools/blob/59485af1c1f6a664655dad49543c474bb4a0d2a2/pkg/crd/gen.go#L185 78 Type: "object", 79 }, 80 "spec": bootstrapConfigSpecSchema, 81 "status": { 82 Type: "object", 83 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 84 // mandatory field from the Cluster API contract 85 "ready": {Type: "boolean"}, 86 "dataSecretName": {Type: "string"}, 87 // General purpose fields to be used in different test scenario. 88 "foo": {Type: "string"}, 89 "bar": {Type: "string"}, 90 }, 91 }, 92 }) 93 } 94 95 var ( 96 bootstrapConfigSpecSchema = apiextensionsv1.JSONSchemaProps{ 97 Type: "object", 98 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 99 // General purpose fields to be used in different test scenario. 100 "foo": {Type: "string"}, 101 "bar": {Type: "string"}, 102 }, 103 } 104 )