sigs.k8s.io/cluster-api@v1.7.1/internal/test/builder/controlplane.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 // ControlPlaneGroupVersion is group version used for control plane objects. 26 ControlPlaneGroupVersion = schema.GroupVersion{Group: "controlplane.cluster.x-k8s.io", Version: "v1beta1"} 27 28 // GenericControlPlaneKind is the Kind for the GenericControlPlane. 29 GenericControlPlaneKind = "GenericControlPlane" 30 // GenericControlPlaneCRD is a generic control plane CRD. 31 GenericControlPlaneCRD = untypedCRD(ControlPlaneGroupVersion.WithKind(GenericControlPlaneKind)) 32 33 // GenericControlPlaneTemplateKind is the Kind for the GenericControlPlaneTemplate. 34 GenericControlPlaneTemplateKind = "GenericControlPlaneTemplate" 35 // GenericControlPlaneTemplateCRD is a generic control plane template CRD. 36 GenericControlPlaneTemplateCRD = untypedCRD(ControlPlaneGroupVersion.WithKind(GenericControlPlaneTemplateKind)) 37 38 // TODO: drop generic CRDs in favour of typed test CRDs. 39 40 // TestControlPlaneTemplateKind is the Kind for the TestControlPlaneTemplate. 41 TestControlPlaneTemplateKind = "TestControlPlaneTemplate" 42 // TestControlPlaneTemplateCRD is a test control plane template CRD. 43 TestControlPlaneTemplateCRD = testControlPlaneTemplateCRD(ControlPlaneGroupVersion.WithKind(TestControlPlaneTemplateKind)) 44 45 // TestControlPlaneKind is the Kind for the TestControlPlane. 46 TestControlPlaneKind = "TestControlPlane" 47 // TestControlPlaneCRD is a test control plane CRD. 48 TestControlPlaneCRD = testControlPlaneCRD(ControlPlaneGroupVersion.WithKind(TestControlPlaneKind)) 49 ) 50 51 func testControlPlaneTemplateCRD(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": controPlaneSpecSchema, 66 }, 67 }, 68 }, 69 }, 70 }) 71 } 72 73 func testControlPlaneCRD(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": controPlaneSpecSchema, 81 "status": { 82 Type: "object", 83 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 84 // mandatory field from the Cluster API contract 85 "ready": {Type: "boolean"}, 86 // mandatory field from the Cluster API contract - replicas support 87 "replicas": {Type: "integer", Format: "int32"}, 88 "selector": {Type: "string"}, 89 "readyReplicas": {Type: "integer", Format: "int32"}, 90 "unavailableReplicas": {Type: "integer", Format: "int32"}, 91 "updatedReplicas": {Type: "integer", Format: "int32"}, 92 // Mandatory field from the Cluster API contract - version support 93 "version": {Type: "string"}, 94 // General purpose fields to be used in different test scenario. 95 "foo": {Type: "string"}, 96 "bar": {Type: "string"}, 97 }, 98 }, 99 }) 100 } 101 102 var ( 103 controPlaneSpecSchema = apiextensionsv1.JSONSchemaProps{ 104 Type: "object", 105 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 106 // Mandatory field from the Cluster API contract - version support 107 "version": { 108 Type: "string", 109 }, 110 // mandatory field from the Cluster API contract - replicas support 111 "replicas": { 112 Type: "integer", 113 Format: "int32", 114 }, 115 // mandatory field from the Cluster API contract - using Machines support 116 "machineTemplate": { 117 Type: "object", 118 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 119 "metadata": metadataSchema, 120 "infrastructureRef": refSchema, 121 "nodeDeletionTimeout": {Type: "string"}, 122 "nodeDrainTimeout": {Type: "string"}, 123 }, 124 }, 125 // General purpose fields to be used in different test scenario. 126 "foo": {Type: "string"}, 127 "bar": {Type: "string"}, 128 // Copy of a subset of KCP spec fields to test server side apply on deep nested structs 129 "kubeadmConfigSpec": { 130 Type: "object", 131 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 132 "clusterConfiguration": { 133 Type: "object", 134 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 135 "controllerManager": { 136 Type: "object", 137 Properties: map[string]apiextensionsv1.JSONSchemaProps{ 138 "extraArgs": { 139 Type: "object", 140 AdditionalProperties: &apiextensionsv1.JSONSchemaPropsOrBool{ 141 Schema: &apiextensionsv1.JSONSchemaProps{Type: "string"}, 142 }, 143 }, 144 }, 145 }, 146 }, 147 }, 148 }, 149 }, 150 }, 151 } 152 )