Skip to content

Commit

Permalink
daemon: ensure informer factory starts after observing feature gates
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Batschelet <[email protected]>
  • Loading branch information
hexfusion committed Apr 16, 2024
1 parent 20f1516 commit 8fd70f0
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions cmd/machine-config-daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,39 +194,43 @@ func runStartCmd(_ *cobra.Command, _ []string) {
klog.Fatalf("Failed to initialize: %v", err)
}

criClient, err := cri.NewClient(ctx, constants.DefaultCRIOSocketPath)
if err != nil {
klog.Fatalf("Failed to initialize CRI client: %v", err)
}
prefetchTimeout := 2 * time.Minute
pinnedImageSetManager := daemon.NewPinnedImageSetManager(
startOpts.nodeName,
criClient,
ctrlctx.ClientBuilder.MachineConfigClientOrDie(componentName),
ctrlctx.InformerFactory.Machineconfiguration().V1alpha1().PinnedImageSets(),
ctrlctx.KubeInformerFactory.Core().V1().Nodes(),
ctrlctx.InformerFactory.Machineconfiguration().V1().MachineConfigPools(),
resource.MustParse(constants.MinFreeStorageAfterPrefetch),
constants.DefaultCRIOSocketPath,
constants.KubeletAuthFile,
prefetchTimeout,
ctrlctx.FeatureGateAccess,
)

// start config informer early because feature gate depends on it
ctrlctx.ConfigInformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeInformerFactory.Start(stopCh)
ctrlctx.KubeNamespacedInformerFactory.Start(stopCh)
ctrlctx.InformerFactory.Start(stopCh)
close(ctrlctx.InformersStarted)

select {
case <-ctrlctx.FeatureGateAccess.InitialFeatureGatesObserved():
// ok to start the rest of the informers now that we have observed the initial feature gates
ctrlctx.KubeInformerFactory.Start(stopCh)
ctrlctx.KubeNamespacedInformerFactory.Start(stopCh)
ctrlctx.InformerFactory.Start(stopCh)
close(ctrlctx.InformersStarted)

featureGates, err := ctrlctx.FeatureGateAccess.CurrentFeatureGates()
if err != nil {
klog.Fatalf("Could not get FG: %v", err)
} else {
klog.Infof("FeatureGates initialized: knownFeatureGates=%v", featureGates.KnownFeatures())
if featureGates.Enabled(configv1.FeatureGatePinnedImages) {
criClient, err := cri.NewClient(ctx, constants.DefaultCRIOSocketPath)
if err != nil {
klog.Fatalf("Failed to initialize CRI client: %v", err)
}

prefetchTimeout := 2 * time.Minute
pinnedImageSetManager := daemon.NewPinnedImageSetManager(
startOpts.nodeName,
criClient,
ctrlctx.ClientBuilder.MachineConfigClientOrDie(componentName),
ctrlctx.InformerFactory.Machineconfiguration().V1alpha1().PinnedImageSets(),
ctrlctx.KubeInformerFactory.Core().V1().Nodes(),
ctrlctx.InformerFactory.Machineconfiguration().V1().MachineConfigPools(),
resource.MustParse(constants.MinFreeStorageAfterPrefetch),
constants.DefaultCRIOSocketPath,
constants.KubeletAuthFile,
prefetchTimeout,
ctrlctx.FeatureGateAccess,
)

go pinnedImageSetManager.Run(2, stopCh)
}
}
Expand Down

0 comments on commit 8fd70f0

Please sign in to comment.