Skip to content

Commit

Permalink
Fix Config Daemon node selector
Browse files Browse the repository at this point in the history
When node selectors are added then removed via "configDaemonNodeSelector"
via the sriovoperatorconfigs CRD, certain combinations will not trigger
an update due to the ordering of arguments into "DeepDerivative" from
the reflect library.

This is an example combination of setting "configDaemonNodeSelector" that
would make it such that the sriov-config-daemon daemon set's nodeSelector
to become out of sync with the original "DeepDerivative" argument order:

Step 1) Create 3 labels in node selector:
configDaemonNodeSelector = {"labelA": "", "labelB": "", "labelC": ""}
config-daemon DS NodeSelector = {"labelA": "", "labelB": "", "labelC": ""}

Step 2) Remove 1 label in node selector without making changes to the other labels:
configDaemonNodeSelector = {"labelA": "", "labelB": ""}
config-daemon DS NodeSelector = {"labelA": "", "labelB": "", "labelC": ""} (Out of Sync)

"DeepDerivative" assumes that the left argument is the original (v1) and
the right argument is the updated (v2). For maps it only checks if v1 >
v2 in length:
    case reflect.Map:
        ...
        if v1.Len() > v2.Len() {
            return false
        }
        ...

This commit just reverts changes from commit:
"661a65b8e1aee6339037948732f75d06ceb91611"
Use DeepDerivative to compare the kube object content
Such that we react to changes to node selectors properly.

Signed-off-by: William Zhao <[email protected]>
  • Loading branch information
wizhaoredhat committed Aug 29, 2023
1 parent bf30003 commit 5c1b0af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func ApplyObject(ctx context.Context, client k8sclient.Client, obj *uns.Unstruct
if err := MergeObjectForUpdate(existing, obj); err != nil {
return errors.Wrapf(err, "could not merge object %s with existing", objDesc)
}
if !equality.Semantic.DeepDerivative(obj, existing) {
if !equality.Semantic.DeepEqual(existing, obj) {
if err := client.Update(ctx, obj); err != nil {
return errors.Wrapf(err, "could not update object %s", objDesc)
} else {
log.Printf("update was successful")
log.Printf("update was successful %s", objDesc)
}
}

Expand Down

0 comments on commit 5c1b0af

Please sign in to comment.