Skip to content

Conversation

@vakalapa
Copy link
Contributor

@vakalapa vakalapa commented Nov 3, 2021

  1. Network policy controller v2 using generic DP APIs
  2. All V2 Controller UTs with GDPI mock

Copy link
Contributor

@huntergregory huntergregory left a comment

Choose a reason for hiding this comment

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

Wrote a note about updating policies versus removing/adding. We'll have to decide whether we want to track Prometheus policy metrics in controller pods, dp daemons, or both.

// If error happens while applying ipsets and iptables,
// the key is re-queued in workqueue and process this function again, which eventually meets desired states of network policy
c.rawNpMap[netpolKey] = netPolObj
metrics.IncNumPolicies()
Copy link
Contributor

Choose a reason for hiding this comment

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

should we track policy metrics in the controller or DP? IPSet metrics must be tracked in the DP since the logic is only feasible in the ipset manager when we apply sets on need in the kernel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am okay with either approaches, since the object is just one and logic is simple if we do it in controller, since we will only increment if DP sends a no error signal. In DP we can have more robust metrics to determine, how many endpoints have a policy, how many rules etc .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In DP policy may not make sense, but rules do. so we should have a metric for rules in DP, wdyt ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense to have rules in DP. Good with the code as is, but if the number of policies is the only metric that the control plane could take care of, then perhaps we just take care of that metric in DP only for simplicity

@vakalapa vakalapa changed the title [NPM] NPM v2 network policy controller and UTs for all v2 controllers feat: [NPM] NPM v2 network policy controller and UTs for all v2 controllers Nov 8, 2021
@huntergregory
Copy link
Contributor

To qualify the prometheus discussion, currently we have cluster-level metrics (e.g. num policies, sets, entries)j and node-level metrics (execution times). These metrics are hosted on different HTTP endpoints, and the cluster-level ones are redundant across all daemonsets.


// nodename in NewPodMetadata is nil so UpdatePod is ignored
podMetadata := dataplane.NewPodMetadata(podKey, namedPortIpsetEntry, "")
podMetadata := dataplane.NewPodMetadata(podKey, namedPortIpsetEntry, nodeName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious - why do we have NodeName? Is it because of endpointPolicy of windows?

Copy link
Contributor Author

@vakalapa vakalapa Nov 8, 2021

Choose a reason for hiding this comment

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

Yes, in linux this will be no-op, this was the only major difference between linux and windows controllers, and i felt this did not have enough usage to be abstracted out and be maintained for both linux and windows.

cachedPodMetadata := dataplane.NewPodMetadata(podKey, cachedNpmPod.PodIP, newPodMetadata.NodeName)

if err = c.dp.RemoveFromSets([]*ipsets.IPSetMetadata{ipsets.NewIPSetMetadata(podIPSetName, ipsets.KeyLabelOfPod)}, cachedPodMetadata); err != nil {
toRemoveSet := ipsets.NewIPSetMetadata(podIPSetName, ipsets.KeyLabelOfPod)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use if and else?

Copy link
Contributor

@JungukCho JungukCho left a comment

Choose a reason for hiding this comment

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

lgtm, but can you double check DeepEqual with UTs before merging it.

// In this updateNetworkPolicy event,
// newNetPol was updated with states which netPolController does not need to reconcile.
if reflect.DeepEqual(*cachedNetPolSpecObj, netPolObj.Spec) {
if reflect.DeepEqual(cachedNetPolSpecObj, &netPolObj.Spec) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious - Are their result different?
reflect.DeepEqual(*cachedNetPolSpecObj, netPolObj.Spec) and reflect.DeepEqual(cachedNetPolSpecObj, &netPolObj.Spec)

Copy link
Contributor Author

@vakalapa vakalapa Nov 9, 2021

Choose a reason for hiding this comment

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

Yeah , did not want to pass in full objs and replicating them inside deep inside, so decided to send in pointers.

}

cachedNetPolObj, netPolExists := c.rawNpMap[key]
cachedNetPolSpecObj, netPolExists := c.rawNpMap[key]
Copy link
Contributor

Choose a reason for hiding this comment

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

I worried about updating name and namespace , but they are immutable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes and our Key has namespace and name in it.

@vakalapa
Copy link
Contributor Author

vakalapa commented Nov 9, 2021

@JungukCho TestUpdateNetworkPolicy validated that scenario and you can see updatePolicy is called only once.

https://github.com/Azure/azure-container-networking/pull/1082/files#diff-0a14b8e3224390042442b845130ec1a4bb07a334ade2087d9a31fea65a0e8201R372

Copy link
Contributor

@JungukCho JungukCho left a comment

Choose a reason for hiding this comment

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

lgtm!

@vakalapa vakalapa merged commit 08df7f7 into master Nov 9, 2021
@vakalapa vakalapa deleted the vakr/netpolv2controller branch November 9, 2021 23:29
matmerr pushed a commit to matmerr/azure-container-networking that referenced this pull request Nov 11, 2021
…ollers (Azure#1082)

* adding a legacy build command

* Adding all v2 controller test files

* v2 podcontroller changes

* completing all pod v2 controllers uts

* Adding netpol v2 controller UTs

* Removing unused make file command

* Fixing lints and correcting a test case

* Fixing an error in expected values

* dealing with flaky tests

* Fixing an issue with HCN vendor, until we wait for the fix to be rolled out

* Addressing some comments

* Removing addPolicy call and relying on updatepolicy

* Saving only spec of netpol and not whole object

* changing name of rawNPMap to rawNPSpecMap

* changing name of rawNPMap to rawNPSpecMap

* Deep equal type for spec was not equal corrected the pointers

* Deep equal type for spec was not equal corrected the pointers
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.

4 participants