diff --git a/manifests/state-container-networking-plugins/0010-container-networking-plugins-ds.yml b/manifests/state-container-networking-plugins/0010-container-networking-plugins-ds.yml index 84feb5b3..e3c8fea2 100644 --- a/manifests/state-container-networking-plugins/0010-container-networking-plugins-ds.yml +++ b/manifests/state-container-networking-plugins/0010-container-networking-plugins-ds.yml @@ -55,6 +55,17 @@ spec: imagePullPolicy: IfNotPresent securityContext: privileged: true + {{- with index .RuntimeSpec.ContainerResources "cni-plugins" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 14}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 14}} + {{- end }} + {{- else }} resources: requests: cpu: "100m" @@ -62,6 +73,7 @@ spec: limits: cpu: "100m" memory: "50Mi" + {{- end }} volumeMounts: - name: cnibin mountPath: /host/opt/cni/bin diff --git a/manifests/state-ib-kubernetes/0070-deployment.yaml b/manifests/state-ib-kubernetes/0070-deployment.yaml index 562c5cae..025c046f 100644 --- a/manifests/state-ib-kubernetes/0070-deployment.yaml +++ b/manifests/state-ib-kubernetes/0070-deployment.yaml @@ -71,10 +71,22 @@ spec: image: {{ .CrSpec.Repository }}/{{ .CrSpec.Image }}:{{ .CrSpec.Version }} imagePullPolicy: IfNotPresent command: ["/usr/bin/ib-kubernetes"] + {{- with index .RuntimeSpec.ContainerResources "ib-kubernetes" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 14}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 14}} + {{- end }} + {{- else }} resources: requests: cpu: 100m memory: 300Mi + {{- end }} env: - name: DAEMON_SM_PLUGIN value: "ufm" diff --git a/manifests/state-ipoib-cni/0050-ipoib-cni-ds.yml b/manifests/state-ipoib-cni/0050-ipoib-cni-ds.yml index 26ab6f41..f72275e0 100644 --- a/manifests/state-ipoib-cni/0050-ipoib-cni-ds.yml +++ b/manifests/state-ipoib-cni/0050-ipoib-cni-ds.yml @@ -59,6 +59,17 @@ spec: containers: - name: ipoib-cni image: {{ .CrSpec.Repository }}/{{ .CrSpec.Image }}:{{ .CrSpec.Version }} + {{- with index .RuntimeSpec.ContainerResources "ipoib-cni" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 14}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 14}} + {{- end }} + {{- else }} resources: requests: cpu: "100m" @@ -66,6 +77,7 @@ spec: limits: cpu: "100m" memory: "50Mi" + {{- end }} securityContext: privileged: true volumeMounts: diff --git a/manifests/state-multus-cni/0050-multus-ds.yml b/manifests/state-multus-cni/0050-multus-ds.yml index c1fcbf6c..d99fa697 100644 --- a/manifests/state-multus-cni/0050-multus-ds.yml +++ b/manifests/state-multus-cni/0050-multus-ds.yml @@ -55,6 +55,17 @@ spec: preStop: exec: command: ["/bin/sh", "-c", "rm -f /host/etc/cni/net.d/00-multus.conf"] + {{- with index .RuntimeSpec.ContainerResources "kube-multus" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 14}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 14}} + {{- end }} + {{- else }} resources: requests: cpu: "100m" @@ -62,6 +73,7 @@ spec: limits: cpu: "100m" memory: "50Mi" + {{- end }} securityContext: privileged: true volumeMounts: diff --git a/manifests/state-nic-feature-discovery/030-nic-feature-discovery-ds.yaml b/manifests/state-nic-feature-discovery/030-nic-feature-discovery-ds.yaml index 5ffb3dbc..40a0d7f3 100644 --- a/manifests/state-nic-feature-discovery/030-nic-feature-discovery-ds.yaml +++ b/manifests/state-nic-feature-discovery/030-nic-feature-discovery-ds.yaml @@ -63,6 +63,17 @@ spec: args: - --v=0 - --logging-format=json + {{- with index .RuntimeSpec.ContainerResources "nic-feature-discovery" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 14}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 14}} + {{- end }} + {{- else }} resources: requests: cpu: "100m" @@ -70,6 +81,7 @@ spec: limits: cpu: "300m" memory: "150Mi" + {{- end }} securityContext: privileged: true volumeMounts: diff --git a/manifests/state-nv-ipam-cni/040-nv-ipam-controller.yaml b/manifests/state-nv-ipam-cni/040-nv-ipam-controller.yaml index dda96c1b..833671e6 100644 --- a/manifests/state-nv-ipam-cni/040-nv-ipam-controller.yaml +++ b/manifests/state-nv-ipam-cni/040-nv-ipam-controller.yaml @@ -119,10 +119,22 @@ spec: port: 8081 initialDelaySeconds: 5 periodSeconds: 10 + {{- with index .RuntimeSpec.ContainerResources "nv-ipam-controller" }} resources: + {{- if .Requests }} requests: - cpu: 100m - memory: 300Mi + {{ .Requests | yaml | nindent 14}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 14}} + {{- end }} + {{- else }} + resources: + requests: + cpu: "100m" + memory: "300Mi" + {{- end }} volumeMounts: {{- if .CrSpec.EnableWebhook }} - mountPath: /tmp/k8s-webhook-server/serving-certs diff --git a/manifests/state-nv-ipam-cni/040-nv-ipam-node.yaml b/manifests/state-nv-ipam-cni/040-nv-ipam-node.yaml index b2c649a0..d0b10226 100644 --- a/manifests/state-nv-ipam-cni/040-nv-ipam-node.yaml +++ b/manifests/state-nv-ipam-cni/040-nv-ipam-node.yaml @@ -81,6 +81,17 @@ spec: - --cni-log-file=/var/log/nv-ipam-cni.log - --cni-log-level=info # log level for shim CNI - --ippools-namespace=$(IPPOOLS_NAMESPACE) + {{- with index .RuntimeSpec.ContainerResources "nv-ipam-node" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 14}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 14}} + {{- end }} + {{- else }} resources: requests: cpu: "100m" @@ -88,6 +99,7 @@ spec: limits: cpu: "300m" memory: "300Mi" + {{- end }} securityContext: privileged: true volumeMounts: diff --git a/manifests/state-ofed-driver/0050_ofed-driver-ds.yaml b/manifests/state-ofed-driver/0050_ofed-driver-ds.yaml index bfa46405..958b36c8 100644 --- a/manifests/state-ofed-driver/0050_ofed-driver-ds.yaml +++ b/manifests/state-ofed-driver/0050_ofed-driver-ds.yaml @@ -112,6 +112,17 @@ spec: readOnly: {{ .ReadOnly }} {{- end }} {{- end }} + {{- with index .RuntimeSpec.ContainerResources "mofed-container" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 14}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 14}} + {{- end }} + {{- end }} startupProbe: exec: command: diff --git a/manifests/state-rdma-device-plugin/0060_rdma-shared-dev-plugin-ds.yaml b/manifests/state-rdma-device-plugin/0060_rdma-shared-dev-plugin-ds.yaml index 8f73d0cb..29fae426 100644 --- a/manifests/state-rdma-device-plugin/0060_rdma-shared-dev-plugin-ds.yaml +++ b/manifests/state-rdma-device-plugin/0060_rdma-shared-dev-plugin-ds.yaml @@ -78,6 +78,17 @@ spec: - name: host-config-volume mountPath: /host/etc/pcidp/ {{- end }} + {{- with index .RuntimeSpec.ContainerResources "rdma-shared-dp" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 12}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 12}} + {{- end }} + {{- end }} volumes: - name: device-plugin hostPath: diff --git a/manifests/state-sriov-device-plugin/0030-sriov-dp-daemonset.yml b/manifests/state-sriov-device-plugin/0030-sriov-dp-daemonset.yml index 62058cf2..4162e235 100644 --- a/manifests/state-sriov-device-plugin/0030-sriov-dp-daemonset.yml +++ b/manifests/state-sriov-device-plugin/0030-sriov-dp-daemonset.yml @@ -93,6 +93,17 @@ spec: - name: host-config-volume mountPath: /host/etc/pcidp/ {{- end}} + {{- with index .RuntimeSpec.ContainerResources "kube-sriovdp" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 12}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 12}} + {{- end }} + {{- end }} volumes: - name: devicesock hostPath: diff --git a/manifests/state-whereabouts-cni/0050-whereabouts-ds.yaml b/manifests/state-whereabouts-cni/0050-whereabouts-ds.yaml index cf9e6adb..4dbe3ad1 100644 --- a/manifests/state-whereabouts-cni/0050-whereabouts-ds.yaml +++ b/manifests/state-whereabouts-cni/0050-whereabouts-ds.yaml @@ -60,6 +60,17 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + {{- with index .RuntimeSpec.ContainerResources "whereabouts" }} + resources: + {{- if .Requests }} + requests: + {{ .Requests | yaml | nindent 12}} + {{- end }} + {{- if .Limits }} + limits: + {{ .Limits | yaml | nindent 12}} + {{- end }} + {{- else }} resources: requests: cpu: "100m" @@ -67,6 +78,7 @@ spec: limits: cpu: "100m" memory: "200Mi" + {{- end }} securityContext: privileged: true volumeMounts: diff --git a/pkg/state/container_resources.go b/pkg/state/container_resources.go new file mode 100644 index 00000000..9451dfbe --- /dev/null +++ b/pkg/state/container_resources.go @@ -0,0 +1,30 @@ +/* +2023 NVIDIA CORPORATION & AFFILIATES + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package state + +import "github.com/Mellanox/network-operator/api/v1alpha1" + +type ContainerResourcesMap map[string]v1alpha1.ResourceRequirements + +func createContainerResourcesMap(resources []v1alpha1.ResourceRequirements) ContainerResourcesMap { + containerResources := ContainerResourcesMap{} + for _, val := range resources { + containerResources[val.Name] = val + } + + return containerResources +} diff --git a/pkg/state/state_cni_plugins.go b/pkg/state/state_cni_plugins.go index c01ceccb..172957db 100644 --- a/pkg/state/state_cni_plugins.go +++ b/pkg/state/state_cni_plugins.go @@ -131,6 +131,7 @@ func (s *stateCNIPlugins) GetWatchSources() map[string]client.Object { return wr } +//nolint:dupl func (s *stateCNIPlugins) getManifestObjects( cr *mellanoxv1alpha1.NicClusterPolicy, staticConfig staticconfig.Provider, reqLogger logr.Logger) ([]*unstructured.Unstructured, error) { @@ -139,8 +140,9 @@ func (s *stateCNIPlugins) getManifestObjects( Tolerations: cr.Spec.Tolerations, NodeAffinity: cr.Spec.NodeAffinity, RuntimeSpec: &cniRuntimeSpec{ - runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, - CniBinDirectory: utils.GetCniBinDirectory(staticConfig, nil), + runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, + CniBinDirectory: utils.GetCniBinDirectory(staticConfig, nil), + ContainerResources: createContainerResourcesMap(cr.Spec.SecondaryNetwork.CniPlugins.ContainerResources), }, } // render objects diff --git a/pkg/state/state_ib_kubernetes.go b/pkg/state/state_ib_kubernetes.go index d7887041..28159d7f 100644 --- a/pkg/state/state_ib_kubernetes.go +++ b/pkg/state/state_ib_kubernetes.go @@ -60,7 +60,8 @@ type stateIBKubernetes struct { type IBKubernetesSpec struct { runtimeSpec // is true if cluster type is Openshift - IsOpenshift bool + IsOpenshift bool + ContainerResources ContainerResourcesMap } type IBKubernetesManifestRenderData struct { CrSpec *mellanoxv1alpha1.IBKubernetesSpec @@ -143,8 +144,9 @@ func (s *stateIBKubernetes) getManifestObjects( NodeAffinity: cr.Spec.NodeAffinity, DeployInitContainer: cr.Spec.OFEDDriver != nil, RuntimeSpec: &IBKubernetesSpec{ - runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, - IsOpenshift: clusterInfo.IsOpenshift(), + runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, + IsOpenshift: clusterInfo.IsOpenshift(), + ContainerResources: createContainerResourcesMap(cr.Spec.IBKubernetes.ContainerResources), }, } // render objects diff --git a/pkg/state/state_ib_kubernetes_test.go b/pkg/state/state_ib_kubernetes_test.go index 6faaa0b0..ccdbe7ce 100644 --- a/pkg/state/state_ib_kubernetes_test.go +++ b/pkg/state/state_ib_kubernetes_test.go @@ -19,6 +19,8 @@ package state import ( "strconv" + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/runtime" . "github.com/onsi/ginkgo/v2" @@ -95,5 +97,140 @@ var _ = Describe("IB Kubernetes state rendering tests", func() { } } }) + It("Should Render ContainerResources", func() { + manifestBaseDir := "../../manifests/state-ib-kubernetes" + + files, err := utils.GetFilesWithSuffix(manifestBaseDir, render.ManifestFileSuffix...) + Expect(err).NotTo(HaveOccurred()) + renderer := render.NewRenderer(files) + + ibKubernetesState := stateIBKubernetes{ + stateSkel: stateSkel{ + renderer: renderer, + }, + } + + Expect(err).NotTo(HaveOccurred()) + + quantity, _ := resource.ParseQuantity("150Mi") + ibKubernetesSpec := &mellanoxv1alpha1.IBKubernetesSpec{} + ibKubernetesSpec.ContainerResources = []mellanoxv1alpha1.ResourceRequirements{{ + Name: "ib-kubernetes", + Requests: v1.ResourceList{ + "cpu": quantity, + }, + Limits: v1.ResourceList{ + "cpu": quantity, + }, + }} + ibKubernetesSpec.Image = "image" + ibKubernetesSpec.ImagePullSecrets = []string{} + ibKubernetesSpec.Version = "version" + cr := &mellanoxv1alpha1.NicClusterPolicy{} + cr.Spec.IBKubernetes = ibKubernetesSpec + + objs, err := ibKubernetesState.getManifestObjects(cr, &dummyProvider{}, testLogger) + Expect(err).NotTo(HaveOccurred()) + Expect(len(objs)).To(Equal(4)) + ds := objs[3] + spec := ds.Object["spec"].(map[string]interface{}) + template := spec["template"].(map[string]interface{}) + templateSpec := template["spec"].(map[string]interface{}) + containers := templateSpec["containers"].([]interface{}) + resources := containers[0].(map[string]interface{})["resources"].(map[string]interface{}) + requests := resources["requests"].(map[string]interface{}) + cpuRequest := requests["cpu"].(string) + Expect(cpuRequest).To(Equal(quantity.String())) + limits := resources["limits"].(map[string]interface{}) + cpuLimit := limits["cpu"].(string) + Expect(cpuLimit).To(Equal(quantity.String())) + }) + It("Should NOT Render ContainerResources with the wrong container name", func() { + manifestBaseDir := "../../manifests/state-ib-kubernetes" + + files, err := utils.GetFilesWithSuffix(manifestBaseDir, render.ManifestFileSuffix...) + Expect(err).NotTo(HaveOccurred()) + renderer := render.NewRenderer(files) + + ibKubernetesState := stateIBKubernetes{ + stateSkel: stateSkel{ + renderer: renderer, + }, + } + + Expect(err).NotTo(HaveOccurred()) + + quantity, _ := resource.ParseQuantity("150Mi") + ibKubernetesSpec := &mellanoxv1alpha1.IBKubernetesSpec{} + ibKubernetesSpec.ContainerResources = []mellanoxv1alpha1.ResourceRequirements{{ + Name: "ib-kubernetes-wrong", + Requests: v1.ResourceList{ + "cpu": quantity, + }, + Limits: v1.ResourceList{ + "cpu": quantity, + }, + }} + ibKubernetesSpec.Image = "image" + ibKubernetesSpec.ImagePullSecrets = []string{} + ibKubernetesSpec.Version = "version" + cr := &mellanoxv1alpha1.NicClusterPolicy{} + cr.Spec.IBKubernetes = ibKubernetesSpec + + objs, err := ibKubernetesState.getManifestObjects(cr, &dummyProvider{}, testLogger) + Expect(err).NotTo(HaveOccurred()) + Expect(len(objs)).To(Equal(4)) + ds := objs[3] + spec := ds.Object["spec"].(map[string]interface{}) + template := spec["template"].(map[string]interface{}) + templateSpec := template["spec"].(map[string]interface{}) + containers := templateSpec["containers"].([]interface{}) + resources := containers[0].(map[string]interface{})["resources"] + Expect(resources).To(BeNil()) + }) + It("Should not render limits if nil", func() { + manifestBaseDir := "../../manifests/state-ib-kubernetes" + + files, err := utils.GetFilesWithSuffix(manifestBaseDir, render.ManifestFileSuffix...) + Expect(err).NotTo(HaveOccurred()) + renderer := render.NewRenderer(files) + + ibKubernetesState := stateIBKubernetes{ + stateSkel: stateSkel{ + renderer: renderer, + }, + } + + Expect(err).NotTo(HaveOccurred()) + + quantity, _ := resource.ParseQuantity("150Mi") + ibKubernetesSpec := &mellanoxv1alpha1.IBKubernetesSpec{} + ibKubernetesSpec.ContainerResources = []mellanoxv1alpha1.ResourceRequirements{{ + Name: "ib-kubernetes", + Requests: v1.ResourceList{ + "cpu": quantity, + }, + }} + ibKubernetesSpec.Image = "image" + ibKubernetesSpec.ImagePullSecrets = []string{} + ibKubernetesSpec.Version = "version" + cr := &mellanoxv1alpha1.NicClusterPolicy{} + cr.Spec.IBKubernetes = ibKubernetesSpec + + objs, err := ibKubernetesState.getManifestObjects(cr, &dummyProvider{}, testLogger) + Expect(err).NotTo(HaveOccurred()) + Expect(len(objs)).To(Equal(4)) + ds := objs[3] + spec := ds.Object["spec"].(map[string]interface{}) + template := spec["template"].(map[string]interface{}) + templateSpec := template["spec"].(map[string]interface{}) + containers := templateSpec["containers"].([]interface{}) + resources := containers[0].(map[string]interface{})["resources"].(map[string]interface{}) + requests := resources["requests"].(map[string]interface{}) + cpuRequest := requests["cpu"].(string) + Expect(cpuRequest).To(Equal(quantity.String())) + limits := resources["limits"] + Expect(limits).To(BeNil()) + }) }) }) diff --git a/pkg/state/state_ipoib_cni.go b/pkg/state/state_ipoib_cni.go index 70220eab..e8ce7193 100644 --- a/pkg/state/state_ipoib_cni.go +++ b/pkg/state/state_ipoib_cni.go @@ -142,9 +142,10 @@ func (s *stateIPoIBCNI) getManifestObjects( Tolerations: cr.Spec.Tolerations, NodeAffinity: cr.Spec.NodeAffinity, RuntimeSpec: &cniRuntimeSpec{ - runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, - IsOpenshift: clusterInfo.IsOpenshift(), - CniBinDirectory: utils.GetCniBinDirectory(staticConfig, clusterInfo), + runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, + IsOpenshift: clusterInfo.IsOpenshift(), + CniBinDirectory: utils.GetCniBinDirectory(staticConfig, clusterInfo), + ContainerResources: createContainerResourcesMap(cr.Spec.SecondaryNetwork.IPoIB.ContainerResources), }, } diff --git a/pkg/state/state_multus_cni.go b/pkg/state/state_multus_cni.go index 138950e0..371aebe1 100644 --- a/pkg/state/state_multus_cni.go +++ b/pkg/state/state_multus_cni.go @@ -129,6 +129,7 @@ func (s *stateMultusCNI) GetWatchSources() map[string]client.Object { return wr } +//nolint:dupl func (s *stateMultusCNI) getManifestObjects( cr *mellanoxv1alpha1.NicClusterPolicy, staticConfig staticconfig.Provider, reqLogger logr.Logger) ([]*unstructured.Unstructured, error) { @@ -137,8 +138,9 @@ func (s *stateMultusCNI) getManifestObjects( Tolerations: cr.Spec.Tolerations, NodeAffinity: cr.Spec.NodeAffinity, RuntimeSpec: &cniRuntimeSpec{ - runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, - CniBinDirectory: utils.GetCniBinDirectory(staticConfig, nil), + runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, + CniBinDirectory: utils.GetCniBinDirectory(staticConfig, nil), + ContainerResources: createContainerResourcesMap(cr.Spec.SecondaryNetwork.Multus.ContainerResources), }, } diff --git a/pkg/state/state_nic_feature_discovery.go b/pkg/state/state_nic_feature_discovery.go index 70e8afb6..fa562e0f 100644 --- a/pkg/state/state_nic_feature_discovery.go +++ b/pkg/state/state_nic_feature_discovery.go @@ -71,7 +71,8 @@ type nfdManifestRenderData struct { type nfdRuntimeSpec struct { runtimeSpec // is true if cluster type is Openshift - IsOpenshift bool + IsOpenshift bool + ContainerResources ContainerResourcesMap } // Sync attempt to get the system to match the desired state which State represent. @@ -145,8 +146,9 @@ func (s *stateNICFeatureDiscovery) getManifestObjects( NodeAffinity: cr.Spec.NodeAffinity, Tolerations: cr.Spec.Tolerations, RuntimeSpec: &nfdRuntimeSpec{ - runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, - IsOpenshift: clusterInfo.IsOpenshift(), + runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, + IsOpenshift: clusterInfo.IsOpenshift(), + ContainerResources: createContainerResourcesMap(cr.Spec.NicFeatureDiscovery.ContainerResources), }, } diff --git a/pkg/state/state_nv_ipam_cni.go b/pkg/state/state_nv_ipam_cni.go index f58db09b..dc7bd8d4 100644 --- a/pkg/state/state_nv_ipam_cni.go +++ b/pkg/state/state_nv_ipam_cni.go @@ -147,9 +147,10 @@ func (s *stateNVIPAMCNI) getManifestObjects( NodeAffinity: cr.Spec.NodeAffinity, Tolerations: cr.Spec.Tolerations, RuntimeSpec: &cniRuntimeSpec{ - runtimeSpec: runtimeSpec{Namespace: config.FromEnv().State.NetworkOperatorResourceNamespace}, - IsOpenshift: clusterInfo.IsOpenshift(), - CniBinDirectory: utils.GetCniBinDirectory(staticConfig, clusterInfo), + runtimeSpec: runtimeSpec{Namespace: config.FromEnv().State.NetworkOperatorResourceNamespace}, + IsOpenshift: clusterInfo.IsOpenshift(), + CniBinDirectory: utils.GetCniBinDirectory(staticConfig, clusterInfo), + ContainerResources: createContainerResourcesMap(cr.Spec.NvIpam.ContainerResources), }, } diff --git a/pkg/state/state_ofed.go b/pkg/state/state_ofed.go index 4a2dd440..dbbccdc9 100644 --- a/pkg/state/state_ofed.go +++ b/pkg/state/state_ofed.go @@ -153,7 +153,8 @@ type ofedRuntimeSpec struct { MOFEDImageName string InitContainerConfig initContainerConfig // is true if cluster type is Openshift - IsOpenshift bool + IsOpenshift bool + ContainerResources ContainerResourcesMap } type ofedManifestRenderData struct { @@ -426,7 +427,8 @@ func (s *stateOFED) getManifestObjects( MOFEDImageName: s.getMofedDriverImageName(cr, nodeAttr, reqLogger), InitContainerConfig: s.getInitContainerConfig(cr, reqLogger, config.FromEnv().State.OFEDState.InitContainerImage), - IsOpenshift: clusterInfo.IsOpenshift(), + IsOpenshift: clusterInfo.IsOpenshift(), + ContainerResources: createContainerResourcesMap(cr.Spec.OFEDDriver.ContainerResources), }, Tolerations: cr.Spec.Tolerations, NodeAffinity: cr.Spec.NodeAffinity, diff --git a/pkg/state/state_shared_dp.go b/pkg/state/state_shared_dp.go index ca66a9c5..617577e0 100644 --- a/pkg/state/state_shared_dp.go +++ b/pkg/state/state_shared_dp.go @@ -62,7 +62,8 @@ type stateSharedDp struct { type sharedDpRuntimeSpec struct { runtimeSpec // is true if cluster type is Openshift - IsOpenshift bool + IsOpenshift bool + ContainerResources ContainerResourcesMap } type sharedDpManifestRenderData struct { CrSpec *mellanoxv1alpha1.DevicePluginSpec @@ -146,8 +147,9 @@ func (s *stateSharedDp) getManifestObjects( NodeAffinity: cr.Spec.NodeAffinity, DeployInitContainer: cr.Spec.OFEDDriver != nil, RuntimeSpec: &sharedDpRuntimeSpec{ - runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, - IsOpenshift: clusterInfo.IsOpenshift(), + runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, + IsOpenshift: clusterInfo.IsOpenshift(), + ContainerResources: createContainerResourcesMap(cr.Spec.RdmaSharedDevicePlugin.ContainerResources), }, } // render objects diff --git a/pkg/state/state_skel.go b/pkg/state/state_skel.go index b943e42b..899b6439 100644 --- a/pkg/state/state_skel.go +++ b/pkg/state/state_skel.go @@ -45,8 +45,9 @@ type runtimeSpec struct { type cniRuntimeSpec struct { runtimeSpec - CniBinDirectory string - IsOpenshift bool + CniBinDirectory string + IsOpenshift bool + ContainerResources ContainerResourcesMap } // a state skeleton intended to be embedded in structs implementing the State interface diff --git a/pkg/state/state_sriov_dp.go b/pkg/state/state_sriov_dp.go index 27835720..4e45fc16 100644 --- a/pkg/state/state_sriov_dp.go +++ b/pkg/state/state_sriov_dp.go @@ -63,7 +63,8 @@ type sriovDpRuntimeSpec struct { runtimeSpec CPUArch string // is true if cluster type is Openshift - IsOpenshift bool + IsOpenshift bool + ContainerResources ContainerResourcesMap } type sriovDpManifestRenderData struct { @@ -148,8 +149,9 @@ func (s *stateSriovDp) getManifestObjects( NodeAffinity: cr.Spec.NodeAffinity, DeployInitContainer: cr.Spec.OFEDDriver != nil, RuntimeSpec: &sriovDpRuntimeSpec{ - runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, - IsOpenshift: clusterInfo.IsOpenshift(), + runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, + IsOpenshift: clusterInfo.IsOpenshift(), + ContainerResources: createContainerResourcesMap(cr.Spec.SriovDevicePlugin.ContainerResources), }, } // render objects diff --git a/pkg/state/state_whereabouts_cni.go b/pkg/state/state_whereabouts_cni.go index 73d48521..54c611cf 100644 --- a/pkg/state/state_whereabouts_cni.go +++ b/pkg/state/state_whereabouts_cni.go @@ -128,6 +128,7 @@ func (s *stateWhereaboutsCNI) GetWatchSources() map[string]client.Object { return wr } +//nolint:dupl func (s *stateWhereaboutsCNI) getManifestObjects( cr *mellanoxv1alpha1.NicClusterPolicy, staticConfig staticconfig.Provider, reqLogger logr.Logger) ([]*unstructured.Unstructured, error) { @@ -136,8 +137,9 @@ func (s *stateWhereaboutsCNI) getManifestObjects( Tolerations: cr.Spec.Tolerations, NodeAffinity: cr.Spec.NodeAffinity, RuntimeSpec: &cniRuntimeSpec{ - runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, - CniBinDirectory: utils.GetCniBinDirectory(staticConfig, nil), + runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace}, + CniBinDirectory: utils.GetCniBinDirectory(staticConfig, nil), + ContainerResources: createContainerResourcesMap(cr.Spec.SecondaryNetwork.IpamPlugin.ContainerResources), }, } // render objects