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

Fix regex match for getting primary interface #1311

Merged
merged 1 commit into from
Dec 9, 2020

Conversation

jayanthvn
Copy link
Contributor

@jayanthvn jayanthvn commented Dec 7, 2020

What type of PR is this?
bug

Which issue does this PR fix:
#1247 #1266

What does this PR do / Why do we need it:
Fixing the current regex match to pick primary interface from primary MAC which is more reliable.

If an issue # is not available please add repro steps and logs from IPAMD/CNI showing the issue:

Testing done on this change:

[root@ip-192-168-85-147 ec2-user]# PRIMARY_MAC=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/mac)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    17  100    17    0     0  17000      0 --:--:-- --:--:-- --:--:-- 17000
[root@ip-192-168-85-147 ec2-user]# PRIMARY_IF=$(ip -o link show | grep -F "link/ether $PRIMARY_MAC" | awk -F'[ :]+' '{print $2}')
[root@ip-192-168-85-147 ec2-user]# echo $PRIMARY_IF
eth0
kubectl logs aws-node-88hvw -c aws-vpc-cni-init -n kube-system
+ PLUGIN_BINS='loopback portmap bandwidth aws-cni-support.sh'
+ for b in '$PLUGIN_BINS'
+ '[' '!' -f loopback ']'
+ for b in '$PLUGIN_BINS'
+ '[' '!' -f portmap ']'
+ for b in '$PLUGIN_BINS'
+ '[' '!' -f bandwidth ']'
+ for b in '$PLUGIN_BINS'
+ '[' '!' -f aws-cni-support.sh ']'
+ HOST_CNI_BIN_PATH=/host/opt/cni/bin
+ echo 'Copying CNI plugin binaries ... '
+ for b in '$PLUGIN_BINS'
+ install loopback /host/opt/cni/bin
Copying CNI plugin binaries ...
+ for b in '$PLUGIN_BINS'
+ install portmap /host/opt/cni/bin
+ for b in '$PLUGIN_BINS'
+ install bandwidth /host/opt/cni/bin
+ for b in '$PLUGIN_BINS'
+ install aws-cni-support.sh /host/opt/cni/bin
Configure rp_filter loose...
+ echo 'Configure rp_filter loose... '
++ get_metadata local-ipv4
+++ curl -X PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds: 60'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    56  100    56    0     0  56000      0 --:--:-- --:--:-- --:--:-- 56000
++ TOKEN=AQAEAHGXwoPHd-WatjsIZZX_51JLMhk73OKTbNWO-XDkiMwHgJ9UWw==
++ attempts=60
++ false
++ '[' 1 -gt 0 ']'
++ '[' 60 -eq 0 ']'
+++ curl -H 'X-aws-ec2-metadata-token: AQAEAHGXwoPHd-WatjsIZZX_51JLMhk73OKTbNWO-XDkiMwHgJ9UWw==' http://169.254.169.254/latest/meta-data/local-ipv4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    14  100    14    0     0  14000      0 --:--:-- --:--:-- --:--:-- 14000
++ meta=192.168.22.192
++ '[' 0 -gt 0 ']'
++ '[' 0 -gt 0 ']'
++ echo 192.168.22.192
+ HOST_IP=192.168.22.192
++ get_metadata mac
+++ curl -X PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds: 60'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    56  100    56    0     0  56000      0 --:--:-- --:--:-- --:--:-- 56000
++ TOKEN=AQAEAHGXwoP4xDK_8AY9PNKkOPBEwr-WQmbR2pDhyWKCpbR1Lqvmuw==
++ attempts=60
++ false
++ '[' 1 -gt 0 ']'
++ '[' 60 -eq 0 ']'
+++ curl -H 'X-aws-ec2-metadata-token: AQAEAHGXwoP4xDK_8AY9PNKkOPBEwr-WQmbR2pDhyWKCpbR1Lqvmuw==' http://169.254.169.254/latest/meta-data/mac
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    17  100    17    0     0  17000      0 --:--:-- --:--:-- --:--:-- 17000
++ meta=0a:2d:8e:94:14:75
++ '[' 0 -gt 0 ']'
++ '[' 0 -gt 0 ']'
++ echo 0a:2d:8e:94:14:75
+ PRIMARY_MAC=0a:2d:8e:94:14:75
++ ip -o link show
++ grep -F 'link/ether 0a:2d:8e:94:14:75'
++ awk '-F[ :]+' '{print $2}'
+ PRIMARY_IF=eth0
+ sysctl -w net.ipv4.conf.eth0.rp_filter=2
net.ipv4.conf.eth0.rp_filter = 2
+ cat /proc/sys/net/ipv4/conf/eth0/rp_filter
2
+ '[' true == true ']'
+ sysctl -w net.ipv4.tcp_early_demux=0
net.ipv4.tcp_early_demux = 0
+ echo 'CNI init container done'
CNI init container done

Automation added to e2e:

No

Will this break upgrades or downgrades. Has updating a running cluster been tested?:
No

Does this change require updates to the CNI daemonset config files to work?:

No

Does this PR introduce any user-facing change?:

No


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

scripts/init.sh Outdated Show resolved Hide resolved
@jayanthvn jayanthvn force-pushed the pri_ip branch 2 times, most recently from 4b4dd02 to 157d356 Compare December 8, 2020 21:07
Copy link
Contributor

@nithu0115 nithu0115 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

scripts/init.sh Outdated Show resolved Hide resolved
Added retry for sync issues

move TOKEN inside get_metadata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants