github.com/Mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/pkg/config/crd.go (about) 1 /* 2 Copyright 2018 Mirantis 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 config 18 19 import ( 20 apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" 21 meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 "k8s.io/apimachinery/pkg/runtime" 23 24 virtlet_v1 "github.com/Mirantis/virtlet/pkg/api/virtlet.k8s/v1" 25 ) 26 27 func configMappingProps() *apiext.JSONSchemaProps { 28 return &apiext.JSONSchemaProps{ 29 Properties: map[string]apiext.JSONSchemaProps{ 30 "spec": { 31 Properties: map[string]apiext.JSONSchemaProps{ 32 "nodeName": { 33 Type: "string", 34 }, 35 "nodeSelector": { 36 Type: "object", 37 // FIXME: https://github.com/kubernetes/kubernetes/issues/59485 38 // AdditionalProperties: &apiext.JSONSchemaPropsOrBool{ 39 // Allows: true, 40 // Schema: &apiext.JSONSchemaProps{ 41 // Type: "string", 42 // }, 43 // }, 44 }, 45 "priority": { 46 Type: "integer", 47 }, 48 "config": { 49 Properties: configFieldSet(&virtlet_v1.VirtletConfig{}).schemaProps(), 50 }, 51 }, 52 }, 53 }, 54 } 55 } 56 57 // GetCRDDefinitions returns custom resource definitions for VirtletImageMapping kind in k8s. 58 func GetCRDDefinitions() []runtime.Object { 59 gv := virtlet_v1.SchemeGroupVersion 60 return []runtime.Object{ 61 &apiext.CustomResourceDefinition{ 62 TypeMeta: meta_v1.TypeMeta{ 63 APIVersion: "apiextensions.k8s.io/v1beta1", 64 Kind: "CustomResourceDefinition", 65 }, 66 ObjectMeta: meta_v1.ObjectMeta{ 67 Labels: map[string]string{ 68 "virtlet.cloud": "", 69 }, 70 Name: "virtletimagemappings." + gv.Group, 71 }, 72 Spec: apiext.CustomResourceDefinitionSpec{ 73 Group: gv.Group, 74 Version: gv.Version, 75 Scope: apiext.NamespaceScoped, 76 Names: apiext.CustomResourceDefinitionNames{ 77 Plural: "virtletimagemappings", 78 Singular: "virtletimagemapping", 79 Kind: "VirtletImageMapping", 80 ShortNames: []string{"vim"}, 81 }, 82 }, 83 }, 84 &apiext.CustomResourceDefinition{ 85 TypeMeta: meta_v1.TypeMeta{ 86 APIVersion: "apiextensions.k8s.io/v1beta1", 87 Kind: "CustomResourceDefinition", 88 }, 89 ObjectMeta: meta_v1.ObjectMeta{ 90 Labels: map[string]string{ 91 "virtlet.cloud": "", 92 }, 93 Name: "virtletconfigmappings." + gv.Group, 94 }, 95 Spec: apiext.CustomResourceDefinitionSpec{ 96 Group: gv.Group, 97 Version: gv.Version, 98 Scope: apiext.NamespaceScoped, 99 Names: apiext.CustomResourceDefinitionNames{ 100 Plural: "virtletconfigmappings", 101 Singular: "virtletconfigmapping", 102 Kind: "VirtletConfigMapping", 103 ShortNames: []string{"vcm"}, 104 }, 105 Validation: &apiext.CustomResourceValidation{ 106 OpenAPIV3Schema: configMappingProps(), 107 }, 108 }, 109 }, 110 } 111 }