@@ -31,7 +31,7 @@ import (
3131 "github.com/caicloud/loadbalancer-controller/pkg/provider"
3232 "github.com/caicloud/loadbalancer-controller/pkg/proxy"
3333
34- apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1 "
34+ apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1 "
3535 "k8s.io/apimachinery/pkg/api/errors"
3636 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3737 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -130,14 +130,17 @@ func (lbc *LoadBalancerController) Run(workers int, stopCh <-chan struct{}) {
130130
131131// ensure loadbalancer tpr initialized
132132func (lbc * LoadBalancerController ) ensureResource () error {
133+ // set x-kubernetes-preserve-unknown-fields to true, stops the API server
134+ // decoding step from pruning fields which are not specified
135+ // in the validation schema.
136+ xPreserveUnknownFields := true
133137 crd := & apiextensions.CustomResourceDefinition {
134138 ObjectMeta : metav1.ObjectMeta {
135139 Name : "loadbalancers." + lbapi .GroupName ,
136140 },
137141 Spec : apiextensions.CustomResourceDefinitionSpec {
138- Group : lbapi .GroupName ,
139- Version : lbapi .SchemeGroupVersion .Version ,
140- Scope : apiextensions .NamespaceScoped ,
142+ Group : lbapi .GroupName ,
143+ Scope : apiextensions .NamespaceScoped ,
141144 Names : apiextensions.CustomResourceDefinitionNames {
142145 Plural : "loadbalancers" ,
143146 Singular : "loadbalancer" ,
@@ -147,26 +150,40 @@ func (lbc *LoadBalancerController) ensureResource() error {
147150 "lb" ,
148151 },
149152 },
150- AdditionalPrinterColumns : []apiextensions.CustomResourceColumnDefinition {
153+ Versions : []apiextensions.CustomResourceDefinitionVersion {
151154 {
152- Name : "VIP" ,
153- Type : "string" ,
154- JSONPath : ".spec.providers.*.vip" ,
155- },
156- {
157- Name : "VIPS" ,
158- Type : "string" ,
159- JSONPath : ".spec.providers.*.vips" ,
160- },
161- {
162- Name : "NODES" ,
163- Type : "string" ,
164- JSONPath : ".spec.nodes.names" ,
155+ Name : lbapi .SchemeGroupVersion .Version ,
156+ AdditionalPrinterColumns : []apiextensions.CustomResourceColumnDefinition {
157+ {
158+ Name : "VIP" ,
159+ Type : "string" ,
160+ JSONPath : ".spec.providers.*.vip" ,
161+ },
162+ {
163+ Name : "VIPS" ,
164+ Type : "string" ,
165+ JSONPath : ".spec.providers.*.vips" ,
166+ },
167+ {
168+ Name : "NODES" ,
169+ Type : "string" ,
170+ JSONPath : ".spec.nodes.names" ,
171+ },
172+ },
173+ Schema : & apiextensions.CustomResourceValidation {
174+ OpenAPIV3Schema : & apiextensions.JSONSchemaProps {
175+ Type : "object" ,
176+ // x-kubernetes-preserve-unknown-fields
177+ XPreserveUnknownFields : & xPreserveUnknownFields ,
178+ },
179+ },
180+ Served : true ,
181+ Storage : true ,
165182 },
166183 },
167184 },
168185 }
169- _ , err := lbc .client .Apiextensions ().ApiextensionsV1beta1 ().CustomResourceDefinitions ().Create (crd )
186+ _ , err := lbc .client .Apiextensions ().ApiextensionsV1 ().CustomResourceDefinitions ().Create (crd )
170187
171188 if errors .IsAlreadyExists (err ) {
172189 log .Info ("Skip the creation for CustomResourceDefinition LoadBalancer because it has already been created" )
0 commit comments