Skip to content

Conversation

jrajahalme
Copy link
Member

@jrajahalme jrajahalme commented May 31, 2024

Wait until endpoint restoration is done before serving any xDS resources to external (daemonset) Envoy on Cilium restart. This reduces Envoy resource churn during agent restart.

Add Cell to xds so that it can depend on the promise directly.

With this we only get one no-op policy update in Envoy:

[cilium/network_policy.cc:1175] NetworkPolicyMap::onConfigUpdate(cilium.policymap.10.244.1.193.1.), 3 resources, version: 17
xternal/envoy/source/common/init/watcher_impl.cc:31] init manager NetworkPolicyMap manager for version 16 destroyed
[cilium/network_policy.cc:1200] Received Network Policy for endpoint 1830 in onConfigUpdate() version 17
[cilium/network_policy.cc:1214] New policy is equal to old one, not updating.
[cilium/network_policy.cc:1200] Received Network Policy for endpoint 3283 in onConfigUpdate() version 17
[cilium/network_policy.cc:1214] New policy is equal to old one, not updating.
[cilium/network_policy.cc:1200] Received Network Policy for endpoint 3268 in onConfigUpdate() version 17
[cilium/network_policy.cc:1214] New policy is equal to old one, not updating.
[external/envoy/source/common/init/target_impl.cc:34] target NetworkPolicyMap manager for version 16 destroyed
[cilium/network_policy.cc:1266] Reopening ipcache on new stream
[cilium/ipcache.cc:81] cilium.ipcache: Opened ipcache.
[cilium/network_policy.cc:1273] Skipping empty or duplicate policy update.
Cilium restart now waits for Envoy resources to stabilize on restart before serving them to daemonset Envoy, reducing policy churn.

@jrajahalme jrajahalme added kind/bug This is a bug in the Cilium logic. area/proxy Impacts proxy components, including DNS, Kafka, Envoy and/or XDS servers. release-note/bug This PR fixes an issue in a previous release of Cilium. labels May 31, 2024
@jrajahalme jrajahalme requested review from a team as code owners May 31, 2024 17:09
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme marked this pull request as draft May 31, 2024 17:55
@jrajahalme
Copy link
Member Author

put back in draft, will have to test restarts when endpoints have L7 policies; it is possible that regeneration now hangs in that case as envoy updates are postponed.

@sayboras
Copy link
Member

sayboras commented Jun 1, 2024

Do we need to update cilium-envoy to the latest to pick up cilium/proxy#785?

@squeed
Copy link
Contributor

squeed commented Jun 3, 2024

I know the context from which this comes -- wanting to ensure Envoy reloads ipcache and doesn't replace policies with an empty set -- but it would be good to identify which sorts of churn this does and does not prevent. What does endpoint restoration provide that Envoy consumes?

As endpoints are regenerated, are we going to see policy drops for non-regenerated endpoints? I assume so, since their policy is not yet generated and thus not in the xDS server. But not sure what we can do about that yet.

@jrajahalme jrajahalme force-pushed the envoy-reopen-ipcache-on-agent-restart branch from 272cd92 to a2682be Compare June 3, 2024 10:17
@jrajahalme
Copy link
Member Author

/test

@jrajahalme

This comment was marked as outdated.

@jrajahalme
Copy link
Member Author

I know the context from which this comes -- wanting to ensure Envoy reloads ipcache and doesn't replace policies with an empty set -- but it would be good to identify which sorts of churn this does and does not prevent. What does endpoint restoration provide that Envoy consumes?

Endpoint restoration waits for k8s.CacheStatus (initial sync of all k8s resources), and endpoint restoration itself re-creates all endpoint policies (bpf maps and Envoy policies). k8s sync includes CEC/CCEC resources, so that should cover Ingress/GW API. I would expect these (k8s initial sync & endpoint regeneration) to recreate all Envoy listeners, clusters, endpoints, secrets, as well as network policies.

As endpoints are regenerated, are we going to see policy drops for non-regenerated endpoints? I assume so, since their policy is not yet generated and thus not in the xDS server. But not sure what we can do about that yet.

We now delay sending any new resources to Envoy, so all existing (and most new) connections should keep going based on the previous policy, both in bpf datapath as well as in Envoy.

There is a caveat with new dns proxy-dependent connection in the window between endpoint bpf having been regenerated and us waiting on ALL endpoints having been regenerated before sending updated network policies to Envoy. The updated policy would include newly allocated FQDN IDs.

@squeed
Copy link
Contributor

squeed commented Jun 3, 2024

Endpoint restoration waits for k8s.CacheStatus...

@jrajahalme no, that's endpoint regeneration. Restoration happens much earlier, even before the k8s clients have started. Regeneration is what re-creates policies and proceeds only after the daemon has initialized.

Network policies are, indeed, ingested before regeneration, but regeneration is what converts them to Envoy configuration.

@jrajahalme jrajahalme force-pushed the envoy-reopen-ipcache-on-agent-restart branch from a2682be to ff3b4a1 Compare June 3, 2024 16:35
@jrajahalme
Copy link
Member Author

jrajahalme commented Jun 3, 2024

Endpoint restoration waits for k8s.CacheStatus...

@jrajahalme no, that's endpoint regeneration. Restoration happens much earlier, even before the k8s clients have started. Regeneration is what re-creates policies and proceeds only after the daemon has initialized.

Network policies are, indeed, ingested before regeneration, but regeneration is what converts them to Envoy configuration.

My read of the following is that initial k8s state is fetched before endpoints are restored:

	if params.Clientset.IsEnabled() {
		// Wait only for certain caches, but not all!
		// (Check Daemon.InitK8sSubsystem() for more info)
		<-params.CacheStatus
	}
	bootstrapStats.k8sInit.End(true)
	d.initRestore(restoredEndpoints, params.EndpointRegenerator)

Endpoints are regenerated during restoration, so whatever happens during endpoint regeneration also happens during endpoint restoration. Finished regenerating restored endpoints is the last log before endpoint restorations is deemed complete.

@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme force-pushed the envoy-reopen-ipcache-on-agent-restart branch from ff3b4a1 to 397cf70 Compare June 3, 2024 18:09
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme marked this pull request as ready for review June 3, 2024 18:50
@jrajahalme jrajahalme force-pushed the envoy-reopen-ipcache-on-agent-restart branch from 397cf70 to a23c363 Compare June 3, 2024 18:58
@jrajahalme jrajahalme requested a review from a team as a code owner June 8, 2024 16:31
@jrajahalme jrajahalme requested review from rgo3 and jibi June 8, 2024 16:31
@jrajahalme jrajahalme force-pushed the envoy-reopen-ipcache-on-agent-restart branch from a62ba38 to f800ea5 Compare June 8, 2024 16:32
@jrajahalme jrajahalme removed request for a team, rgo3 and jibi June 8, 2024 16:47
@jrajahalme
Copy link
Member Author

/test

@jrajahalme jrajahalme requested a review from sayboras June 9, 2024 15:54
Copy link
Member

@sayboras sayboras left a comment

Choose a reason for hiding this comment

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

Thanks

Copy link
Member

@mhofstetter mhofstetter left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes Jarno! Only one non-blocking input/question.

@jrajahalme jrajahalme added the release-blocker/1.16 This issue will prevent the release of the next version of Cilium. label Jun 10, 2024
@jrajahalme jrajahalme added this pull request to the merge queue Jun 10, 2024
Merged via the queue into cilium:main with commit 2bf8ae7 Jun 10, 2024
@jrajahalme jrajahalme deleted the envoy-reopen-ipcache-on-agent-restart branch June 10, 2024 06:38
@jrajahalme jrajahalme mentioned this pull request Nov 4, 2024
@jrajahalme jrajahalme added the backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. label Nov 4, 2024
@jrajahalme jrajahalme mentioned this pull request Nov 4, 2024
@jrajahalme jrajahalme added the backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. label Nov 4, 2024
@julianwiedmann julianwiedmann removed backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. labels Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/proxy Impacts proxy components, including DNS, Kafka, Envoy and/or XDS servers. kind/bug This is a bug in the Cilium logic. release-blocker/1.16 This issue will prevent the release of the next version of Cilium. release-note/bug This PR fixes an issue in a previous release of Cilium.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants