Skip to content

Commit 45ebc7c

Browse files
committed
Account for all offloaded pod network VFs
Request one VF for each attached secondary network and account for the cluster default and primary UDN legs when pods share offloaded networks. Use the calculated quantity for SR-IOV and secondary-network pod resources, and annotate generated NADs with the device resource name. Signed-off-by: Venkat Kunaparaju <vkunaparaju@nvidia.com>
1 parent 38d0d23 commit 45ebc7c

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

manifests/pod-secondary-network.yaml.j2

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ spec:
2121
image: {{ test_image }}
2222
command: {{ command }}
2323
args: {{ args }}
24-
imagePullPolicy: {{ image_pull_policy }}{% if has_resources %}
24+
imagePullPolicy: {{ image_pull_policy }}{% if has_resource_name or has_resources %}
2525
resources:
26-
requests: {% if cpu_request %}
26+
requests: {% if has_resource_name %}
27+
{{ resource_name }}: {{ sriov_resource_quantity }}{% endif %}{% if cpu_request %}
2728
cpu: {{ cpu_request }}{% endif %}{% if mem_request %}
2829
memory: {{ mem_request }}{% endif %}
29-
limits: {% if cpu_limit %}
30+
limits: {% if has_resource_name %}
31+
{{ resource_name }}: {{ sriov_resource_quantity }}{% endif %}{% if cpu_limit %}
3032
cpu: {{ cpu_limit }}{% endif %}{% if mem_limit %}
3133
memory: {{ mem_limit }}{% endif %}{% endif %}
3234
securityContext:

manifests/secondary-nad.yaml.j2

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ apiVersion: "k8s.cni.cncf.io/v1"
22
kind: NetworkAttachmentDefinition
33
metadata:
44
name: {{ nad_name }}
5-
namespace: {{ name_space }}
5+
namespace: {{ name_space }}{% if has_resource_name %}
6+
annotations:
7+
k8s.v1.cni.cncf.io/resourceName: {{ resource_name }}{% endif %}
68
labels:
79
tft-tests: "secondary-nad"
810
spec:
@@ -13,8 +15,7 @@ spec:
1315
"Role": "secondary",
1416
"topology": {{ topology }},
1517
"subnets": {{ subnets }},
16-
"mtu": {{ mtu }},{% if has_resource_name %}
17-
"resourceName": {{ resource_name }},{% endif %}
18+
"mtu": {{ mtu }},
1819
"type": "ovn-k8s-cni-overlay",
1920
"logFile": "/var/log/ovn-kubernetes/flowtest.log",
2021
"logLevel": "5",

manifests/sriov-pod.yaml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ spec:
2525
imagePullPolicy: {{ image_pull_policy }}{% if has_resource_name or has_resources %}
2626
resources:
2727
requests: {% if has_resource_name %}
28-
{{ resource_name }}: '1'{% endif %}{% if cpu_request %}
28+
{{ resource_name }}: {{ sriov_resource_quantity }}{% endif %}{% if cpu_request %}
2929
cpu: {{ cpu_request }}{% endif %}{% if mem_request %}
3030
memory: {{ mem_request }}{% endif %}
3131
limits: {% if has_resource_name %}
32-
{{ resource_name }}: '1'{% endif %}{% if cpu_limit %}
32+
{{ resource_name }}: {{ sriov_resource_quantity }}{% endif %}{% if cpu_limit %}
3333
cpu: {{ cpu_limit }}{% endif %}{% if mem_limit %}
3434
memory: {{ mem_limit }}{% endif %}{% endif %}
3535
securityContext:

task.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,22 @@ def _get_pod_secondary_network_nads(self) -> tuple[str, ...]:
447447
return (self._get_effective_secondary_network_nad(),)
448448
return ()
449449

450+
def _get_sriov_resource_quantity(
451+
self,
452+
secondary_network_nads: tuple[str, ...],
453+
) -> str:
454+
if self.pod_type == PodType.SRIOV:
455+
return str(1 + int(self.ts.test_case_id.is_udn_primary))
456+
needs_primary_udn_vf = self.ts.test_case_id.is_udn_secondary and any(
457+
test_case.is_udn_primary
458+
for test_case in self.ts.cfg_descr.get_tft().test_cases
459+
)
460+
return str(
461+
len(secondary_network_nads)
462+
+ int(self.node.sriov)
463+
+ int(needs_primary_udn_vf)
464+
)
465+
450466
def get_template_args(self) -> dict[str, str | list[str] | bool]:
451467
resource_name = self.get_resource_name()
452468
conn = self.ts.connection
@@ -482,6 +498,9 @@ def get_template_args(self) -> dict[str, str | list[str] | bool]:
482498
),
483499
"has_resource_name": bool(resource_name),
484500
"resource_name": _j(resource_name),
501+
"sriov_resource_quantity": _j(
502+
self._get_sriov_resource_quantity(pod_secondary_network_nads)
503+
),
485504
"default_network": _j(self.node.default_network),
486505
"has_resources": has_resources,
487506
"cpu_request": conn.cpu_request or "",

0 commit comments

Comments
 (0)