@@ -30,6 +30,7 @@ import (
30
30
"github.com/go-openapi/validate"
31
31
"github.com/golang/glog"
32
32
33
+ apiequality "k8s.io/apimachinery/pkg/api/equality"
33
34
apierrors "k8s.io/apimachinery/pkg/api/errors"
34
35
"k8s.io/apimachinery/pkg/api/meta"
35
36
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -79,6 +80,11 @@ type crdHandler struct {
79
80
80
81
// crdInfo stores enough information to serve the storage for the custom resource
81
82
type crdInfo struct {
83
+ // spec and acceptedNames are used to compare against if a change is made on a CRD. We only update
84
+ // the storage if one of these changes.
85
+ spec * apiextensions.CustomResourceDefinitionSpec
86
+ acceptedNames * apiextensions.CustomResourceDefinitionNames
87
+
82
88
storage * customresource.REST
83
89
requestScope handlers.RequestScope
84
90
}
@@ -108,6 +114,9 @@ func NewCustomResourceDefinitionHandler(
108
114
109
115
crdInformer .Informer ().AddEventHandler (cache.ResourceEventHandlerFuncs {
110
116
UpdateFunc : ret .updateCustomResourceDefinition ,
117
+ DeleteFunc : func (obj interface {}) {
118
+ ret .removeDeadStorage ()
119
+ },
111
120
})
112
121
113
122
ret .customStorage .Store (crdStorageMap {})
@@ -254,6 +263,7 @@ func (r *crdHandler) removeDeadStorage() {
254
263
}
255
264
}
256
265
if ! found {
266
+ glog .V (4 ).Infof ("Removing dead CRD storage for %v" , s .requestScope .Resource )
257
267
s .storage .DestroyFunc ()
258
268
delete (storageMap , uid )
259
269
}
@@ -376,6 +386,9 @@ func (r *crdHandler) getServingInfoFor(crd *apiextensions.CustomResourceDefiniti
376
386
}
377
387
378
388
ret = & crdInfo {
389
+ spec : & crd .Spec ,
390
+ acceptedNames : & crd .Status .AcceptedNames ,
391
+
379
392
storage : storage ,
380
393
requestScope : requestScope ,
381
394
}
@@ -411,14 +424,24 @@ func (c crdObjectConverter) ConvertFieldLabel(version, kind, label, value string
411
424
}
412
425
}
413
426
414
- func (c * crdHandler ) updateCustomResourceDefinition (oldObj , _ interface {}) {
427
+ func (c * crdHandler ) updateCustomResourceDefinition (oldObj , newObj interface {}) {
415
428
oldCRD := oldObj .(* apiextensions.CustomResourceDefinition )
416
- glog . V ( 4 ). Infof ( "Updating customresourcedefinition %s" , oldCRD . Name )
429
+ newCRD := newObj .( * apiextensions. CustomResourceDefinition )
417
430
418
431
c .customStorageLock .Lock ()
419
432
defer c .customStorageLock .Unlock ()
420
-
421
433
storageMap := c .customStorage .Load ().(crdStorageMap )
434
+
435
+ oldInfo , found := storageMap [newCRD .UID ]
436
+ if ! found {
437
+ return
438
+ }
439
+ if apiequality .Semantic .DeepEqual (& newCRD .Spec , oldInfo .spec ) && apiequality .Semantic .DeepEqual (& newCRD .Status .AcceptedNames , oldInfo .acceptedNames ) {
440
+ glog .V (6 ).Infof ("Ignoring customresourcedefinition %s update because neither spec, nor accepted names changed" , oldCRD .Name )
441
+ return
442
+ }
443
+
444
+ glog .V (4 ).Infof ("Updating customresourcedefinition %s" , oldCRD .Name )
422
445
storageMap2 := make (crdStorageMap , len (storageMap ))
423
446
424
447
// Copy because we cannot write to storageMap without a race
0 commit comments