Skip to content

Commit eabd986

Browse files
remove panic (#2448)
Signed-off-by: akihikokuroda <[email protected]>
1 parent f254e91 commit eabd986

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

test/e2e/csv_e2e_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import (
1616
rbacv1 "k8s.io/api/rbac/v1"
1717
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
1818
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
19+
"k8s.io/apimachinery/pkg/api/equality"
1920
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
k8slabels "k8s.io/apimachinery/pkg/labels"
2223
"k8s.io/apimachinery/pkg/runtime"
24+
"k8s.io/apimachinery/pkg/util/diff"
2325
"k8s.io/apimachinery/pkg/util/intstr"
2426
"k8s.io/apimachinery/pkg/util/wait"
2527
"k8s.io/apimachinery/pkg/watch"
@@ -1551,7 +1553,7 @@ var _ = Describe("ClusterServiceVersion", func() {
15511553
// Fetch cluster service version again to check for unnecessary control loops
15521554
sameCSV, err := fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
15531555
Expect(err).ShouldNot(HaveOccurred())
1554-
compareResources(GinkgoT(), fetchedCSV, sameCSV)
1556+
Expect(equality.Semantic.DeepEqual(fetchedCSV, sameCSV)).Should(BeTrue(), diff.ObjectDiff(fetchedCSV, sameCSV))
15551557
})
15561558
It("create with owned API service", func() {
15571559

@@ -2547,7 +2549,7 @@ var _ = Describe("ClusterServiceVersion", func() {
25472549
// Fetch cluster service version again to check for unnecessary control loops
25482550
sameCSV, err := fetchCSV(crc, csvNew.Name, testNamespace, csvSucceededChecker)
25492551
Expect(err).ShouldNot(HaveOccurred())
2550-
compareResources(GinkgoT(), fetchedCSV, sameCSV)
2552+
Expect(equality.Semantic.DeepEqual(fetchedCSV, sameCSV)).Should(BeTrue(), diff.ObjectDiff(fetchedCSV, sameCSV))
25512553
})
25522554
It("update different deployment name", func() {
25532555

@@ -2725,7 +2727,7 @@ var _ = Describe("ClusterServiceVersion", func() {
27252727
// Fetch cluster service version again to check for unnecessary control loops
27262728
sameCSV, err := fetchCSV(crc, csvNew.Name, testNamespace, csvSucceededChecker)
27272729
Expect(err).ShouldNot(HaveOccurred())
2728-
compareResources(GinkgoT(), fetchedCSV, sameCSV)
2730+
Expect(equality.Semantic.DeepEqual(fetchedCSV, sameCSV)).Should(BeTrue(), diff.ObjectDiff(fetchedCSV, sameCSV))
27292731

27302732
// Should have created new deployment and deleted old
27312733
depNew, err := c.GetDeployment(testNamespace, strategyNew.DeploymentSpecs[0].Name)
@@ -2915,7 +2917,7 @@ var _ = Describe("ClusterServiceVersion", func() {
29152917
// Fetch cluster service version again to check for unnecessary control loops
29162918
sameCSV, err := fetchCSV(crc, csvNew.Name, testNamespace, csvSucceededChecker)
29172919
Expect(err).ShouldNot(HaveOccurred())
2918-
compareResources(GinkgoT(), fetchedCSV, sameCSV)
2920+
Expect(equality.Semantic.DeepEqual(fetchedCSV, sameCSV)).Should(BeTrue(), diff.ObjectDiff(fetchedCSV, sameCSV))
29192921

29202922
// Should have created new deployment and deleted old
29212923
depNew, err := c.GetDeployment(testNamespace, strategyNew.DeploymentSpecs[0].Name)
@@ -3285,7 +3287,7 @@ var _ = Describe("ClusterServiceVersion", func() {
32853287
// Fetch cluster service version again to check for unnecessary control loops
32863288
sameCSV, err := fetchCSV(crc, csvNew.Name, testNamespace, csvSucceededChecker)
32873289
Expect(err).ShouldNot(HaveOccurred())
3288-
compareResources(GinkgoT(), fetchedCSV, sameCSV)
3290+
Expect(equality.Semantic.DeepEqual(fetchedCSV, sameCSV)).Should(BeTrue(), diff.ObjectDiff(fetchedCSV, sameCSV))
32893291

32903292
// Should have created new deployment and deleted old one
32913293
depNew, err := c.GetDeployment(testNamespace, strategyNew.DeploymentSpecs[0].Name)
@@ -3364,7 +3366,7 @@ var _ = Describe("ClusterServiceVersion", func() {
33643366
// Fetch cluster service version again to check for unnecessary control loops
33653367
sameCSV, err = fetchCSV(crc, csvNew2.Name, testNamespace, csvSucceededChecker)
33663368
Expect(err).ShouldNot(HaveOccurred())
3367-
compareResources(GinkgoT(), fetchedCSV, sameCSV)
3369+
Expect(equality.Semantic.DeepEqual(fetchedCSV, sameCSV)).Should(BeTrue(), diff.ObjectDiff(fetchedCSV, sameCSV))
33683370

33693371
// Should have created new deployment and deleted old one
33703372
depNew, err = c.GetDeployment(testNamespace, strategyNew2.DeploymentSpecs[0].Name)

test/e2e/installplan_e2e_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import (
2525
rbacv1 "k8s.io/api/rbac/v1"
2626
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
2727
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
28+
"k8s.io/apimachinery/pkg/api/equality"
2829
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2930
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3132
"k8s.io/apimachinery/pkg/runtime"
3233
k8sjson "k8s.io/apimachinery/pkg/runtime/serializer/json"
34+
"k8s.io/apimachinery/pkg/util/diff"
3335
"k8s.io/apimachinery/pkg/util/wait"
3436
"k8s.io/apimachinery/pkg/watch"
3537
"k8s.io/client-go/discovery"
@@ -712,8 +714,8 @@ var _ = Describe("Install Plan", func() {
712714
// Fetch installplan again to check for unnecessary control loops
713715
fetchedInstallPlan, err = fetchInstallPlan(GinkgoT(), crc, fetchedInstallPlan.GetName(), func(fip *operatorsv1alpha1.InstallPlan) bool {
714716
// Don't compare object meta as labels can be applied by the operator controller.
715-
compareResources(GinkgoT(), fetchedInstallPlan.Spec, fip.Spec)
716-
compareResources(GinkgoT(), fetchedInstallPlan.Status, fip.Status)
717+
Expect(equality.Semantic.DeepEqual(fetchedInstallPlan.Spec, fip.Spec)).Should(BeTrue(), diff.ObjectDiff(fetchedInstallPlan, fip))
718+
Expect(equality.Semantic.DeepEqual(fetchedInstallPlan.Status, fip.Status)).Should(BeTrue(), diff.ObjectDiff(fetchedInstallPlan, fip))
717719
return true
718720
})
719721
require.NoError(GinkgoT(), err)
@@ -875,7 +877,7 @@ var _ = Describe("Install Plan", func() {
875877

876878
// Fetch installplan again to check for unnecessary control loops
877879
fetchedInstallPlan, err = fetchInstallPlan(GinkgoT(), crc, fetchedInstallPlan.GetName(), func(fip *operatorsv1alpha1.InstallPlan) bool {
878-
compareResources(GinkgoT(), fetchedInstallPlan, fip)
880+
Expect(equality.Semantic.DeepEqual(fetchedInstallPlan, fip)).Should(BeTrue(), diff.ObjectDiff(fetchedInstallPlan, fip))
879881
return true
880882
})
881883
require.NoError(GinkgoT(), err)
@@ -2343,7 +2345,7 @@ var _ = Describe("Install Plan", func() {
23432345

23442346
// Fetch installplan again to check for unnecessary control loops
23452347
fetchedInstallPlan, err = fetchInstallPlan(GinkgoT(), crc, fetchedInstallPlan.GetName(), func(fip *operatorsv1alpha1.InstallPlan) bool {
2346-
compareResources(GinkgoT(), fetchedInstallPlan, fip)
2348+
Expect(equality.Semantic.DeepEqual(fetchedInstallPlan, fip)).Should(BeTrue(), diff.ObjectDiff(fetchedInstallPlan, fip))
23472349
return true
23482350
})
23492351
require.NoError(GinkgoT(), err)
@@ -2544,7 +2546,7 @@ var _ = Describe("Install Plan", func() {
25442546

25452547
// Fetch installplan again to check for unnecessary control loops
25462548
fetchedInstallPlan, err = fetchInstallPlan(GinkgoT(), crc, fetchedInstallPlan.GetName(), func(fip *operatorsv1alpha1.InstallPlan) bool {
2547-
compareResources(GinkgoT(), fetchedInstallPlan, fip)
2549+
Expect(equality.Semantic.DeepEqual(fetchedInstallPlan, fip)).Should(BeTrue(), diff.ObjectDiff(fetchedInstallPlan, fip))
25482550
return true
25492551
})
25502552
require.NoError(GinkgoT(), err)

test/e2e/util_test.go

-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
1818
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1919
extScheme "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/scheme"
20-
"k8s.io/apimachinery/pkg/api/equality"
2120
apierrors "k8s.io/apimachinery/pkg/api/errors"
2221
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2322
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -26,7 +25,6 @@ import (
2625
"k8s.io/apimachinery/pkg/runtime/schema"
2726
k8sjson "k8s.io/apimachinery/pkg/runtime/serializer/json"
2827
"k8s.io/apimachinery/pkg/types"
29-
"k8s.io/apimachinery/pkg/util/diff"
3028
"k8s.io/apimachinery/pkg/util/wait"
3129
"k8s.io/apimachinery/pkg/watch"
3230
"k8s.io/apiserver/pkg/storage/names"
@@ -226,14 +224,6 @@ func awaitAnnotations(t GinkgoTInterface, query func() (metav1.ObjectMeta, error
226224
return err
227225
}
228226

229-
// compareResources compares resource equality then prints a diff for easier debugging
230-
func compareResources(t GinkgoTInterface, expected, actual interface{}) {
231-
if eq := equality.Semantic.DeepEqual(expected, actual); !eq {
232-
t.Fatalf("Resource does not match expected value: %s",
233-
diff.ObjectDiff(expected, actual))
234-
}
235-
}
236-
237227
type checkResourceFunc func() error
238228

239229
func waitForDelete(checkResource checkResourceFunc) error {

0 commit comments

Comments
 (0)