k8snetworkplumbingwg / network-resources-injector

A Kubernetes Dynamic Admission Controller that patches Pods to add additional information.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SR-IOV network resources injector cannot parse multiple ip addresses in ipam config

vpickard opened this issue · comments

When configuring ips via pod annotation, SR-IOV injector cannot parse net-attach-def with an array of ip list, which result in SR-IOV resource request/limit not be injected in pod spec. The pod can still be created successfully, but no SR-IOV interface is attached.

  1. create sriov-net1 net-attach-def

apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: sriov-net1
annotations:
k8s.v1.cni.cncf.io/resourceName: intel.com/intel_sriov_netdevice
spec:
config: '{
"type": "sriov",
"cniVersion": "0.3.1",
"name": "sriov-network",
"ipam": {
"type": "static"
}
}'

  1. use pod spec below:

apiVersion: v1
kind: Pod
metadata:
name: pod-sriov-vf
annotations:
k8s.v1.cni.cncf.io/networks: |
[
{
"name": "sriov-net1",
"ips": ["100.100.100.100/24", "2001::2/64"]
}
]
spec:
containers:

  • name: appcntr3
    image: centos/tools
    imagePullPolicy: IfNotPresent
    command: [ "/bin/bash", "-c", "--" ]
    args: [ "while true; do sleep 300000; done;" ]
    resources:
    requests:
    memory: 100Mi
    cpu: '2'
    intel.com/intel_sriov_netdevice: '1'
    limits:
    memory: 100Mi
    cpu: '2'
    intel.com/intel_sriov_netdevice: '1'

Network resources injector logs

I1108 01:56:43.472065 1 webhook.go:332] Received mutation request
I1108 01:56:43.475727 1 webhook.go:371] network attachment definition 'default/sriov-net1' found
I1108 01:56:43.475765 1 webhook.go:377] resource 'intel.com/intel_sriov_netdevice' needs to be requested for network 'default/sriov-net1'
I1108 01:56:43.475850 1 webhook.go:422] patch after all mutations%!(EXTRA []webhook.jsonPatchOperation=[{add /spec/containers/0/resources/requests/intel.com1intel_sriov_netdevice {{1 0} {} DecimalSI}} {add /spec/containers/0/resources/limits/intel.com1intel_sriov_netdevice {{1 0} {} DecimalSI}} {add /spec/containers/0/volumeMounts/- {podnetinfo false /etc/podnetinfo }} {add /spec/volumes/- {podnetinfo {nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil &DownwardAPIVolumeSource{Items:[{labels ObjectFieldSelector{APIVersion:,FieldPath:metadata.labels,} nil } {annotations &ObjectFieldSelector{APIVersion:,FieldPath:metadata.annotations,} nil }],DefaultMode:nil,} nil nil nil nil nil nil nil nil nil nil nil nil}}}])
I1108 01:56:43.476046 1 webhook.go:257] sending response to the Kubernetes API server
I1108 01:59:45.137375 1 webhook.go:332] Received mutation request
I1108 01:59:45.138197 1 webhook.go:157] '[
{
"name": "sriov-net1",
"ips": "100.100.100.100/24"
}
]
' is not in JSON format: json: cannot unmarshal string into Go struct field NetworkSelectionElement.ips of type []string... trying to parse as comma separated network selections list
I1108 01:59:45.138347 1 webhook.go:217] at least one of the network selection units is invalid: error found at '[
{
"name": "sriov-net1"'
E1108 01:59:45.138388 1 webhook.go:163] error parsing network selection element: at least one of the network selection units is invalid: error found at '[
{
"name": "sriov-net1"'
I1108 01:59:45.138421 1 webhook.go:391] pod doesn't need any custom network resources
I1108 01:59:45.138432 1 webhook.go:257] sending response to the Kubernetes API server

#15 that resolves this issue.

[root@vpickard-k8s deployments]# kubectl exec -it pod-sriov-vf sh
sh-4.2# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: eth0@if49: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default
link/ether 8e:3d:65:1a:ee:b9 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 10.244.1.38/24 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::8c3d:65ff:fe1a:eeb9/64 scope link
valid_lft forever preferred_lft forever
18: net1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 6a:4f:b6:e9:86:9b brd ff:ff:ff:ff:ff:ff
inet 100.100.100.100/24 brd 100.100.100.255 scope global net1
valid_lft forever preferred_lft forever
inet6 2001::2/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::684f:b6ff:fee9:869b/64 scope link
valid_lft forever preferred_lft forever
sh-4.2#