@@ -2,12 +2,14 @@ package route_delegation
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"net/http"
6
7
"time"
7
8
8
9
. "github.com/onsi/gomega"
9
10
"github.com/stretchr/testify/assert"
10
11
"github.com/stretchr/testify/suite"
12
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
13
"k8s.io/apimachinery/pkg/types"
12
14
"sigs.k8s.io/controller-runtime/pkg/client"
13
15
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
@@ -16,7 +18,6 @@ import (
16
18
testmatchers "github.com/solo-io/gloo/test/gomega/matchers"
17
19
"github.com/solo-io/gloo/test/kubernetes/e2e"
18
20
"github.com/solo-io/gloo/test/kubernetes/e2e/defaults"
19
- "github.com/solo-io/gloo/test/kubernetes/testutils/gloogateway"
20
21
)
21
22
22
23
var _ e2e.NewSuiteFunc = NewTestingSuite
@@ -33,6 +34,9 @@ type tsuite struct {
33
34
manifests map [string ][]string
34
35
35
36
manifestObjects map [string ][]client.Object
37
+
38
+ // resources from common manifest
39
+ commonResources []client.Object
36
40
}
37
41
38
42
func NewTestingSuite (ctx context.Context , testInst * e2e.TestInstallation ) suite.TestingSuite {
@@ -44,21 +48,20 @@ func NewTestingSuite(ctx context.Context, testInst *e2e.TestInstallation) suite.
44
48
45
49
func (s * tsuite ) SetupSuite () {
46
50
s .manifests = map [string ][]string {
47
- "TestBasic" : {commonManifest , basicRoutesManifest },
48
- "TestRecursive" : {commonManifest , recursiveRoutesManifest },
49
- "TestCyclic" : {commonManifest , cyclicRoutesManifest },
50
- "TestInvalidChild" : {commonManifest , invalidChildRoutesManifest },
51
- "TestHeaderQueryMatch" : {commonManifest , headerQueryMatchRoutesManifest },
52
- "TestMultipleParents" : {commonManifest , multipleParentsManifest },
53
- "TestInvalidChildValidStandalone" : {commonManifest , invalidChildValidStandaloneManifest },
54
- "TestUnresolvedChild" : {commonManifest , unresolvedChildManifest },
55
- "TestRouteOptions" : {commonManifest , routeOptionsManifest },
56
- "TestMatcherInheritance" : {commonManifest , matcherInheritanceManifest },
51
+ "TestBasic" : {basicRoutesManifest },
52
+ "TestRecursive" : {recursiveRoutesManifest },
53
+ "TestCyclic" : {cyclicRoutesManifest },
54
+ "TestInvalidChild" : {invalidChildRoutesManifest },
55
+ "TestHeaderQueryMatch" : {headerQueryMatchRoutesManifest },
56
+ "TestMultipleParents" : {multipleParentsManifest },
57
+ "TestInvalidChildValidStandalone" : {invalidChildValidStandaloneManifest },
58
+ "TestUnresolvedChild" : {unresolvedChildManifest },
59
+ "TestRouteOptions" : {routeOptionsManifest },
60
+ "TestMatcherInheritance" : {matcherInheritanceManifest },
57
61
}
58
62
// Not every resource that is applied needs to be verified. We are not testing `kubectl apply`,
59
63
// but the below code demonstrates how it can be done if necessary
60
64
s .manifestObjects = map [string ][]client.Object {
61
- commonManifest : {proxyService , proxyDeployment , defaults .CurlPod , httpbinTeam1 , httpbinTeam2 , gateway },
62
65
basicRoutesManifest : {routeRoot , routeTeam1 , routeTeam2 },
63
66
cyclicRoutesManifest : {routeRoot , routeTeam1 , routeTeam2 },
64
67
recursiveRoutesManifest : {routeRoot , routeTeam1 , routeTeam2 },
@@ -70,13 +73,56 @@ func (s *tsuite) SetupSuite() {
70
73
routeOptionsManifest : {routeRoot , routeTeam1 , routeTeam2 },
71
74
matcherInheritanceManifest : {routeParent1 , routeParent2 , routeTeam1 },
72
75
}
73
- clients , err := gloogateway .NewResourceClients (s .ctx , s .ti .ClusterContext )
74
- s .Require ().NoError (err )
75
- s .ti .ResourceClients = clients
76
+
77
+ s .commonResources = []client.Object {
78
+ // resources from manifest
79
+ httpbinTeam1Service , httpbinTeam1Deployment , httpbinTeam2Service , httpbinTeam2Deployment , gateway ,
80
+ // deployer-generated resources
81
+ proxyDeployment , proxyService ,
82
+ }
83
+
84
+ // set up common resources once
85
+ err := s .ti .Actions .Kubectl ().ApplyFile (s .ctx , commonManifest )
86
+ s .Require ().NoError (err , "can apply common manifest" )
87
+ s .ti .Assertions .EventuallyObjectsExist (s .ctx , s .commonResources ... )
88
+ // make sure pods are running
89
+ s .ti .Assertions .EventuallyPodsRunning (s .ctx , httpbinTeam1Deployment .GetNamespace (), metav1.ListOptions {
90
+ LabelSelector : "app=httpbin,version=v1" ,
91
+ })
92
+ s .ti .Assertions .EventuallyPodsRunning (s .ctx , httpbinTeam2Deployment .GetNamespace (), metav1.ListOptions {
93
+ LabelSelector : "app=httpbin,version=v2" ,
94
+ })
95
+ s .ti .Assertions .EventuallyPodsRunning (s .ctx , proxyMeta .GetNamespace (), metav1.ListOptions {
96
+ LabelSelector : fmt .Sprintf ("app.kubernetes.io/name=%s" , proxyMeta .GetName ()),
97
+ })
98
+
99
+ // set up curl once
100
+ err = s .ti .Actions .Kubectl ().ApplyFile (s .ctx , defaults .CurlPodManifest )
101
+ s .Require ().NoError (err , "can apply curl pod manifest" )
102
+ s .ti .Assertions .EventuallyPodsRunning (s .ctx , defaults .CurlPod .GetNamespace (), metav1.ListOptions {
103
+ LabelSelector : defaults .CurlPodLabelSelector ,
104
+ })
76
105
}
77
106
78
107
func (s * tsuite ) TearDownSuite () {
79
- // nothing at the moment
108
+ // clean up curl
109
+ err := s .ti .Actions .Kubectl ().DeleteFileSafe (s .ctx , defaults .CurlPodManifest )
110
+ s .Require ().NoError (err , "can delete curl pod manifest" )
111
+ s .ti .Assertions .EventuallyObjectsNotExist (s .ctx , defaults .CurlPod )
112
+
113
+ // clean up common resources
114
+ err = s .ti .Actions .Kubectl ().DeleteFileSafe (s .ctx , commonManifest )
115
+ s .Require ().NoError (err , "can delete common manifest" )
116
+ s .ti .Assertions .EventuallyObjectsNotExist (s .ctx , s .commonResources ... )
117
+ s .ti .Assertions .EventuallyPodsNotExist (s .ctx , httpbinTeam1Deployment .GetNamespace (), metav1.ListOptions {
118
+ LabelSelector : "app=httpbin,version=v1" ,
119
+ })
120
+ s .ti .Assertions .EventuallyPodsNotExist (s .ctx , httpbinTeam2Deployment .GetNamespace (), metav1.ListOptions {
121
+ LabelSelector : "app=httpbin,version=v2" ,
122
+ })
123
+ s .ti .Assertions .EventuallyPodsNotExist (s .ctx , proxyMeta .GetNamespace (), metav1.ListOptions {
124
+ LabelSelector : fmt .Sprintf ("app.kubernetes.io/name=%s" , proxyMeta .GetName ()),
125
+ })
80
126
}
81
127
82
128
func (s * tsuite ) BeforeTest (suiteName , testName string ) {
0 commit comments