Skip to content

Commit 05c5747

Browse files
k8s-ci-robotshaneutt
authored andcommitted
Merge pull request #1707 from arkodg/supported-kinds-bug
Add explicit equality checks for SupportedKinds
1 parent a3e38ea commit 05c5747

File tree

2 files changed

+160
-6
lines changed

2 files changed

+160
-6
lines changed

conformance/utils/kubernetes/helpers.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
v1 "k8s.io/api/core/v1"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/types"
35-
"k8s.io/apimachinery/pkg/util/sets"
3635
"k8s.io/apimachinery/pkg/util/wait"
3736
"sigs.k8s.io/controller-runtime/pkg/client"
3837

@@ -636,12 +635,29 @@ func listenersMatch(t *testing.T, expected, actual []v1beta1.ListenerStatus) boo
636635
// Ensure that the expected Listener.SupportedKinds items are present in actual Listener.SupportedKinds
637636
// Find the items instead of performing an exact match of the slice because the implementation
638637
// might support more Kinds than defined in the test
639-
eSupportedKindsSet := sets.New(eListener.SupportedKinds...)
640-
aSupportedKindsSet := sets.New(aListener.SupportedKinds...)
641-
if !aSupportedKindsSet.IsSuperset(eSupportedKindsSet) {
642-
t.Logf("Expected %v kinds to be present in SupportedKinds", eSupportedKindsSet.Difference(aSupportedKindsSet))
643-
return false
638+
for _, eKind := range eListener.SupportedKinds {
639+
found := false
640+
641+
for _, aKind := range aListener.SupportedKinds {
642+
if eKind.Group == nil {
643+
eKind.Group = (*v1beta1.Group)(&v1beta1.GroupVersion.Group)
644+
}
645+
646+
if aKind.Group == nil {
647+
aKind.Group = (*v1beta1.Group)(&v1beta1.GroupVersion.Group)
648+
}
649+
650+
if *eKind.Group == *aKind.Group && eKind.Kind == aKind.Kind {
651+
found = true
652+
break
653+
}
654+
}
655+
if !found {
656+
t.Logf("Expected Group:%s Kind:%s to be present in SupportedKinds", *eKind.Group, eKind.Kind)
657+
return false
658+
}
644659
}
660+
645661
if aListener.AttachedRoutes != eListener.AttachedRoutes {
646662
t.Logf("Expected AttachedRoutes to be %v, got %v", eListener.AttachedRoutes, aListener.AttachedRoutes)
647663
return false
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package kubernetes
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
24+
"sigs.k8s.io/gateway-api/apis/v1alpha2"
25+
"sigs.k8s.io/gateway-api/apis/v1beta1"
26+
)
27+
28+
func Test_listenersMatch(t *testing.T) {
29+
tests := []struct {
30+
name string
31+
expected []v1beta1.ListenerStatus
32+
actual []v1beta1.ListenerStatus
33+
want bool
34+
}{
35+
{
36+
name: "SupportedKinds: expected empty and actual is non empty",
37+
expected: []v1beta1.ListenerStatus{
38+
{
39+
SupportedKinds: []v1beta1.RouteGroupKind{},
40+
},
41+
},
42+
actual: []v1beta1.ListenerStatus{
43+
{
44+
SupportedKinds: []v1beta1.RouteGroupKind{
45+
{
46+
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group),
47+
Kind: v1beta1.Kind("HTTPRoute"),
48+
},
49+
},
50+
},
51+
},
52+
want: false,
53+
},
54+
{
55+
name: "SupportedKinds: expected and actual are equal",
56+
expected: []v1beta1.ListenerStatus{
57+
{
58+
SupportedKinds: []v1beta1.RouteGroupKind{
59+
{
60+
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group),
61+
Kind: v1beta1.Kind("HTTPRoute"),
62+
},
63+
},
64+
},
65+
},
66+
actual: []v1beta1.ListenerStatus{
67+
{
68+
SupportedKinds: []v1beta1.RouteGroupKind{
69+
{
70+
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group),
71+
Kind: v1beta1.Kind("HTTPRoute"),
72+
},
73+
},
74+
},
75+
},
76+
want: true,
77+
},
78+
{
79+
name: "SupportedKinds: expected kind not found in actual",
80+
expected: []v1beta1.ListenerStatus{
81+
{
82+
SupportedKinds: []v1beta1.RouteGroupKind{
83+
{
84+
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group),
85+
Kind: v1beta1.Kind("HTTPRoute"),
86+
},
87+
},
88+
},
89+
},
90+
actual: []v1beta1.ListenerStatus{
91+
{
92+
SupportedKinds: []v1beta1.RouteGroupKind{
93+
{
94+
Group: (*v1beta1.Group)(&v1alpha2.GroupVersion.Group),
95+
Kind: v1beta1.Kind("GRPCRoute"),
96+
},
97+
},
98+
},
99+
},
100+
want: false,
101+
},
102+
{
103+
name: "SupportedKinds: expected is a subset of actual",
104+
expected: []v1beta1.ListenerStatus{
105+
{
106+
SupportedKinds: []v1beta1.RouteGroupKind{
107+
{
108+
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group),
109+
Kind: v1beta1.Kind("HTTPRoute"),
110+
},
111+
},
112+
},
113+
},
114+
actual: []v1beta1.ListenerStatus{
115+
{
116+
SupportedKinds: []v1beta1.RouteGroupKind{
117+
{
118+
Group: (*v1beta1.Group)(&v1alpha2.GroupVersion.Group),
119+
Kind: v1beta1.Kind("GRPCRoute"),
120+
},
121+
{
122+
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group),
123+
Kind: v1beta1.Kind("HTTPRoute"),
124+
},
125+
},
126+
},
127+
},
128+
want: true,
129+
},
130+
}
131+
132+
for _, test := range tests {
133+
test := test
134+
t.Run(test.name, func(t *testing.T) {
135+
assert.Equal(t, test.want, listenersMatch(t, test.expected, test.actual))
136+
})
137+
}
138+
}

0 commit comments

Comments
 (0)