Skip to content

Commit

Permalink
daemon/pinnedimagesets: ensure sync on first boot
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Batschelet <[email protected]>
  • Loading branch information
hexfusion committed Apr 25, 2024
1 parent 8a5f52c commit 7c8fed4
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion pkg/daemon/pinned_image_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ type PinnedImageSetManager struct {
queue workqueue.RateLimitingInterface
featureGatesAccessor featuregates.FeatureGateAccess

// mutex to protect the cancelFn
// mutex protects cancelFn
mu sync.Mutex
cancelFn context.CancelFunc

once sync.Once
bootstrapped bool
}

// NewPinnedImageSetManager creates a new pinned image set manager.
Expand Down Expand Up @@ -175,6 +178,11 @@ func NewPinnedImageSetManager(
DeleteFunc: p.deleteMachineConfigPool,
})

nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: p.handleNodeEvent,
UpdateFunc: func(oldObj, newObj interface{}) { p.handleNodeEvent(newObj) },
})

p.syncHandler = p.sync
p.enqueueMachineConfigPool = p.enqueue

Expand Down Expand Up @@ -912,6 +920,40 @@ func (p *PinnedImageSetManager) updatePinnedImageSet(oldObj, newObj interface{})
}
}

func (p *PinnedImageSetManager) handleNodeEvent(newObj interface{}) {
newNode := newObj.(*corev1.Node)
if newNode.Name != p.nodeName {
return
}

pools, _, err := helpers.GetPoolsForNode(p.mcpLister, newNode)
if err != nil {
klog.Errorf("error finding pools for node %s: %v", newNode.Name, err)
return
}
if pools == nil {
return
}

// handle first sync during startup
if !p.isBootstrapped() {
for _, pool := range pools {
p.enqueueMachineConfigPool(pool)
}
}
p.setBootstrapped()
}

func (p *PinnedImageSetManager) isBootstrapped() bool {
return p.bootstrapped
}

func (p *PinnedImageSetManager) setBootstrapped() {
defer p.once.Do(func() {
p.bootstrapped = true
})
}

func (p *PinnedImageSetManager) addMachineConfigPool(obj interface{}) {
pool := obj.(*mcfgv1.MachineConfigPool)
if pool.DeletionTimestamp != nil {
Expand Down

0 comments on commit 7c8fed4

Please sign in to comment.