diff --git a/pkg/reconciler/nodeconfig_reconciler.go b/pkg/reconciler/nodeconfig_reconciler.go index 6ec1e7a..708e9c0 100644 --- a/pkg/reconciler/nodeconfig_reconciler.go +++ b/pkg/reconciler/nodeconfig_reconciler.go @@ -124,9 +124,9 @@ func getFirstValidRevision(revisions []v1alpha1.NetworkConfigRevision) *v1alpha1 return nil } -func (ncr *NodeConfigReconciler) processConfigs(ctx context.Context, configs []v1alpha1.NodeNetworkConfig, revision *v1alpha1.NetworkConfigRevision) (bool, int, int, error) { - ready := 0 - ongoing := 0 +func (ncr *NodeConfigReconciler) processConfigs(ctx context.Context, configs []v1alpha1.NodeNetworkConfig, revision *v1alpha1.NetworkConfigRevision) (shouldSkip bool, ready, ongoing int, err error) { + ready = 0 + ongoing = 0 for i := range configs { // Every NodeNetworkConfig obejct should have 2 owner references - for NodeConfigRevision and for the Node. If there is only one owner reference, // it means that either node or revision were deleted, so the config itself can be deleted as well. @@ -149,12 +149,11 @@ func (ncr *NodeConfigReconciler) processConfigs(ctx context.Context, configs []v // Update ongoing counter ongoing++ // If status is 'provisioning' or empty check for how long this status is set already, and if time configTimeout is exceeded, tag config as invalid. - if time.Now().After(configs[i].Status.LastUpdate.Add(configTimeout)) { - configs[i].Status.ConfigStatus = StatusInvalid - configs[i].Status.LastUpdate = metav1.Now() - if err := ncr.client.Status().Update(ctx, &configs[i]); err != nil { - return true, ready, ongoing, fmt.Errorf("error invalidating config: %w", err) - } + invalidated, err := ncr.invalidateConfig(ctx, &configs[i]) + if err != nil { + return true, ready, ongoing, fmt.Errorf("error invalidating config: %w", err) + } + if invalidated { return true, ready, ongoing, nil } case StatusProvisioned: @@ -166,6 +165,18 @@ func (ncr *NodeConfigReconciler) processConfigs(ctx context.Context, configs []v return false, ready, ongoing, nil } +func (ncr *NodeConfigReconciler) invalidateConfig(ctx context.Context, cfg *v1alpha1.NodeNetworkConfig) (bool, error) { + if time.Now().After(cfg.Status.LastUpdate.Add(configTimeout)) { + cfg.Status.ConfigStatus = StatusInvalid + cfg.Status.LastUpdate = metav1.Now() + if err := ncr.client.Status().Update(ctx, cfg); err != nil { + return true, fmt.Errorf("error updating config's status: %w", err) + } + return true, nil + } + return false, nil +} + func getNodesToDeploy(nodes map[string]*corev1.Node, configs []v1alpha1.NodeNetworkConfig, revision *v1alpha1.NetworkConfigRevision) []*corev1.Node { for nodeName := range nodes { for i := range configs {