-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
🐛 Fixed a bug in newGVKFixupWatcher which caused the metadata informer to hang #1790
Merged
k8s-ci-robot
merged 4 commits into
kubernetes-sigs:master
from
wallrj:1789-close-metadata-watch-result-channel
Feb 8, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0fbdc4b
Test that gvkFixupWatcher matches the behaviour of watch.FakeWatcher
wallrj 5f4904e
Re-implement gvkFixupWatcher as a watch.FilterFunc
wallrj 7ab04d5
Update copyright headers
wallrj a4e0eee
Remove DeepCopy, as suggested during code review
wallrj File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package internal | ||
|
||
import ( | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/watch" | ||
) | ||
|
||
// Test that gvkFixupWatcher behaves like watch.FakeWatcher | ||
// and that it overrides the GVK. | ||
// These tests are adapted from the watch.FakeWatcher tests in: | ||
// https://github.com/kubernetes/kubernetes/blob/adbda068c1808fcc8a64a94269e0766b5c46ec41/staging/src/k8s.io/apimachinery/pkg/watch/watch_test.go#L33-L78 | ||
var _ = Describe("gvkFixupWatcher", func() { | ||
It("behaves like watch.FakeWatcher", func() { | ||
newTestType := func(name string) runtime.Object { | ||
return &metav1.PartialObjectMetadata{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
}, | ||
} | ||
} | ||
|
||
f := watch.NewFake() | ||
// This is the GVK which we expect the wrapper to set on all the events | ||
expectedGVK := schema.GroupVersionKind{ | ||
Group: "testgroup", | ||
Version: "v1test2", | ||
Kind: "TestKind", | ||
} | ||
gvkfw := newGVKFixupWatcher(expectedGVK, f) | ||
|
||
table := []struct { | ||
t watch.EventType | ||
s runtime.Object | ||
}{ | ||
{watch.Added, newTestType("foo")}, | ||
{watch.Modified, newTestType("qux")}, | ||
{watch.Modified, newTestType("bar")}, | ||
{watch.Deleted, newTestType("bar")}, | ||
{watch.Error, newTestType("error: blah")}, | ||
} | ||
|
||
consumer := func(w watch.Interface) { | ||
for _, expect := range table { | ||
By(fmt.Sprintf("Fixing up watch.EventType: %v and passing it on", expect.t)) | ||
got, ok := <-w.ResultChan() | ||
Expect(ok).To(BeTrue(), "closed early") | ||
Expect(expect.t).To(Equal(got.Type), "unexpected Event.Type or out-of-order Event") | ||
Expect(got.Object).To(BeAssignableToTypeOf(&metav1.PartialObjectMetadata{}), "unexpected Event.Object type") | ||
a := got.Object.(*metav1.PartialObjectMetadata) | ||
Expect(got.Object.GetObjectKind().GroupVersionKind()).To(Equal(expectedGVK), "GVK was not fixed up") | ||
expected := expect.s.DeepCopyObject() | ||
expected.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{}) | ||
actual := a.DeepCopyObject() | ||
actual.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{}) | ||
Expect(actual).To(Equal(expected), "unexpected change to the Object") | ||
} | ||
Eventually(w.ResultChan()).Should(BeClosed()) | ||
} | ||
|
||
sender := func() { | ||
f.Add(newTestType("foo")) | ||
f.Action(watch.Modified, newTestType("qux")) | ||
f.Modify(newTestType("bar")) | ||
f.Delete(newTestType("bar")) | ||
f.Error(newTestType("error: blah")) | ||
f.Stop() | ||
} | ||
|
||
go sender() | ||
consumer(gvkfw) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package internal | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"sigs.k8s.io/controller-runtime/pkg/envtest/printer" | ||
) | ||
|
||
func TestSource(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
suiteName := "Cache Internal Suite" | ||
RunSpecsWithDefaultAndCustomReporters(t, suiteName, []Reporter{printer.NewlineReporter{}, printer.NewProwReporter(suiteName)}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎉 Thanks for capturing all of that history!