Skip to content

Commit

Permalink
Fixed linter issues
Browse files Browse the repository at this point in the history
Signed-off-by: Patryk Strusiewicz-Surmacki <[email protected]>
  • Loading branch information
p-strusiewiczsurmacki-mobica committed Aug 19, 2024
1 parent 672e19a commit 17c6f79
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions pkg/reconciler/nodeconfig_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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 {
Expand Down

0 comments on commit 17c6f79

Please sign in to comment.