Skip to content

Commit

Permalink
Merge pull request #484 from wizhaoredhat/fix_plugin_ds_node_selector
Browse files Browse the repository at this point in the history
Fix Plugin Config Daemon node selector
  • Loading branch information
e0ne authored Sep 28, 2023
2 parents 22c7a2e + 48b2aeb commit 532df8a
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 @@ -76,7 +77,7 @@ spec:
hostPath:
path: /var/lib/kubelet/plugins_registry
- 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 @@ -371,6 +371,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 532df8a

Please sign in to comment.