Skip to content

Commit

Permalink
bugfix for clusternet#688
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksontong committed Dec 7, 2023
1 parent 0c98fc8 commit 2b0d8be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pkg/controllermanager/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,17 @@ func (deployer *Deployer) handleBase(baseCopy *appsapi.Base) error {
return err
}

// If the sub associated with base is a dividing strategy, check if there are derived loc resources, if not, do not create desc
if sub, _ := deployer.subsController.FindSubByUID(baseCopy.Labels[known.ConfigSubscriptionUIDLabel]); sub != nil {
if sub.Spec.SchedulingStrategy == appsapi.DividingSchedulingStrategyType {
if locs, _ := deployer.locLister.Localizations(baseCopy.Namespace).List(labels.SelectorFromSet(labels.Set{
string(sub.UID): subscriptionKind.Kind,
})); len(locs) == 0 {
return fmt.Errorf("Waiting loc for Base %s", klog.KObj(baseCopy))
}
}
}

err := deployer.populateDescriptions(baseCopy)
if err != nil {
return err
Expand Down
18 changes: 17 additions & 1 deletion pkg/controllers/apps/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Controller struct {

clusternetClient clusternetclientset.Interface
subsLister applisters.SubscriptionLister
subsIndexer cache.Indexer
recorder record.EventRecorder
syncHandlerFunc SyncHandlerFunc
}
Expand All @@ -68,6 +69,7 @@ func NewController(
c := &Controller{
clusternetClient: clusternetClient,
subsLister: subsInformer.Lister(),
subsIndexer: subsInformer.Informer().GetIndexer(),
recorder: recorder,
syncHandlerFunc: syncHandlerFunc,
}
Expand Down Expand Up @@ -107,8 +109,13 @@ func NewController(
return true, nil
})

err := subsInformer.Informer().AddIndexers(cache.Indexers{known.IndexKeyForSubscriptionUID: utils.SubUidIndexFunc})
if err != nil {
return nil, err
}

// Manage the addition/update of Subscription
_, err := subsInformer.Informer().AddEventHandler(yachtController.DefaultResourceEventHandlerFuncs())
_, err = subsInformer.Informer().AddEventHandler(yachtController.DefaultResourceEventHandlerFuncs())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -255,3 +262,12 @@ func (c *Controller) patchSubscriptionLabels(sub *appsapi.Subscription, labels m
patchData,
metav1.PatchOptions{})
}

func (c *Controller) FindSubByUID(uid string) (*appsapi.Subscription, error) {
objs, err := c.subsIndexer.ByIndex(known.IndexKeyForSubscriptionUID, uid)
if err != nil || len(objs) == 0 {
return nil, fmt.Errorf("find base by uid %s failed: %v %d", uid, err, len(objs))
}

return objs[0].(*appsapi.Subscription), nil
}

0 comments on commit 2b0d8be

Please sign in to comment.