Skip to content

Commit 1eab535

Browse files
authored
Bug fix - HasMatchingPlugin should return true for cases without wildcard (#653)
1 parent 6282e04 commit 1eab535

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pkg/podgrouper/podgrouper/hub/hub.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ func (ph *DefaultPluginsHub) GetDefaultPlugin() grouper.Grouper {
8282
}
8383

8484
func (ph *DefaultPluginsHub) HasMatchingPlugin(gvk metav1.GroupVersionKind) bool {
85-
// search using wildcard version - this hub will return a plugin even if the version is not exact match
85+
if _, found := ph.customPlugins[gvk]; found {
86+
return true
87+
}
88+
89+
// search using wildcard version
8690
gvk.Version = "*"
8791
if _, found := ph.customPlugins[gvk]; found {
8892
return true

pkg/podgrouper/podgrouper/hub/hub_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ var _ = Describe("SupportedTypes", func() {
4949
Expect(plugin.Name()).To(BeEquivalentTo("TensorFlow Grouper"))
5050
})
5151

52+
It("should return plugin for exact GVK match - HasMatchingPlugin function", func() {
53+
gvk := metav1.GroupVersionKind{
54+
Group: "kubeflow.org",
55+
Version: "v1",
56+
Kind: "TFJob",
57+
}
58+
hasPlugin := hub.HasMatchingPlugin(gvk)
59+
Expect(hasPlugin).To(BeTrue())
60+
})
61+
5262
It("should return default plugin for non-existent GVK", func() {
5363
gvk := metav1.GroupVersionKind{
5464
Group: "non-existent-group",
@@ -59,6 +69,16 @@ var _ = Describe("SupportedTypes", func() {
5969
Expect(plugin).NotTo(BeNil())
6070
Expect(plugin.Name()).To(BeEquivalentTo("Default Grouper"))
6171
})
72+
73+
It("non-existent GVK - HasMatchingPlugin returns false", func() {
74+
gvk := metav1.GroupVersionKind{
75+
Group: "non-existent-group",
76+
Version: "v1",
77+
Kind: "NonExistentKind",
78+
}
79+
hasPlugin := hub.HasMatchingPlugin(gvk)
80+
Expect(hasPlugin).To(BeFalse())
81+
})
6282
})
6383

6484
Context("Wildcard Version Tests", func() {

0 commit comments

Comments
 (0)