Skip to content

Commit

Permalink
Fix Plugin Config Daemon node selector
Browse files Browse the repository at this point in the history
When node selectors are added via "configDaemonNodeSelector"
via the sriovoperatorconfigs CRD then completely removed, the previous
node selectors would remain for the plugin config daemons
(sriov-device-plugin). This was not cleaned up, because the function
"syncPluginDaemonSet" bails out when "configDaemonNodeSelector" is
empty. For example:

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

Step 2) Remove all labels in node selector:
configDaemonNodeSelector = {}
device-plugin DS NodeSelector = {"labelA": "", "labelB": "", "labelC": ""}

The expectation is that the device plugin will revert to the default
node selectors (e.g. {"node-role.kubernetes.io/worker": "",
"kubernetes.io/os": "linux"})

This change will make the node selector field in the sriov-device-plugin
to take in a variable. This default node selector value is then shared
with the code that updates the node selector.

Signed-off-by: William Zhao <[email protected]>
  • Loading branch information
wizhaoredhat committed Aug 23, 2023
1 parent 990648e commit 48b2aeb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
7 changes: 4 additions & 3 deletions bindata/manifests/plugins/sriov-device-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ spec:
spec:
hostNetwork: true
nodeSelector:
kubernetes.io/os: linux
node-role.kubernetes.io/worker:
{{- range $key, $value := .NodeSelectorField }}
{{ $key }}: {{ $value }}
{{- end }}
tolerations:
- operator: Exists
serviceAccountName: sriov-device-plugin
Expand Down Expand Up @@ -70,7 +71,7 @@ spec:
hostPath:
path: /var/lib/kubelet/
- name: config-volume
configMap:
configMap:
name: device-plugin-config
- name: device-info
hostPath:
Expand Down
5 changes: 5 additions & 0 deletions controllers/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ func formatJSON(str string) (string, error) {
}
return prettyJSON.String(), nil
}

func GetDefaultNodeSelector() map[string]string {
return map[string]string{"node-role.kubernetes.io/worker": "",
"kubernetes.io/os": "linux"}
}
1 change: 1 addition & 0 deletions controllers/sriovnetworknodepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncPluginDaemonObjs(ctx context.Cont
data.Data["ReleaseVersion"] = os.Getenv("RELEASEVERSION")
data.Data["ResourcePrefix"] = os.Getenv("RESOURCE_PREFIX")
data.Data["ImagePullSecrets"] = GetImagePullSecrets()
data.Data["NodeSelectorField"] = GetDefaultNodeSelector()

objs, err := renderDsForCR(constants.PluginPath, &data)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions controllers/sriovoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ func (r *SriovOperatorConfigReconciler) syncPluginDaemonSet(ctx context.Context,

names := []string{"sriov-cni", "sriov-device-plugin"}

if len(dc.Spec.ConfigDaemonNodeSelector) == 0 {
return nil
}
for _, name := range names {
err := r.Client.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, ds)
if err != nil {
Expand All @@ -166,7 +163,11 @@ func (r *SriovOperatorConfigReconciler) syncPluginDaemonSet(ctx context.Context,
logger.Error(err, "Couldn't get daemonset", "name", name)
return err
}
ds.Spec.Template.Spec.NodeSelector = dc.Spec.ConfigDaemonNodeSelector
if len(dc.Spec.ConfigDaemonNodeSelector) == 0 {
ds.Spec.Template.Spec.NodeSelector = GetDefaultNodeSelector()
} else {
ds.Spec.Template.Spec.NodeSelector = dc.Spec.ConfigDaemonNodeSelector
}
err = r.Client.Update(ctx, ds)
if err != nil {
logger.Error(err, "Couldn't update daemonset", "name", name)
Expand Down

0 comments on commit 48b2aeb

Please sign in to comment.