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/revision index #1733

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shiyan2016
Copy link
Member

Ⅰ. Describe what this PR does

add revision fieldindex to optimize list revisions operation

Ⅱ. Does this pull request fix one issue?

Ⅲ. Describe how to verify it

Ⅳ. Special notes for reviews

@shiyan2016 shiyan2016 force-pushed the feature/revision-index branch 2 times, most recently from 09f5315 to 0f20137 Compare September 9, 2024 10:04
err := rh.List(context.TODO(), &revisions, &client.ListOptions{Namespace: parent.GetNamespace(), LabelSelector: selector})
if err != nil {
return nil, err
opts := &client.ListOptions{
Copy link
Member

Choose a reason for hiding this comment

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

consider add DisableDeepCopy option

Copy link
Member

Choose a reason for hiding this comment

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

When use DisableDeepCopy, kruise will panic in e2e because some update codes in cloneset VCTHashEqual handler.
We should fix it. @shiyan2016

pkg/controller/cloneset/cloneset_controller.go:453

lastEqualRevision := equalRevisions[equalCount-1]
if !VCTHashEqual(lastEqualRevision, updateRevision) {
	klog.InfoS("Revision vct hash will be updated", "revisionName", lastEqualRevision.Name, "lastRevisionVCTHash", lastEqualRevision.Annotations[volumeclaimtemplate.HashAnnotation], "updateRevisionVCTHash", updateRevision.Annotations[volumeclaimtemplate.HashAnnotation])
	lastEqualRevision.Annotations[volumeclaimtemplate.HashAnnotation] = updateRevision.Annotations[volumeclaimtemplate.HashAnnotation]
}
// if the equivalent revision is not immediately prior we will roll back by incrementing the
// Revision of the equivalent revision
updateRevision, err = r.controllerHistory.UpdateControllerRevision(equalRevisions[equalCount-1], updateRevision.Revision)

@furykerry
Copy link
Member

plz fix the ut

@shiyan2016 shiyan2016 force-pushed the feature/revision-index branch 2 times, most recently from 29fc5b4 to d5e1156 Compare September 23, 2024 13:55
@@ -137,6 +139,7 @@ func init() {
utilruntime.Must(appsv1.AddToScheme(scheme))
utilruntime.Must(appsv1alpha1.AddToScheme(scheme))
utilruntime.Must(corev1.AddToScheme(scheme))
utilruntime.Must(apps.AddToScheme(scheme))
Copy link
Member

Choose a reason for hiding this comment

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

there is no need to add unversioned scheme here, L139 already do the job

@@ -69,7 +71,13 @@ func TestRevisionHistory(t *testing.T) {
t.Fatalf("Failed to new controller revision: %v", err)
}

fakeClient := fake.NewClientBuilder().Build()
fakeClient := fake.NewClientBuilder().WithIndex(&apps.ControllerRevision{}, fieldindex.IndexNameForOwnerRefUID, func(obj client.Object) []string {
var owners []string
Copy link
Member

Choose a reason for hiding this comment

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

There are so many errors in other uts and can be fixed by using client with index.
I think we should wrap this code with a customized function and replace fake.NewClientBuilder().

err := rh.List(context.TODO(), &revisions, &client.ListOptions{Namespace: parent.GetNamespace(), LabelSelector: selector})
if err != nil {
return nil, err
opts := &client.ListOptions{
Copy link
Member

Choose a reason for hiding this comment

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

When use DisableDeepCopy, kruise will panic in e2e because some update codes in cloneset VCTHashEqual handler.
We should fix it. @shiyan2016

pkg/controller/cloneset/cloneset_controller.go:453

lastEqualRevision := equalRevisions[equalCount-1]
if !VCTHashEqual(lastEqualRevision, updateRevision) {
	klog.InfoS("Revision vct hash will be updated", "revisionName", lastEqualRevision.Name, "lastRevisionVCTHash", lastEqualRevision.Annotations[volumeclaimtemplate.HashAnnotation], "updateRevisionVCTHash", updateRevision.Annotations[volumeclaimtemplate.HashAnnotation])
	lastEqualRevision.Annotations[volumeclaimtemplate.HashAnnotation] = updateRevision.Annotations[volumeclaimtemplate.HashAnnotation]
}
// if the equivalent revision is not immediately prior we will roll back by incrementing the
// Revision of the equivalent revision
updateRevision, err = r.controllerHistory.UpdateControllerRevision(equalRevisions[equalCount-1], updateRevision.Revision)

@@ -219,6 +229,13 @@ func testUpdateWhenSidecarSetPaused(t *testing.T, sidecarSetInput *appsv1alpha1.

fakeClient := fake.NewClientBuilder().WithScheme(scheme).
WithObjects(sidecarSetInput, podInput).
WithIndex(&apps.ControllerRevision{}, fieldindex.IndexNameForOwnerRefUID, func(obj 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.

use appsv1.ControllerRevision{}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants