-
Notifications
You must be signed in to change notification settings - Fork 776
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
Conversation
51d4e52
to
983fdd8
Compare
pkg/util/fieldindex/register.go
Outdated
return nil | ||
} | ||
|
||
ns := sets.NewString() |
There was a problem hiding this comment.
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'.
8e01623
to
650b7a3
Compare
@@ -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 != "" { |
There was a problem hiding this comment.
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.
@ls-2018 There need to be optimized, and only getting the pod.namepsace sidecarSet and the ClusterScope SidecarSet. |
pkg/util/fieldindex/register.go
Outdated
IndexNameForController = ".metadata.controller" | ||
IndexNameForIsActive = "isActive" | ||
IndexNameForSideCarSetNamespace = "spec.namespace" | ||
IndexNameForSideCarSetClusterScopeNamespace = "spec.namespaceSelector" |
There was a problem hiding this comment.
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.
pkg/util/fieldindex/register.go
Outdated
@@ -152,3 +160,16 @@ func indexImagePullJobActive(c cache.Cache) error { | |||
return []string{isActive} | |||
}) | |||
} | |||
|
|||
func indexSideCatSet(c cache.Cache) error { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
pkg/util/fieldindex/register.go
Outdated
if obj.Spec.Namespace != "" { | ||
return []string{obj.Spec.Namespace} | ||
} | ||
return []string{IndexValueSideCarSetClusterScope} |
There was a problem hiding this comment.
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
pkg/util/fieldindex/register.go
Outdated
IndexNameForController = ".metadata.controller" | ||
IndexNameForIsActive = "isActive" | ||
IndexNameForSideCarSetNamespace = "namespace" | ||
IndexValueSideCarSetClusterScope = "ClusterScope" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IndexNameForSideCarSetNamespace -> IndexNameForSidecarSetNamespace
IndexValueSideCarSetClusterScope -> IndexValueSidecarSetClusterScope
4298d8b
to
d9ee8fd
Compare
Moreover, it will improve a lot if use index in sidecarset controller as same as webhook,
|
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
/cc @zmberg @furykerry |
pkg/util/fieldindex/register.go
Outdated
@@ -152,3 +161,32 @@ func indexImagePullJobActive(c cache.Cache) error { | |||
return []string{isActive} | |||
}) | |||
} | |||
|
|||
func IndexSideCarSet(rawObj client.Object) []string { |
There was a problem hiding this comment.
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
pkg/util/fieldindex/register.go
Outdated
IndexNameForController = ".metadata.controller" | ||
IndexNameForIsActive = "isActive" | ||
IndexNameForSidecarSetNamespace = "namespace" | ||
IndexValueSidecarSetClusterScope = "ClusterScope" |
There was a problem hiding this comment.
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.
pkg/util/fieldindex/register.go
Outdated
IndexNameForIsActive = "isActive" | ||
IndexNameForSidecarSetNamespace = "namespace" | ||
IndexValueSidecarSetClusterScope = "ClusterScope" | ||
LabelMetadataName = "kubernetes.io/metadata.name" |
There was a problem hiding this comment.
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.
/lgtm |
pkg/util/fieldindex/register.go
Outdated
return []string{IndexValueSidecarSetClusterScope} | ||
} | ||
|
||
func indexSideCarSet(c cache.Cache) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indexSideCarSet -> indexSidecarSet
Signed-off-by: acejilam <[email protected]>
/lgtm |
/lgtm |
/approve |
/lgtm |
[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 |
@Spground: changing LGTM is restricted to collaborators In response to this:
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. |
Ⅰ. Describe what this PR does
Ⅱ. Does this pull request fix one issue?
Ⅲ. Describe how to verify it
Ⅳ. Special notes for reviews