Skip to content

Commit

Permalink
test: add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
petr-muller committed Mar 1, 2024
1 parent ac37481 commit 5f53aa9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/featuregates/featurechangestopper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func NewChangeStopper(
cacheSynced: []cache.InformerSynced{featureGateInformer.Informer().HasSynced},
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "feature-gate-stopper"),
}

klog.Infof("NewChangeStopper: startingRequiredFeatureSet=%q", startingRequiredFeatureSet)
klog.Infof("NewChangeStopper: startingCVOGates=%+v", startingCVOGates)
c.queue.Add("cluster") // seed an initial sync, in case startingRequiredFeatureSet is wrong
if _, err := featureGateInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(_ interface{}) {
Expand All @@ -67,15 +68,23 @@ func NewChangeStopper(
func (c *ChangeStopper) syncHandler(_ context.Context) (done bool, err error) {
var current configv1.FeatureSet
var currentCvoGates CvoGates
klog.Info("ChangeStopper.syncHandler: Processing work item")
if featureGates, err := c.featureGateLister.Get("cluster"); err == nil {

current = featureGates.Spec.FeatureSet
currentCvoGates = CvoGatesFromFeatureGate(featureGates, c.startingCvoGates.desiredVersion)
klog.Info("ChangeStopper.syncHandler: got gate, featureset=%q", current)
klog.Info("ChangeStopper.syncHandler: got gate, gates=%+v", currentCvoGates)
} else if !apierrors.IsNotFound(err) {
return false, err
} else {
klog.Info("ChangeStopper.syncHandler: not-found error: %v", err)
}

featureSetChanged := current != c.startingRequiredFeatureSet
cvoFeaturesChanged := currentCvoGates != c.startingCvoGates
klog.Infof("ChangeStopper.syncHandler: featureSetChanged=%v", featureSetChanged)
klog.Infof("ChangeStopper.syncHandler: cvoFeaturesChanged=%v", cvoFeaturesChanged)
if featureSetChanged || cvoFeaturesChanged {
var action string
if c.shutdownFn == nil {
Expand Down Expand Up @@ -118,6 +127,7 @@ func (c *ChangeStopper) Run(ctx context.Context, shutdownFn context.CancelFunc)
if !cache.WaitForCacheSync(ctx.Done(), c.cacheSynced...) {
return errors.New("feature gate cache failed to sync")
}
klog.Infof("ChangeStopper.Run(): Cache synced")

err := wait.PollUntilContextCancel(ctx, 30*time.Second, true, c.runWorker)
klog.Info("Shutting down stop-on-featureset-change controller")
Expand Down
4 changes: 4 additions & 0 deletions pkg/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ func (c *Context) InitializeFromPayload(ctx context.Context, restConfig *rest.Co
var clusterFeatureGate *configv1.FeatureGate

fgInformer := c.InformerFactory.Config().V1().FeatureGates()
// TODO: Maybe we need to wait for cache sync but if that was the case then why the stopper does not restart us :/

// client-go automatically retries some network blip errors on GETs for 30s by default, and we want to
// retry the remaining ones ourselves. If we fail longer than that, the operator won't be able to do work
Expand All @@ -524,6 +525,7 @@ func (c *Context) InitializeFromPayload(ctx context.Context, restConfig *rest.Co
// if we have no featuregates, then the cluster is using the default featureset, which is "".
// This excludes everything that could possibly depend on a different feature set.
startingFeatureSet = ""
klog.Info("InitializeFromPayload: FeatureGate not found in cluster, using default feature set")
return true, nil
case fgErr != nil:
lastError = fgErr
Expand All @@ -532,6 +534,8 @@ func (c *Context) InitializeFromPayload(ctx context.Context, restConfig *rest.Co
default:
clusterFeatureGate = gate
startingFeatureSet = gate.Spec.FeatureSet
klog.Infof("InitializeFromPayload: FeatureGate found in cluster, using its feature set %q", startingFeatureSet)
klog.Infof("InitializeFromPayload: FeatureGate found in cluster, its status %+v", gate.Status)
return true, nil
}
}); err != nil {
Expand Down

0 comments on commit 5f53aa9

Please sign in to comment.