Skip to content

Commit

Permalink
Add IsPolicySet in SriovNetworkNodeState
Browse files Browse the repository at this point in the history
There is a stage when the SriovNetworkNodeState is initializing
where the spec is empty because the SriovNetworkNodePolicyReconciler
did not yet applied the policies.

It can cause a non required action by the plugins,
that will try to apply the empty spec by resetting the NIC for example.

This commit adds IsPolicySet, a boolean field to the spec of SriovNetworkNodeState.

IsPolicySet will be set to true only if the SriovNetworkNodeState spec has been
computed.
The config daemon will not run the plugins if IsPolicySet is false.

Solves issue #283

Signed-off-by: Fred Rolland <frolland@nvidia.com>
  • Loading branch information
rollandf committed Apr 26, 2022
1 parent 70b25f6 commit 16654d4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/v1/sriovnetworknodestate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
type SriovNetworkNodeStateSpec struct {
DpConfigVersion string `json:"dpConfigVersion,omitempty"`
Interfaces Interfaces `json:"interfaces,omitempty"`
IsPolicySet bool `json:"isPolicySet,omitempty"`
}

type Interface struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ spec:
- pciAddress
type: object
type: array
isPolicySet:
type: boolean
type: object
status:
description: SriovNetworkNodeStateStatus defines the observed state of
Expand Down
10 changes: 10 additions & 0 deletions controllers/sriovnetworknodepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncSriovNetworkNodeState(np *sriovne
logger.Info("Fail to get SriovNetworkNodeState", "namespace", ns.Namespace, "name", ns.Name)
if errors.IsNotFound(err) {
ns.Spec.DpConfigVersion = cksum
ns.Spec.IsPolicySet = false
err = r.Create(context.TODO(), ns)
if err != nil {
return fmt.Errorf("Couldn't create SriovNetworkNodeState: %v", err)
Expand All @@ -280,6 +281,12 @@ func (r *SriovNetworkNodePolicyReconciler) syncSriovNetworkNodeState(np *sriovne
return fmt.Errorf("Failed to get SriovNetworkNodeState: %v", err)
}
} else {

if len(found.Status.Interfaces) == 0 {
logger.Info("SriovNetworkNodeState Status Interfaces are empty. Skip update of policies in spec")
return nil
}

logger.Info("SriovNetworkNodeState already exists, updating")
newVersion := found.DeepCopy()
newVersion.Spec = ns.Spec
Expand Down Expand Up @@ -308,6 +315,9 @@ func (r *SriovNetworkNodePolicyReconciler) syncSriovNetworkNodeState(np *sriovne
}
}
newVersion.Spec.DpConfigVersion = cksum
// Setting IsPolicySet to 'true' to indicate to the config daemon
// that relevant policies are available in the spec.
newVersion.Spec.IsPolicySet = true
if equality.Semantic.DeepDerivative(newVersion.Spec, found.Spec) {
logger.Info("SriovNetworkNodeState did not change, not updating")
return nil
Expand Down
7 changes: 5 additions & 2 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,15 @@ func (dn *Daemon) nodeStateSyncHandler(generation int64) error {
return nil
}

if !latestState.Spec.IsPolicySet {
glog.V(0).Infof("nodeStateSyncHandler(): Interface policy spec not yet set")
return nil
}

dn.refreshCh <- Message{
syncStatus: "InProgress",
lastSyncError: "",
}

// load plugins if has not loaded
if len(dn.LoadedPlugins) == 0 {
err = dn.loadVendorPlugins(latestState)
Expand All @@ -461,7 +465,6 @@ func (dn *Daemon) nodeStateSyncHandler(generation int64) error {
return err
}
}

reqReboot := false
reqDrain := false
for k, p := range dn.LoadedPlugins {
Expand Down

0 comments on commit 16654d4

Please sign in to comment.