-
Notifications
You must be signed in to change notification settings - Fork 558
Add Azure-npm to provide native k8s network policy support #3205
Conversation
/assign @jackfrancis |
pkg/acsengine/const.go
Outdated
@@ -50,6 +50,8 @@ const ( | |||
NetworkPolicyCalico = "calico" | |||
// NetworkPolicyCilium is the string expression for cilium network policy config option | |||
NetworkPolicyCilium = "cilium" | |||
// NetworkPolicyAzure is the string expression for cilium network policy config option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste typo in the comment, should say Azure CNI, not cilium
pkg/acsengine/const.go
Outdated
@@ -50,6 +50,8 @@ const ( | |||
NetworkPolicyCalico = "calico" | |||
// NetworkPolicyCilium is the string expression for cilium network policy config option | |||
NetworkPolicyCilium = "cilium" | |||
// NetworkPolicyAzure is the string expression for cilium network policy config option | |||
NetworkPolicyAzure = "azure" | |||
// NetworkPluginAzure is the string expression for Azure CNI network policy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be network plugin
instead of network policy
since you are adding one for network policy. Or maybe we could reuse the same constant for both? Your call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jackfrancis separated NetworkPolicy & NetworkPlugin. So basically NetworkPlugin means CNI and NetworkPolicy means network policy plugin. These are two different things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I meant the comment should reflect that, right it's // NetworkPluginAzure is the string expression for Azure CNI network policy
which is confusing
pkg/acsengine/defaults.go
Outdated
@@ -384,7 +384,7 @@ func setOrchestratorDefaults(cs *api.ContainerService) { | |||
switch o.KubernetesConfig.NetworkPolicy { | |||
case NetworkPluginAzure: | |||
o.KubernetesConfig.NetworkPlugin = NetworkPluginAzure | |||
o.KubernetesConfig.NetworkPolicy = DefaultNetworkPolicy | |||
o.KubernetesConfig.NetworkPolicy = NetworkPolicyAzure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for changing the default here? This might break backwards compatibility so we'll have to do some extensive testing if this is something we want. cc: @jackfrancis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we don't have network policy support in Azure CNI, now we just released it. Therefore we want to set default NetworkPolicy to azure.
pkg/api/convertertoapi.go
Outdated
api.KubernetesConfig.NetworkPlugin = vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy | ||
api.KubernetesConfig.NetworkPolicy = "" // no-op but included for emphasis | ||
} else if vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy == NetworkPolicyNone { | ||
if vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy == NetworkPolicyNone { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why this is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For setting default NetworkPolicy to azure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how this is setting the default NetworkPolicy to azure? What I'm reading is "if NetworkPolicy is none. set NetworkPolicy to "" and NetworkPlugin to kubenet". What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously it overwrites NetworkPolicy to "" if NetworkPolicy == NetworkPolicyAzure. It's not needed anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes need to be removed from this PR. The entire reason for this code (as described in the comments) is to maintain backwards-compatibility with prior usage patterns. This code is not meant to accommodate ongoing usage pattern changes/additions.
pkg/acsengine/defaults_test.go
Outdated
@@ -430,10 +430,6 @@ func TestNetworkPolicyDefaults(t *testing.T) { | |||
t.Fatalf("NetworkPlugin did not have the expected value, got %s, expected %s", | |||
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin, "azure") | |||
} | |||
if properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy != "" { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
@CecileRobertMichon You're right. We could overwrite the NetworkPolicy to DefaultNetworkPolicy for k8s < 1.8. |
fd63aa4
to
60ebf34
Compare
pkg/api/convertertoapi.go
Outdated
api.KubernetesConfig.NetworkPlugin = NetworkPluginKubenet | ||
api.KubernetesConfig.NetworkPolicy = "" // no-op but included for emphasis | ||
} else if vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy == NetworkPolicyAzure { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should happen in defaults.go since it is modifying the default behavior
Codecov Report
@@ Coverage Diff @@
## master #3205 +/- ##
==========================================
+ Coverage 54.55% 54.59% +0.04%
==========================================
Files 104 104
Lines 15739 15759 +20
==========================================
+ Hits 8586 8604 +18
- Misses 6404 6405 +1
- Partials 749 750 +1 |
How does this PR relate to #3198 ? |
@CecileRobertMichon PR #3198 is Azure Container Network Monitering Service, which is used for container networking telemetry purposes. This PR adds native k8s network policy support. |
pkg/acsengine/defaults.go
Outdated
@@ -394,6 +394,12 @@ func setOrchestratorDefaults(cs *api.ContainerService) { | |||
o.KubernetesConfig.NetworkPlugin = NetworkPolicyCilium | |||
} | |||
|
|||
if o.KubernetesConfig.NetworkPolicy == NetworkPolicyAzure { | |||
if !common.IsKubernetesVersionGe(k8sVersion, "1.8.0") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this < 1.8.0 logic up into the above switch/case statement, as it is executing against an identical condition (NetworkPolicy == "azure")
What is the expected default behavior for network policy after this PR if a user does not pass in any netork plugin/policy value? ie. with the default kubernetes example apimodel We need to update the relevant docs (especially since the default behavior isn't straightforward by looking at the code because of all the back compat cruft), specifically https://github.com/Azure/acs-engine/blob/master/examples/networkpolicy/README.md and clusterdefinition.md |
This change should have no impact on the current expected default configuration outcome. From a high level, this PR:
That should be it. I believe our unit tests should ensure no regressions in our default configuration cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
8ed0bcc
to
959b5ba
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: CecileRobertMichon, jackfrancis, saiyan86 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 |
@saiyan86 Great to see this progressing. Where do we report issues with azure-npm? Is there a repo available? Certain policies do not seem to function correctly, for example try https://github.com/ahmetb/kubernetes-network-policy-recipes/blob/master/04-deny-traffic-from-other-namespaces.md . This does not seem to work with azure-npm, but does with kube-router. Policies using pod selectors do seem to work. @jackfrancis @CecileRobertMichon are you aware of a project that tests various network policies? Thanks. |
@marrobi Thank you for trying it out. Please file the issue @ https://github.com/Azure/azure-container-networking/issues |
@marrobi I'm not! We have a very basic NetworkPolicy validation in our E2E tests, would love to introduce something more thorough if you discover a comprehensive lib/project. |
@jackfrancis I will add some tests soon that should work for both Calico and us. |
What this PR does / why we need it:
This PR provides native k8s policy support.
Azure-npm is a Microsoft Azure's fault-tolerant and scalable implementation of Kubernetes Network Policy plugin.
Azure-npm supports all network policies specified by current version of Kubernetes, and will continue to support future versions.
Azure-npm only supports Kubernetes v1.8 or later, as it requires NetworkPolicy API v1beta1.