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

feature: Optimizing Pod SidecarSet webhook performance #1547

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

ls-2018
Copy link
Member

@ls-2018 ls-2018 commented Mar 28, 2024

Ⅰ. Describe what this PR does

Ⅱ. Does this pull request fix one issue?

Ⅲ. Describe how to verify it

Ⅳ. Special notes for reviews

@kruise-bot kruise-bot requested review from FillZpp and furykerry March 28, 2024 02:32
@kruise-bot kruise-bot added the size/M size/M: 30-99 label Mar 28, 2024
@ls-2018 ls-2018 force-pushed the 1546 branch 2 times, most recently from 51d4e52 to 983fdd8 Compare March 28, 2024 02:36
return nil
}

ns := sets.NewString()
Copy link
Member

Choose a reason for hiding this comment

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

I think there are two types, one is configured spec.namespace and the other is not configured which you can set 'CludsterScope' Namespace, and namespaceSelector also counts as a type of 'ClusterScope'.

@ls-2018 ls-2018 force-pushed the 1546 branch 3 times, most recently from 8e01623 to 650b7a3 Compare March 28, 2024 02:59
@@ -93,10 +95,30 @@ func (h *SidecarSetCreateUpdateHandler) validateSidecarSet(obj *appsv1alpha1.Sid
}
// iterate across all containers in other sidecarsets to avoid duplication of name
sidecarSets := &appsv1alpha1.SidecarSetList{}
if err := h.Client.List(context.TODO(), sidecarSets, &client.ListOptions{}); err != nil {
allErrs = append(allErrs, field.InternalError(field.NewPath(""), fmt.Errorf("query other sidecarsets failed, err: %v", err)))
if obj.Spec.Namespace != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Why validate here, didn't understand the scenario.

@zmberg
Copy link
Member

zmberg commented Mar 28, 2024

@ls-2018 There need to be optimized, and only getting the pod.namepsace sidecarSet and the ClusterScope SidecarSet.
image

IndexNameForController = ".metadata.controller"
IndexNameForIsActive = "isActive"
IndexNameForSideCarSetNamespace = "spec.namespace"
IndexNameForSideCarSetClusterScopeNamespace = "spec.namespaceSelector"
Copy link
Member

Choose a reason for hiding this comment

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

Don't build this index of spec.namespaceSelector.

@@ -152,3 +160,16 @@ func indexImagePullJobActive(c cache.Cache) error {
return []string{isActive}
})
}

func indexSideCatSet(c cache.Cache) error {
Copy link
Member

Choose a reason for hiding this comment

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

indexSideCatSet -> indexSidecarSet

for _, sidecarSet := range sidecarsetList.Items {
for _, sidecarSet := range append(sidecarsetList.Items, sidecarsetList2.Items...) {
// Prevents sidecarSet from processing twice
key := fmt.Sprintf("%s/%s", sidecarSet.Namespace, sidecarSet.Name)
Copy link
Member

Choose a reason for hiding this comment

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

sidecarset is a clusterscope resource, so the name of sidecarset should be unique clusterwise, it is not necessary to add namespace in the key. Actually it seems impossible for a sidecarset to be both cluster scoped and namespace scoped, so is it really possible to precess sidecarset twice here?

if obj.Spec.Namespace != "" {
return []string{obj.Spec.Namespace}
}
return []string{IndexValueSideCarSetClusterScope}
Copy link
Member

Choose a reason for hiding this comment

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

since k8s 1.22, k8s will automatically assign name label in the namespace, so if the sidecarset namespace selector select the built-in label, it should also return the namespace index

IndexNameForController = ".metadata.controller"
IndexNameForIsActive = "isActive"
IndexNameForSideCarSetNamespace = "namespace"
IndexValueSideCarSetClusterScope = "ClusterScope"
Copy link
Member

Choose a reason for hiding this comment

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

IndexNameForSideCarSetNamespace -> IndexNameForSidecarSetNamespace
IndexValueSideCarSetClusterScope -> IndexValueSidecarSetClusterScope

@ls-2018 ls-2018 force-pushed the 1546 branch 2 times, most recently from 4298d8b to d9ee8fd Compare March 28, 2024 12:36
@Spground
Copy link
Contributor

Spground commented Apr 1, 2024

Moreover, it will improve a lot if use index in sidecarset controller as same as webhook,

func (p *Processor) listMatchedSidecarSets(pod *corev1.Pod) string {
.

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 45.83333% with 26 lines in your changes are missing coverage. Please review.

Project coverage is 47.78%. Comparing base (1f00e6b) to head (51e60fa).
Report is 3 commits behind head on master.

Files Patch % Lines
pkg/controller/sidecarset/sidecarset_processor.go 0.00% 11 Missing ⚠️
pkg/util/fieldindex/register.go 69.23% 8 Missing ⚠️
pkg/webhook/pod/mutating/sidecarset.go 36.36% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1547      +/-   ##
==========================================
- Coverage   47.97%   47.78%   -0.20%     
==========================================
  Files         162      163       +1     
  Lines       23491    23611     +120     
==========================================
+ Hits        11270    11282      +12     
- Misses      11005    11108     +103     
- Partials     1216     1221       +5     
Flag Coverage Δ
unittests 47.78% <45.83%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ls-2018 ls-2018 requested review from furykerry and zmberg April 2, 2024 00:34
@ls-2018
Copy link
Member Author

ls-2018 commented Apr 2, 2024

/cc @zmberg @furykerry

@@ -152,3 +161,32 @@ func indexImagePullJobActive(c cache.Cache) error {
return []string{isActive}
})
}

func IndexSideCarSet(rawObj client.Object) []string {
Copy link
Member

Choose a reason for hiding this comment

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

plz add ut for this published func

IndexNameForController = ".metadata.controller"
IndexNameForIsActive = "isActive"
IndexNameForSidecarSetNamespace = "namespace"
IndexValueSidecarSetClusterScope = "ClusterScope"
Copy link
Contributor

Choose a reason for hiding this comment

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

How about ClusterScope refactor to be clusterScope , which looks like be same format style.

IndexNameForIsActive = "isActive"
IndexNameForSidecarSetNamespace = "namespace"
IndexValueSidecarSetClusterScope = "ClusterScope"
LabelMetadataName = "kubernetes.io/metadata.name"
Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, it's better refs the API label via k8s apis (k8s.io/api/core/v1/well_known_labels.go) rather than we repeat these literal values.

@furykerry
Copy link
Member

/lgtm

return []string{IndexValueSidecarSetClusterScope}
}

func indexSideCarSet(c cache.Cache) error {
Copy link
Member

Choose a reason for hiding this comment

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

indexSideCarSet -> indexSidecarSet

@zmberg
Copy link
Member

zmberg commented Apr 7, 2024

/lgtm

@furykerry
Copy link
Member

/lgtm

@furykerry
Copy link
Member

/approve

@Spground
Copy link
Contributor

Spground commented Apr 8, 2024

/lgtm

@kruise-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: furykerry

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kruise-bot
Copy link

@Spground: changing LGTM is restricted to collaborators

In response to this:

/lgtm

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@kruise-bot kruise-bot merged commit 8bb8964 into openkruise:master Apr 8, 2024
32 of 34 checks passed
@ls-2018 ls-2018 deleted the 1546 branch April 8, 2024 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants