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 various bugs related to restart of StatefulSet pods that may result in connectivity issues #31605

Merged
merged 5 commits into from May 8, 2024

Conversation

christarazi
Copy link
Member

@christarazi christarazi commented Mar 26, 2024

  • k8s/watcher: Remove outdated comments about K8sEventHandover
  • daemon, endpoint: Consolidate K8s metadata into struct
  • watchers: Detect Pod UID changes
  • daemon,endpoint,cni: Pass pod UID through CNI ADD
  • k8s/watchers: Fix pod IP modified check

Fixes: #30409

@christarazi christarazi added kind/bug This is a bug in the Cilium logic. area/daemon Impacts operation of the Cilium daemon. sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers. release-note/bug This PR fixes an issue in a previous release of Cilium. sig/kvstore Impacts the KVStore package interactions. sig/agent Cilium agent related. labels Mar 26, 2024
@christarazi

This comment was marked as outdated.

@christarazi

This comment was marked as outdated.

pkg/identity/identity.go Outdated Show resolved Hide resolved
@christarazi christarazi changed the title pr/christarazi/fix sts Fix various bugs related to restart of StatefulSet pods that may result in connectivity issues Mar 28, 2024
@christarazi christarazi marked this pull request as ready for review March 28, 2024 20:30
@christarazi christarazi requested review from a team as code owners March 28, 2024 20:30
@christarazi
Copy link
Member Author

christarazi commented Mar 28, 2024

/test

Edit:

@tklauser
Copy link
Member

tklauser commented Apr 2, 2024

Is this fix something we want to backport to 1.15? From the linked issue it seems all currently supported stable versions are affected.

This commit causes the Kubernetes Pod watcher to trigger endpoint
identity updates if the Pod UID changes. This covers the third scenario
pointed out in [1], see issue for more details.

To summarize, with StatefulSet restarts, it is possible for the
apiserver to coalesce Pod events where the delete and add event are
replaced with a single update event that includes, for example a label
change. If Cilium indexes based on namespace/name of the pod, then it
will miss this update event and therefore, Cilium must use the UID of
the pod to disambiguate.

[1]: cilium#30409

Signed-off-by: Chris Tarazi <chris@isovalent.com>
@christarazi

This comment was marked as outdated.

@christarazi christarazi force-pushed the pr/christarazi/fix-sts branch 2 times, most recently from fda9152 to b56ecff Compare May 8, 2024 18:28
@christarazi

This comment was marked as outdated.

Copy link
Contributor

@squeed squeed left a comment

Choose a reason for hiding this comment

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

One minor suggestion, then LGTM

daemon/cmd/endpoint.go Show resolved Hide resolved
Building off of the previous commit, This commit modifies if the CNI ADD
handling logic to pass the Kubernetes Pod UID in the ADD request to the
Agent. In addition, a extra condition checks whether the UID of the pod
corresponding to the CNI ADD request is the same UID which Cilium is
aware of (within its pod informer store) during endpoint creation. This
is key for handling StatefulSets properly, see [1].

If the UID is outdated, this means that Cilium has not yet received the
updated pod event that corresponds with the CNI ADD. In this case,
Cilium will attempt to query the pod store up for to 2 seconds. If the
pod store does not have the altest pod reference after 2 seconds, Cilium
will trigger a direct fetch from the apiserver, as to avoid a
potentially large window of time where an endpoint cannot be created. If
the direct fetch fails, the endpoint will be created with the 'init'
identity until the metadata resolver (controller) is able to fetch the
latest pod metadata.

The reason for these changes is due to the way StatefulSets are
implemented in Kubernetes. One significant property of StatefulSets is
that they have a fixed name. When a StatefulSet is restarted, Cilium is
unable to properly handle it because Cilium indexes based on
namespace/name[1]. Therefore, we must pass a UID through the CNI ADD in
order to ensure that when Cilium creates a new endpoint, it is created
with the most up-to-date corresponding Kubernetes metadata.

[1]: cilium#30409, see case 1.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
Previously, the logic in the pod watcher did not properly check for
changes in a pod's IPs, incorrectly relying on the length of the IP
strings changing, rather than the contents. This commit fixes that while
also simplifying the logic into a simpler one-liner.

Reported-by: Casey Callendrello <cdc@isovalent.com>
Signed-off-by: Chris Tarazi <chris@isovalent.com>
@christarazi
Copy link
Member Author

/test

Copy link
Contributor

@learnitall learnitall left a comment

Choose a reason for hiding this comment

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

API changes LGTM!

@christarazi christarazi added this pull request to the merge queue May 8, 2024
Merged via the queue into cilium:main with commit b048dbd May 8, 2024
63 of 64 checks passed
@christarazi christarazi deleted the pr/christarazi/fix-sts branch May 8, 2024 22:41
@christarazi christarazi mentioned this pull request May 9, 2024
1 task
@christarazi christarazi added backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. and removed needs-backport/1.15 This PR / issue needs backporting to the v1.15 branch labels May 9, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from main to Backport pending to v1.15 in 1.15.5 May 9, 2024
@primeroz
Copy link

primeroz commented May 9, 2024

Is this being backported to 1.14 ? 🙏

@github-actions github-actions bot added backport-done/1.15 The backport for Cilium 1.15.x for this PR is done. and removed backport-pending/1.15 The backport for Cilium 1.15.x for this PR is in progress. labels May 9, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed this from Backport pending to v1.15 in 1.15.5 May 9, 2024
@primeroz
Copy link

@christarazi sorry for the ping , i just wanted to check if there is any plan of porting this fix to 1.14 ?

thanks 🙏

@christarazi
Copy link
Member Author

@primeroz Right now only v1.15 backport was considered due to the nature of the changes being non-trivial. The risk of backporting to older stable versions is that we introduce a regression in very stable versions of Cilium.

@primeroz
Copy link

primeroz commented May 14, 2024

@christarazi i understand and we will check internally if is worth for us to upgrade to 1.15

Just to confirm though the issue is present in 1.14 as well right ? ( we think we did hit it )

thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects/v1.13 This issue affects v1.13 branch affects/v1.14 This issue affects v1.14 branch area/daemon Impacts operation of the Cilium daemon. backport-done/1.15 The backport for Cilium 1.15.x for this PR is done. kind/bug This is a bug in the Cilium logic. release-blocker/1.15 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. sig/agent Cilium agent related. sig/k8s Impacts the kubernetes API, or kubernetes -> cilium internals translation layers. sig/kvstore Impacts the KVStore package interactions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cilium-agent incorrectly handles rollouts of statefulsets
8 participants