Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 'mac' to specify MAC address for interface #148

Merged
merged 9 commits into from
Nov 8, 2018
Merged

Conversation

s1061123
Copy link
Member

@s1061123 s1061123 commented Sep 6, 2018

This change supports mac to specify MAC address for interface. This feature interworks with the latest 'tuning' CNI plugin of CNCF repo (https://github.com/containernetworking/plugins) and change MAC address.

@coveralls
Copy link

coveralls commented Sep 6, 2018

Pull Request Test Coverage Report for Build 474

  • 16 of 29 (55.17%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 48.6%

Changes Missing Coverage Covered Lines Changed/Added Lines %
multus/multus.go 6 10 60.0%
types/conf.go 6 15 40.0%
Files with Coverage Reduction New Missed Lines %
types/conf.go 1 28.41%
Totals Coverage Status
Change from base Build 471: 0.2%
Covered Lines: 486
Relevant Lines: 1000

💛 - Coveralls

README.md Outdated Show resolved Hide resolved
@s1061123
Copy link
Member Author

@rkamudhan @dougbtv Fixed conflicts.

@manndavidj
Copy link

manndavidj commented Nov 7, 2018

I pulled this feature branch and have been testing it in an Openshift environment using the Ansible playbook provided by @dougbtv . I put my network annotations with the "interfaceRequest" and "macRequest" fields in and the interface name reflected my chosen "mgmt". However, the MAC assignment doesn't seem to be working. Here's my network definition:

apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: macvlan-conf-vio
spec: 
  config: '{
      "cniVersion": "0.3.0",
      "plugins": [ {
        "type": "macvlan",
        "master": "eno1",
        "mode": "bridge",
        "ipam": {
          "type": "host-local",
          "subnet": "10.255.102.0/24",
          "rangeStart": "10.255.102.110",
          "rangeEnd": "10.255.102.125",
          "routes": [
            { "dst": "0.0.0.0/0" }
          ],
          "gateway": "10.255.102.1"
        }
      },
      {
        "type":"tuning"
      }]
    }'

And my pod definition which uses it:

apiVersion: v1
kind: Pod
metadata:
  name: samplepod-vio
  annotations:
    k8s.v1.cni.cncf.io/networks: '[
      { "name": "macvlan-conf-vio",
        "interfaceRequest": "mgmt",
        "macRequest": "aa:bb:cc:dd:ee:ff"
      }
    ]'
spec:
  containers:
  - name: samplepod
    command: ["/bin/bash", "-c", "sleep 2000000000000"]
    image: dougbtv/centos-network

I captured the following logs and it looks like there may be some annotation parsing in that's missing for the "MacRequest". In k8sclient/k8sclient.go:parsePodNetworkAnnotation() it appears to only capture the network name, network namespace and interface request fields. See the logs below that show my "macRequest" annotation that is noted but not captured when performing the final interface configuration.

2018-11-06T13:21:01-05:00 [debug] TryLoadK8sDelegates: &{{true} <nil> samplepod-vio default e73345d706dd0a623beffe2c0c084c640d6b5a953fd592442963ef5a96da3828}, &{{ multus-cni-network multus map[] {} {[]  [] []}} <nil> <nil> /etc/cni/multus/net.d /var/lib/cni/multus /opt/cni/bin [] [0xc4202be5a0] [] /etc/cni/net.d/multus.d/multus.kubeconfig   <nil> }, <nil>snode-1.mydomain.com,HostNetwork:false,HostPID:false,HostIPC:false,SecurityContext:&PodSecurityContext{SELinuxOptions:&SELinuxOptions{User:,Role:,Type:,Level:s0:c1,c0,},RunAsUser:nil,RunAsNonRoot:nil,SupplementalGroups:[],FSGroup:nil,RunAsGroup:nil,Sysctls:[],},ImagePullSecr2018-11-06T13:21:01-05:00 [debug] GetK8sClient: /etc/cni/net.d/multus.d/multus.kubeconfig, <nil>r,InitContainers:[],AutomountServiceAccountToken:nil,Tolerations:[],HostAliases:[],PriorityClassName:,Priority:nil,DNSConfig:nil,ShareProcessNamespace:nil,ReadinessGates:[],},Status:PodStatus{Phase:Pending,Conditions:[{I2018-11-06T13:21:01-05:00 [debug] setKubeClientInfo: &{<nil>  }, &{0xc4202dc690}, &{{true} <nil> samplepod-vio default e73345d706dd0a623beffe2c0c084c640d6b5a953fd592442963ef5a96da3828}th unready status: [samplepod]} {PodScheduled True 0001-01-01 00:00:00 +0000 UTC 2018-11-06 13:10:10 -0500 EST  }],Message:,Reason:,2018-11-06T13:21:01-05:00 [debug] GetK8sNetwork: &{0xc4202dc690}, &{{true} <nil> samplepod-vio default e73345d706dd0a623beffe2c0c084c640d6b5a953fd592442963ef5a96da3828}, /etc/cni/multus/net.dgbtv/centos-network  }],QOSClass:BestEffort,InitContainerStatuses:[],NominatedNodeName:,},}, [{
2018-11-06T13:21:01-05:00 [debug] getPodNetworkAnnotation: &{0xc4202dc690}, &{{true} <nil> samplepod-vio default e73345d706dd0a623beffe2c0c084c640d6b5a953fd592442963ef5a96da3828}
2018-11-06T13:21:01-05:00 [debug] parsePodNetworkAnnotation: [ { "name": "macvlan-conf-vio", "interfaceRequest": "mgmt", "macRequest": "aa:bb:cc:dd:ee:ff" } ], default
2018-11-06T13:21:01-05:00 [debug] getKubernetesDelegate: &{0xc4202dc690}, &{macvlan-conf-vio default   mgmt}, /etc/cni/multus/net.d
...
2018-11-06T13:10:18-05:00 [debug] setPodNetworkAnnotation: &{0xc4202e4690}, default, &Pod{ObjectMeta:k8s_io_apimachinery_pkg_apis_meta_v1.ObjectMeta{Name:samplepod-vio,GenerateName:,Namespace:default,SelfLink:/api/v1/namespaces/default/pods/samplepod-vio,UID:32e4f7a1-e1ef-11e8-bcc4-fa163ee0837f,ResourceVersion:7248
64,Generation:0,CreationTimestamp:2018-11-06 13:10:10 -0500 EST,DeletionTimestamp:<nil>,DeletionGracePeriodSeconds:nil,Labels:map[string]string{},Annotations:map[string]string{k8s.v1.cni.cncf.io/networks: [ { "name": "macvlan-conf-vio", "interfaceRequest": "mgmt", "macRequest": "aa:bb:cc:dd:ee:ff" } ],openshift.io/
scc: anyuid,},OwnerReferences:[],Finalizers:[],ClusterName:,Initializers:nil,},Spec:PodSpec{Volumes:[{default-token-4q9dt {nil nil nil nil nil SecretVolumeSource{SecretName:default-token-4q9dt,Items:[],DefaultMode:*420,Optional:nil,} nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil ni
l}}],Containers:[{samplepod dougbtv/centos-network [/bin/bash -c sleep 2000000000000] []  [] [] [] {map[] map[]} [{default-token-4q9dt true /var/run/secrets/kubernetes.io/serviceaccount  <nil>}] [] nil nil nil /dev/termination-log File Always SecurityContext{Capabilities:&Capabilities{Add:[],Drop:[MKNOD],},Privileg
ed:nil,SELinuxOptions:nil,RunAsUser:nil,RunAsNonRoot:nil,ReadOnlyRootFilesystem:nil,AllowPrivilegeEscalation:nil,RunAsGroup:nil,} false false false}],RestartPolicy:Always,TerminationGracePeriodSeconds:*30,ActiveDeadlineSeconds:nil,DNSPolicy:ClusterFirst,NodeSelector:map[string]string{},ServiceAccountName:default,De
precatedServiceAccount:default,NodeName:osnode-1.mydomain.com,HostNetwork:false,HostPID:false,HostIPC:false,SecurityContext:&PodSecurityContext{SELinuxOptions:&SELinuxOptions{User:,Role:,Type:,Level:s0:c1,c0,},RunAsUser:nil,RunAsNonRoot:nil,SupplementalGroups:[],FSGroup:nil,RunAsGroup:nil,Sysctls:[],},ImagePullSecr
ets:[{default-dockercfg-p6dzw}],Hostname:,Subdomain:,Affinity:nil,SchedulerName:default-scheduler,InitContainers:[],AutomountServiceAccountToken:nil,Tolerations:[],HostAliases:[],PriorityClassName:,Priority:nil,DNSConfig:nil,ShareProcessNamespace:nil,ReadinessGates:[],},Status:PodStatus{Phase:Pending,Conditions:[{I
nitialized True 0001-01-01 00:00:00 +0000 UTC 2018-11-06 13:10:10 -0500 EST  } {Ready False 0001-01-01 00:00:00 +0000 UTC 2018-11-06 13:10:10 -0500 EST ContainersNotReady containers with unready status: [samplepod]} {PodScheduled True 0001-01-01 00:00:00 +0000 UTC 2018-11-06 13:10:10 -0500 EST  }],Message:,Reason:,
HostIP:10.255.102.10,PodIP:,StartTime:2018-11-06 13:10:10 -0500 EST,ContainerStatuses:[{samplepod {ContainerStateWaiting{Reason:ContainerCreating,Message:,} nil nil} {nil nil nil} false 0 dougbtv/centos-network  }],QOSClass:BestEffort,InitContainerStatuses:[],NominatedNodeName:,},}, [{
    "name": "",
    "ips": [
        "10.130.0.102"
    ],
    "default": true,
    "dns": {}
},{
    "name": "macvlan-conf-vio",
    "interface": "mgmt",
    "ips": [
        "10.255.102.123"
    ],
    "mac": "b6:d7:ae:16:f6:e9",
    "dns": {}
}]

and then probing my pod after deployment (ignore the differing MAC, this was several iterations after that log dump. In any case it wasn't what I assigned):

[root@osmaster-1 multus-cni]# oc exec -it samplepod-vio ifconfig mgmt
mgmt: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.255.102.124  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fe80::d861:5dff:fe70:d313  prefixlen 64  scopeid 0x20<link>
        ether da:61:5d:70:d3:13  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9  bytes 690 (690.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Thanks, appreciate your work on this!

@s1061123
Copy link
Member Author

s1061123 commented Nov 8, 2018

@manndavidj , thank you for your testing!

Could you please check the following things in your lab?:

Here is my example:

# Execute following command at Kubernetes master
$ cat <<EOF | kubectl create -f -
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: macvlan-conf-3
spec:
  config: '{
            "cniVersion": "0.3.0",
            "name" : "macvlan3",
            "plugins": [ {
              "type": "macvlan",
              "master": "eth1",
              "mode": "bridge",
              "ipam": {
                  "type": "host-local",
                  "ranges": [
                      [ {
                           "subnet": "10.10.0.0/16",
                           "rangeStart": "10.10.1.20",
                           "rangeEnd": "10.10.3.50",
                           "gateway": "10.10.0.254"
                      } ]
                  ]
              }
            },
            {
              "type": "tuning"
            }]
          }'
EOF
$ cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
  name: pod-case-05
  annotations:
    k8s.v1.cni.cncf.io/networks: '[
            { "name" : "macvlan-conf-3",
              "mac": "c2:b0:57:49:47:f1" }
    ]'
spec:
  containers:
  - name: pod-case-05
    image: docker.io/centos/tools:latest
    command:
    - /sbin/init
EOF

@s1061123 s1061123 changed the title Support MacRequest to specify MAC address for interface Support 'mac' to specify MAC address for interface Nov 8, 2018
@s1061123
Copy link
Member Author

s1061123 commented Nov 8, 2018

Changed Top description and titles ("macRequest" -> "mac")

@dcbw
Copy link
Member

dcbw commented Nov 8, 2018

/lgtm

@s1061123 s1061123 merged commit 9f00ea4 into master Nov 8, 2018
@s1061123 s1061123 deleted the dev/mac branch November 8, 2018 15:15
pliurh pushed a commit to pliurh/multus-cni that referenced this pull request Sep 22, 2023
…nsistency-openshift-4.14-multus-cni

Updating multus-cni images to be consistent with ART
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants