Skip to content

Commit

Permalink
Propagate resource requirements to the states
Browse files Browse the repository at this point in the history
Signed-off-by: amaslennikov <[email protected]>
  • Loading branch information
almaslennikov committed Dec 20, 2023
1 parent e7e7f5f commit bd43ffb
Show file tree
Hide file tree
Showing 24 changed files with 345 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,25 @@ 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"
memory: "50Mi"
limits:
cpu: "100m"
memory: "50Mi"
{{- end }}
volumeMounts:
- name: cnibin
mountPath: /host/opt/cni/bin
Expand Down
12 changes: 12 additions & 0 deletions manifests/state-ib-kubernetes/0070-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions manifests/state-ipoib-cni/0050-ipoib-cni-ds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,25 @@ 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"
memory: "50Mi"
limits:
cpu: "100m"
memory: "50Mi"
{{- end }}
securityContext:
privileged: true
volumeMounts:
Expand Down
12 changes: 12 additions & 0 deletions manifests/state-multus-cni/0050-multus-ds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,25 @@ 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"
memory: "50Mi"
limits:
cpu: "100m"
memory: "50Mi"
{{- end }}
securityContext:
privileged: true
volumeMounts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,25 @@ 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"
memory: "50Mi"
limits:
cpu: "300m"
memory: "150Mi"
{{- end }}
securityContext:
privileged: true
volumeMounts:
Expand Down
16 changes: 14 additions & 2 deletions manifests/state-nv-ipam-cni/040-nv-ipam-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions manifests/state-nv-ipam-cni/040-nv-ipam-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,25 @@ 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"
memory: "50Mi"
limits:
cpu: "300m"
memory: "300Mi"
{{- end }}
securityContext:
privileged: true
volumeMounts:
Expand Down
11 changes: 11 additions & 0 deletions manifests/state-ofed-driver/0050_ofed-driver-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions manifests/state-sriov-device-plugin/0030-sriov-dp-daemonset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions manifests/state-whereabouts-cni/0050-whereabouts-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,25 @@ 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"
memory: "100Mi"
limits:
cpu: "100m"
memory: "200Mi"
{{- end }}
securityContext:
privileged: true
volumeMounts:
Expand Down
30 changes: 30 additions & 0 deletions pkg/state/container_resources.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 4 additions & 2 deletions pkg/state/state_cni_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions pkg/state/state_ib_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit bd43ffb

Please sign in to comment.