mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
@ -77,9 +77,11 @@ func NewAutoRegistrationController(crdinformer crdinformers.CustomResourceDefini
|
||||
cast := obj.(*apiextensions.CustomResourceDefinition)
|
||||
c.enqueueCRD(cast)
|
||||
},
|
||||
UpdateFunc: func(_, obj interface{}) {
|
||||
cast := obj.(*apiextensions.CustomResourceDefinition)
|
||||
c.enqueueCRD(cast)
|
||||
UpdateFunc: func(oldObj, newObj interface{}) {
|
||||
// Enqueue both old and new object to make sure we remove and add appropriate API services.
|
||||
// The working queue will resolve any duplicates and only changes will stay in the queue.
|
||||
c.enqueueCRD(oldObj.(*apiextensions.CustomResourceDefinition))
|
||||
c.enqueueCRD(newObj.(*apiextensions.CustomResourceDefinition))
|
||||
},
|
||||
DeleteFunc: func(obj interface{}) {
|
||||
cast, ok := obj.(*apiextensions.CustomResourceDefinition)
|
||||
@ -120,8 +122,10 @@ func (c *crdRegistrationController) Run(threadiness int, stopCh <-chan struct{})
|
||||
utilruntime.HandleError(err)
|
||||
} else {
|
||||
for _, crd := range crds {
|
||||
if err := c.syncHandler(schema.GroupVersion{Group: crd.Spec.Group, Version: crd.Spec.Version}); err != nil {
|
||||
utilruntime.HandleError(err)
|
||||
for _, version := range crd.Spec.Versions {
|
||||
if err := c.syncHandler(schema.GroupVersion{Group: crd.Spec.Group, Version: version.Name}); err != nil {
|
||||
utilruntime.HandleError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,11 +186,12 @@ func (c *crdRegistrationController) processNextWorkItem() bool {
|
||||
}
|
||||
|
||||
func (c *crdRegistrationController) enqueueCRD(crd *apiextensions.CustomResourceDefinition) {
|
||||
c.queue.Add(schema.GroupVersion{Group: crd.Spec.Group, Version: crd.Spec.Version})
|
||||
for _, version := range crd.Spec.Versions {
|
||||
c.queue.Add(schema.GroupVersion{Group: crd.Spec.Group, Version: version.Name})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *crdRegistrationController) handleVersionUpdate(groupVersion schema.GroupVersion) error {
|
||||
found := false
|
||||
apiServiceName := groupVersion.Version + "." + groupVersion.Group
|
||||
|
||||
// check all CRDs. There shouldn't that many, but if we have problems later we can index them
|
||||
@ -195,26 +200,27 @@ func (c *crdRegistrationController) handleVersionUpdate(groupVersion schema.Grou
|
||||
return err
|
||||
}
|
||||
for _, crd := range crds {
|
||||
if crd.Spec.Version == groupVersion.Version && crd.Spec.Group == groupVersion.Group {
|
||||
found = true
|
||||
break
|
||||
if crd.Spec.Group != groupVersion.Group {
|
||||
continue
|
||||
}
|
||||
for _, version := range crd.Spec.Versions {
|
||||
if version.Name != groupVersion.Version || !version.Served {
|
||||
continue
|
||||
}
|
||||
|
||||
c.apiServiceRegistration.AddAPIServiceToSync(&apiregistration.APIService{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: apiServiceName},
|
||||
Spec: apiregistration.APIServiceSpec{
|
||||
Group: groupVersion.Group,
|
||||
Version: groupVersion.Version,
|
||||
GroupPriorityMinimum: 1000, // CRDs should have relatively low priority
|
||||
VersionPriority: 100, // CRDs will be sorted by kube-like versions like any other APIService with the same VersionPriority
|
||||
},
|
||||
})
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
c.apiServiceRegistration.RemoveAPIServiceToSync(apiServiceName)
|
||||
return nil
|
||||
}
|
||||
|
||||
c.apiServiceRegistration.AddAPIServiceToSync(&apiregistration.APIService{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: apiServiceName},
|
||||
Spec: apiregistration.APIServiceSpec{
|
||||
Group: groupVersion.Group,
|
||||
Version: groupVersion.Version,
|
||||
GroupPriorityMinimum: 1000, // CRDs should have relatively low priority
|
||||
VersionPriority: 100, // CRDs should have relatively low priority
|
||||
},
|
||||
})
|
||||
|
||||
c.apiServiceRegistration.RemoveAPIServiceToSync(apiServiceName)
|
||||
return nil
|
||||
}
|
||||
|
@ -42,8 +42,16 @@ func TestHandleVersionUpdate(t *testing.T) {
|
||||
startingCRDs: []*apiextensions.CustomResourceDefinition{
|
||||
{
|
||||
Spec: apiextensions.CustomResourceDefinitionSpec{
|
||||
Group: "group.com",
|
||||
Version: "v1",
|
||||
Group: "group.com",
|
||||
// Version field is deprecated and crd registration won't rely on it at all.
|
||||
// defaulting route will fill up Versions field if user only provided version field.
|
||||
Versions: []apiextensions.CustomResourceDefinitionVersion{
|
||||
{
|
||||
Name: "v1",
|
||||
Served: true,
|
||||
Storage: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -66,8 +74,14 @@ func TestHandleVersionUpdate(t *testing.T) {
|
||||
startingCRDs: []*apiextensions.CustomResourceDefinition{
|
||||
{
|
||||
Spec: apiextensions.CustomResourceDefinitionSpec{
|
||||
Group: "group.com",
|
||||
Version: "v1",
|
||||
Group: "group.com",
|
||||
Versions: []apiextensions.CustomResourceDefinitionVersion{
|
||||
{
|
||||
Name: "v1",
|
||||
Served: true,
|
||||
Storage: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -78,27 +92,28 @@ func TestHandleVersionUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
registration := &fakeAPIServiceRegistration{}
|
||||
crdCache := cache.NewIndexer(cache.DeletionHandlingMetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||
crdLister := crdlisters.NewCustomResourceDefinitionLister(crdCache)
|
||||
c := crdRegistrationController{
|
||||
crdLister: crdLister,
|
||||
apiServiceRegistration: registration,
|
||||
}
|
||||
for i := range test.startingCRDs {
|
||||
crdCache.Add(test.startingCRDs[i])
|
||||
}
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
registration := &fakeAPIServiceRegistration{}
|
||||
crdCache := cache.NewIndexer(cache.DeletionHandlingMetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||
crdLister := crdlisters.NewCustomResourceDefinitionLister(crdCache)
|
||||
c := crdRegistrationController{
|
||||
crdLister: crdLister,
|
||||
apiServiceRegistration: registration,
|
||||
}
|
||||
for i := range test.startingCRDs {
|
||||
crdCache.Add(test.startingCRDs[i])
|
||||
}
|
||||
|
||||
c.handleVersionUpdate(test.version)
|
||||
c.handleVersionUpdate(test.version)
|
||||
|
||||
if !reflect.DeepEqual(test.expectedAdded, registration.added) {
|
||||
t.Errorf("%s expected %v, got %v", test.name, test.expectedAdded, registration.added)
|
||||
}
|
||||
if !reflect.DeepEqual(test.expectedRemoved, registration.removed) {
|
||||
t.Errorf("%s expected %v, got %v", test.name, test.expectedRemoved, registration.removed)
|
||||
}
|
||||
if !reflect.DeepEqual(test.expectedAdded, registration.added) {
|
||||
t.Errorf("%s expected %v, got %v", test.name, test.expectedAdded, registration.added)
|
||||
}
|
||||
if !reflect.DeepEqual(test.expectedRemoved, registration.removed) {
|
||||
t.Errorf("%s expected %v, got %v", test.name, test.expectedRemoved, registration.removed)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type fakeAPIServiceRegistration struct {
|
||||
|
Reference in New Issue
Block a user