Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

fix: enforce Azure CNI config via jq instead of sed #4060

Merged
merged 9 commits into from
Nov 20, 2020

Conversation

jackfrancis
Copy link
Member

@jackfrancis jackfrancis commented Nov 19, 2020

Reason for Change:

This PR reduces the bash complexity of the jq usage inside the Azure CNI setup foo so that the Azure CNI configuration is always a multi-line file to accommodate all the pre-existing (known-working) sed foo.

A future workstream would be to replace the sed foo with jq foo.

Before:

azureuser@k8s-agentpool1-40173905-vmss000001:~$ echo $(sudo cat "/etc/cni/net.d/10-azure.conflist" | jq '.plugins[0].ipv6Mode="ipv6nat"') > test.json
azureuser@k8s-agentpool1-40173905-vmss000001:~$ cat test.json 
{ "cniVersion": "0.3.0", "name": "azure", "plugins": [ { "type": "azure-vnet", "mode": "transparent", "bridge": "azure0", "ipsToRouteViaHost": [ "169.254.20.10" ], "ipam": { "type": "azure-vnet-ipam" }, "ipv6Mode": "ipv6nat" }, { "type": "portmap", "capabilities": { "portMappings": true }, "snat": true } ] }

In other words, the resultant JSON is a string with no newlines (which the sed commands aren't able to interpret).

After:

azureuser@k8s-agentpool1-40173905-vmss000001:~$ sudo jq '.plugins[0].ipv6Mode="ipv6nat"' "/etc/cni/net.d/10-azure.conflist" > test.json
azureuser@k8s-agentpool1-40173905-vmss000001:~$ cat test.json 
{
  "cniVersion": "0.3.0",
  "name": "azure",
  "plugins": [
    {
      "type": "azure-vnet",
      "mode": "transparent",
      "bridge": "azure0",
      "ipsToRouteViaHost": [
        "169.254.20.10"
      ],
      "ipam": {
        "type": "azure-vnet-ipam"
      },
      "ipv6Mode": "ipv6nat"
    },
    {
      "type": "portmap",
      "capabilities": {
        "portMappings": true
      },
      "snat": true
    }
  ]
}

This PR also rationalizes the ipv6 dual stack implementation and configuration, which requires bridge mode in order to work.

Issue Fixed:

Credit Where Due:

Does this change contain code from or inspired by another project?

  • No
  • Yes

If "Yes," did you notify that project's maintainers and provide attribution?

  • No
  • Yes

Requirements:

Notes:

@codecov
Copy link

codecov bot commented Nov 19, 2020

Codecov Report

Merging #4060 (f18149f) into master (cff0a34) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4060      +/-   ##
==========================================
+ Coverage   73.23%   73.25%   +0.02%     
==========================================
  Files         135      135              
  Lines       20640    20542      -98     
==========================================
- Hits        15115    15048      -67     
+ Misses       4549     4521      -28     
+ Partials      976      973       -3     
Impacted Files Coverage Δ
pkg/api/types.go 92.15% <ø> (-1.17%) ⬇️
pkg/engine/templates_generated.go 43.70% <ø> (ø)
pkg/api/vlabs/validate.go 81.85% <100.00%> (+0.05%) ⬆️
cmd/addpool.go 18.07% <0.00%> (-0.11%) ⬇️
pkg/api/mocks.go 100.00% <0.00%> (ø)
pkg/api/converterfromapi.go 95.66% <0.00%> (+<0.01%) ⬆️
pkg/api/defaults.go 93.42% <0.00%> (+0.01%) ⬆️
pkg/api/convertertoapi.go 94.00% <0.00%> (+0.01%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cff0a34...f18149f. Read the comment docs.

@acs-bot acs-bot added size/S and removed size/XS labels Nov 19, 2020
if [[ "${IPV6_DUALSTACK_ENABLED}" == "true" ]]; then
echo $(cat "$CNI_CONFIG_DIR/10-azure.conflist" | jq '.plugins[0].ipv6Mode="ipv6nat"') > "$CNI_CONFIG_DIR/10-azure.conflist"
fi
{{- if IsIPv6DualStackFeatureEnabled}}
Copy link
Member Author

Choose a reason for hiding this comment

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

saving cloud-init payload here

@acs-bot acs-bot added size/M and removed size/S labels Nov 20, 2020
fi
if [[ "${NETWORK_MODE}" == "bridge" ]]; then
sed -i 's#"mode":"transparent"#"mode":"bridge"#g' $CNI_CONFIG_DIR/10-azure.conflist
jq '.plugins[0].mode="bridge"' "$CNI_CONFIG_DIR/10-azure.conflist" > $tmpDir/tmp
Copy link
Member Author

Choose a reason for hiding this comment

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

Every time you replace a sed with a jq a @jchauncey gets his wings

@jackfrancis jackfrancis changed the title fix: ensure Azure CNI config and sed can play together fix: enforce Azure CNI config via jq instead of sed Nov 20, 2020
@@ -14,6 +14,8 @@
"properties": {
"orchestratorProfile": {
"kubernetesConfig": {
"networkPlugin": "azure",
Copy link
Member Author

Choose a reason for hiding this comment

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

These changes ensure we still have test coverage for Azure CNI + bridge mode now that Azure CNI 1.2.0 has merged with transparent mode enabled by default.

Copy link
Member

@aramase aramase left a comment

Choose a reason for hiding this comment

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

/lgtm

@acs-bot
Copy link

acs-bot commented Nov 20, 2020

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aramase, jackfrancis

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jackfrancis jackfrancis merged commit 7fdbef0 into Azure:master Nov 20, 2020
@jackfrancis jackfrancis deleted the ipv6-jq-cse branch November 20, 2020 23:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants