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

daemon: updates the CEP in-place #32574

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ovidiutirla
Copy link
Contributor

@ovidiutirla ovidiutirla commented May 16, 2024

based on #32501

Adds the logic required to update the CEP in-place when dynamic label filter detect any changes to network policy.
The reconcile loop will fetch all the CEP and compute the labels that needs to be added and removed considering the pod labels, namespace labels and the existing CEP labels.

Fixes: #32576

Add logic to update the CEP labels in-place when there are dynamic label filter changes.

Adds the base logic for handling the dynamic label filter for limiting
the set of identity relevant labels used for creating the CIDs. Many
labels are not useful for policy enforcement or visibility, the objective
is to create CIDs only for labels used in network policies to greatly
reduce the number of CIDs.

Signed-off-by: Ovidiu Tirla <otirla@google.com>
Add a daemon feature flag for the dynamic label filter
which is disabled by default for now. The goal is to have
it enabled by default and completely replace the need to
manually set the identity relevant labels.

Signed-off-by: Ovidiu Tirla <otirla@google.com>
Signed-off-by: Ovidiu Tirla <otirla@google.com>
Modifies the CEP to reflect the dynamic filter labels changes

Signed-off-by: Ovidiu Tirla <otirla@google.com>
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label May 16, 2024
@github-actions github-actions bot added the kind/community-contribution This was a contribution made by a community member. label May 16, 2024
@ovidiutirla ovidiutirla marked this pull request as ready for review May 16, 2024 11:51
@ovidiutirla ovidiutirla requested review from a team as code owners May 16, 2024 11:51
@ovidiutirla ovidiutirla marked this pull request as draft May 20, 2024 08:06
Copy link
Member

@bimmlerd bimmlerd left a comment

Choose a reason for hiding this comment

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

Hi, thanks a bunch for the contribution! Thanks for taking the time and using hive/cell.

I've asked some code level questions, but the biggest question on my mind is whether this can turn out to be a performance bottleneck. ModifyIdentityLabels I'd assume is a pretty expensive operation - if things change, I think this regenerates all affected endpoints, correct? Do you have some insight in how this performs in a cluster?

// If the SOURCE is any the transformed value will be empty
// k8s.Foo converts to k8s:Foo, any.Foo converts to :Foo
func normalizeKeyLabel(labelWithSourcePrefix string) string {
before, after, found := strings.Cut(labelWithSourcePrefix, ".")
Copy link
Member

Choose a reason for hiding this comment

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

I was under the impression that label keys can contain dots. If there's no intentional source but the label key contains a dot, does this still do the right thing?

return exitingLabels
}

// getRelevantKeyLabels extracts the label key from the MatchLabels and MatchExpressions.
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'm a bit confused by this naming - what are key labels? To me, this seems to extract a set of label keys from both the matchLabels and the matchExpressionLabels. So should this be named extractLabelKeys?

exitingLabels[l.Key] = l
}
// Merge with pod labels
exitingLabels.MergeLabels(labels.Map2Labels(podLabels, labels.LabelSourceK8s))
Copy link
Member

Choose a reason for hiding this comment

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

I have slight performance worries here - we're doing a lot of string/map allocs and deallocs shuffling these different label representations around. How often do you expect this code to run?

A more efficient representation could be to use sorted lists of immutable labels, to avoid the constant allocation and deallocation.

pkg/labelsfilterdynamic/manager.go Show resolved Hide resolved
identityLabelsMap := identityLabels.StringMap()
labelsToRemove := labels.Labels{}

for _, label := range endpointLabels {
Copy link
Member

Choose a reason for hiding this comment

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

Will this break in interesting ways if endpoint labels have duplicates?

pkg/labelsfilterdynamic/cell.go Show resolved Hide resolved
)

type controller struct {

Copy link
Member

Choose a reason for hiding this comment

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

nit: spurious newline


// EnableDynamicLabelFilter enables to filter dynamically the label prefixes used to determine identities based
// on network policy labels.
EnableDynamicLabelFilter bool
Copy link
Member

Choose a reason for hiding this comment

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

Let's try to avoid adding new fields to the DaemonConfig. You're creating a new cell, you can use cell.Config to scope the configuration to your cell.

pkg/labelsfilterdynamic/signals/signal.go Show resolved Hide resolved
case <-ctx.Done():
l.Info("Cilium Dynamic Label Filter Controller shut down")
return
case <-c.Signal.Signal:
Copy link
Member

Choose a reason for hiding this comment

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

Should this be rate-limited in some way? There's the signal coalescing if triggers arrive faster than the reconciliation can occur, but in effect (assuming fast trigger rate) the bottleneck is the rate at which reconciliation can happen - it's not clear to me that that's the right choice, given (I believe) this can kick of identity/ep regenerations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. kind/community-contribution This was a contribution made by a community member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CFP: Dynamic Labels Filter
2 participants