Skip to content

Commit

Permalink
OCPBUGS-47643: Allow configuring node placement for nmstate-console-p…
Browse files Browse the repository at this point in the history
…lugin (#1283)

Use the NMState CR fields of .spec.InfraNodeSelector, .spec.InfraTolerations and .spec.InfraAffinity to propagate also to the nmstate-console-plugin Deployment.
This will allow users to control the placement of the nmstate-console-plugin pod, along with the webhook and metrics deployments.

Signed-off-by: Oren Cohen <[email protected]>
  • Loading branch information
orenc1 authored Jan 14, 2025
1 parent c33aada commit 129b149
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
13 changes: 7 additions & 6 deletions api/v1/nmstate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type NMStateSpec struct {
// Affinity is an optional affinity selector that will be added to handler DaemonSet manifest.
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// Affinity is an optional affinity selector that will be added to webhook & certmanager Deployment manifests.
// InfraAffinity is an optional affinity selector that will be added to webhook, metrics & console-plugin Deployment manifests.
// +optional
InfraAffinity *corev1.Affinity `json:"infraAffinity,omitempty"`
// NodeSelector is an optional selector that will be added to handler DaemonSet manifest
Expand All @@ -41,13 +41,14 @@ type NMStateSpec struct {
// If Tolerations is specified, the handler daemonset will be also scheduled on nodes with corresponding taints
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// InfraNodeSelector is an optional selector that will be added to webhook & certmanager Deployment manifests
// If InfraNodeSelector is specified, the webhook and certmanager will run only on nodes that have each of the indicated
// key-value pairs as labels applied to the node.
// InfraNodeSelector is an optional selector that will be added to webhook, metrics & console-plugin Deployment manifests
// If InfraNodeSelector is specified, the webhook, metrics and the console plugin will run only on nodes that have each
// of the indicated key-value pairs as labels applied to the node.
// +optional
InfraNodeSelector map[string]string `json:"infraNodeSelector,omitempty"`
// InfraTolerations is an optional list of tolerations to be added to webhook & certmanager Deployment manifests
// If InfraTolerations is specified, the webhook and certmanager will be able to be scheduled on nodes with corresponding taints
// InfraTolerations is an optional list of tolerations to be added to webhook, metrics & console-plugin Deployment manifests
// If InfraTolerations is specified, the webhook, metrics and the console plugin will be able to be scheduled on nodes with
// corresponding taints
// +optional
InfraTolerations []corev1.Toleration `json:"infraTolerations,omitempty"`
// SelfSignConfiguration defines self signed certificate configuration
Expand Down
15 changes: 8 additions & 7 deletions bundle/manifests/nmstate.io_nmstates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,8 @@ spec:
type: object
type: object
infraAffinity:
description: Affinity is an optional affinity selector that will be
added to webhook & certmanager Deployment manifests.
description: InfraAffinity is an optional affinity selector that will
be added to webhook, metrics & console-plugin Deployment manifests.
properties:
nodeAffinity:
description: Describes node affinity scheduling rules for the
Expand Down Expand Up @@ -1569,14 +1569,15 @@ spec:
additionalProperties:
type: string
description: |-
InfraNodeSelector is an optional selector that will be added to webhook & certmanager Deployment manifests
If InfraNodeSelector is specified, the webhook and certmanager will run only on nodes that have each of the indicated
key-value pairs as labels applied to the node.
InfraNodeSelector is an optional selector that will be added to webhook, metrics & console-plugin Deployment manifests
If InfraNodeSelector is specified, the webhook, metrics and the console plugin will run only on nodes that have each
of the indicated key-value pairs as labels applied to the node.
type: object
infraTolerations:
description: |-
InfraTolerations is an optional list of tolerations to be added to webhook & certmanager Deployment manifests
If InfraTolerations is specified, the webhook and certmanager will be able to be scheduled on nodes with corresponding taints
InfraTolerations is an optional list of tolerations to be added to webhook, metrics & console-plugin Deployment manifests
If InfraTolerations is specified, the webhook, metrics and the console plugin will be able to be scheduled on nodes with
corresponding taints
items:
description: |-
The pod this Toleration is attached to tolerates any taint that matches
Expand Down
7 changes: 7 additions & 0 deletions controllers/operator/nmstate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,17 @@ func (r *NMStateReconciler) applyHandler(instance *nmstatev1.NMState) error {

func (r *NMStateReconciler) applyOpenshiftUIPlugin(instance *nmstatev1.NMState) error {
data := render.MakeRenderData()
data.Funcs["toYaml"] = nmstaterenderer.ToYaml
data.Data["PluginNamespace"] = environment.GetEnvVar("HANDLER_NAMESPACE", "openshift-nmstate")
data.Data["PluginName"] = environment.GetEnvVar("PLUGIN_NAME", "nmstate-console-plugin")
data.Data["PluginImage"] = environment.GetEnvVar("PLUGIN_IMAGE", "quay.io/nmstate/nmstate-console-plugin:release-1.0.0")
data.Data["PluginPort"] = environment.GetEnvVar("PLUGIN_PORT", "9443")

// if not set in the NMState CR, these entries are nil
data.Data["InfraNodeSelector"] = instance.Spec.InfraNodeSelector
data.Data["InfraTolerations"] = instance.Spec.InfraTolerations
data.Data["InfraAffinity"] = instance.Spec.InfraAffinity

return r.renderAndApply(instance, data, filepath.Join("openshift", "ui-plugin"), true)
}

Expand Down
15 changes: 8 additions & 7 deletions deploy/crds/nmstate.io_nmstates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,8 @@ spec:
type: object
type: object
infraAffinity:
description: Affinity is an optional affinity selector that will be
added to webhook & certmanager Deployment manifests.
description: InfraAffinity is an optional affinity selector that will
be added to webhook, metrics & console-plugin Deployment manifests.
properties:
nodeAffinity:
description: Describes node affinity scheduling rules for the
Expand Down Expand Up @@ -1569,14 +1569,15 @@ spec:
additionalProperties:
type: string
description: |-
InfraNodeSelector is an optional selector that will be added to webhook & certmanager Deployment manifests
If InfraNodeSelector is specified, the webhook and certmanager will run only on nodes that have each of the indicated
key-value pairs as labels applied to the node.
InfraNodeSelector is an optional selector that will be added to webhook, metrics & console-plugin Deployment manifests
If InfraNodeSelector is specified, the webhook, metrics and the console plugin will run only on nodes that have each
of the indicated key-value pairs as labels applied to the node.
type: object
infraTolerations:
description: |-
InfraTolerations is an optional list of tolerations to be added to webhook & certmanager Deployment manifests
If InfraTolerations is specified, the webhook and certmanager will be able to be scheduled on nodes with corresponding taints
InfraTolerations is an optional list of tolerations to be added to webhook, metrics & console-plugin Deployment manifests
If InfraTolerations is specified, the webhook, metrics and the console plugin will be able to be scheduled on nodes with
corresponding taints
items:
description: |-
The pod this Toleration is attached to tolerates any taint that matches
Expand Down
9 changes: 9 additions & 0 deletions deploy/openshift/ui-plugin/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ spec:
labels:
app: {{ .PluginName }}
spec:
{{- if .InfraNodeSelector }}
nodeSelector: {{ toYaml .InfraNodeSelector | nindent 8 }}
{{- end }}
{{- if .InfraTolerations }}
tolerations: {{ toYaml .InfraTolerations | nindent 8 }}
{{- end }}
{{- if .InfraAffinity }}
affinity: {{ toYaml .InfraAffinity | nindent 8 }}
{{- end }}
containers:
- name: {{ .PluginName }}
image: {{ .PluginImage }}
Expand Down

0 comments on commit 129b149

Please sign in to comment.