@@ -7,40 +7,23 @@ import (
7
7
. "github.com/onsi/ginkgo/v2"
8
8
. "github.com/onsi/gomega"
9
9
"github.com/solo-io/gloo/pkg/utils/kubeutils"
10
+ "github.com/solo-io/gloo/projects/gloo/pkg/defaults"
10
11
"github.com/solo-io/gloo/projects/gloo/pkg/syncer/setup"
11
12
"github.com/solo-io/solo-kit/pkg/api/v1/clients"
12
13
"github.com/solo-io/solo-kit/pkg/api/v1/clients/factory"
13
14
"github.com/solo-io/solo-kit/pkg/api/v1/clients/memory"
14
15
skkube "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes"
15
- skerrors "github.com/solo-io/solo-kit/pkg/errors"
16
16
"github.com/solo-io/solo-kit/pkg/utils/statusutils"
17
17
corev1 "k8s.io/api/core/v1"
18
18
)
19
19
20
- var _ = Describe ("ControlPlane" , func () {
21
-
22
- Context ("xds host" , func () {
23
-
24
- AfterEach (func () {
25
- err := os .Unsetenv (statusutils .PodNamespaceEnvName )
26
- Expect (err ).NotTo (HaveOccurred ())
27
- })
28
-
29
- It ("respects POD_NAMESPACE" , func () {
30
- err := os .Setenv (statusutils .PodNamespaceEnvName , "other-ns" )
31
- Expect (err ).NotTo (HaveOccurred ())
32
- xdsHost := setup .GetControlPlaneXdsHost ()
33
- Expect (xdsHost ).To (Equal ("gloo.other-ns.svc.cluster.local" ))
34
- })
35
-
36
- It ("uses default value when POD_NAMESPACE not set" , func () {
37
- xdsHost := setup .GetControlPlaneXdsHost ()
38
- Expect (xdsHost ).To (Equal ("gloo.gloo-system.svc.cluster.local" ))
39
- })
40
- })
20
+ const (
21
+ otherNS = "other-ns"
22
+ )
41
23
42
- Context ( "xds port " , func () {
24
+ var _ = Describe ( "ControlPlane " , func () {
43
25
26
+ Context ("xds service" , func () {
44
27
var (
45
28
ctx context.Context
46
29
svcClient skkube.ServiceClient
@@ -58,7 +41,8 @@ var _ = Describe("ControlPlane", func() {
58
41
svcClient , err = skkube .NewServiceClient (ctx , inMemoryFactory )
59
42
Expect (err ).NotTo (HaveOccurred ())
60
43
61
- svc1 = skkube .NewService ("gloo-system" , kubeutils .GlooServiceName )
44
+ svc1 = skkube .NewService (defaults .GlooSystem , kubeutils .GlooServiceName )
45
+ svc1 .Labels = kubeutils .GlooServiceLabels
62
46
svc1 .Spec = corev1.ServiceSpec {
63
47
Ports : []corev1.ServicePort {
64
48
{
@@ -68,7 +52,8 @@ var _ = Describe("ControlPlane", func() {
68
52
},
69
53
}
70
54
71
- svc2 = skkube .NewService ("other-ns" , kubeutils .GlooServiceName )
55
+ svc2 = skkube .NewService (otherNS , kubeutils .GlooServiceName )
56
+ svc2 .Labels = kubeutils .GlooServiceLabels
72
57
svc2 .Spec = corev1.ServiceSpec {
73
58
Ports : []corev1.ServicePort {
74
59
{
@@ -84,58 +69,92 @@ var _ = Describe("ControlPlane", func() {
84
69
Expect (err ).NotTo (HaveOccurred ())
85
70
})
86
71
87
- It ("returns xds port from gloo service in default namespace" , func () {
72
+ It ("returns xds service from gloo service in default namespace" , func () {
88
73
// write both services
89
74
_ , err = svcClient .Write (svc1 , clients.WriteOpts {Ctx : ctx })
90
75
Expect (err ).NotTo (HaveOccurred ())
91
76
_ , err = svcClient .Write (svc2 , clients.WriteOpts {Ctx : ctx })
92
77
Expect (err ).NotTo (HaveOccurred ())
93
78
94
79
// should return the port from gloo service in gloo-system
95
- port , err := setup .GetControlPlaneXdsPort (ctx , svcClient )
80
+ service , err := setup .GetControlPlaneService (ctx , defaults . GlooSystem , svcClient )
96
81
Expect (err ).NotTo (HaveOccurred ())
97
- Expect (port ).To (Equal (int32 (1111 )))
82
+ Expect (service ).NotTo (BeNil ())
83
+ Expect (service .Name ).To (Equal (svc1 .Name ))
84
+ Expect (service .Namespace ).To (Equal (svc1 .Namespace ))
98
85
})
99
86
100
- It ("returns xds port from gloo service in POD_NAMESPACE namespace" , func () {
101
- err := os .Setenv (statusutils .PodNamespaceEnvName , "other-ns" )
102
- Expect (err ).NotTo (HaveOccurred ())
103
-
104
- // write both services
87
+ It ("returns error when no gloo service exists in the namespace" , func () {
88
+ // only write svc1
105
89
_ , err = svcClient .Write (svc1 , clients.WriteOpts {Ctx : ctx })
106
90
Expect (err ).NotTo (HaveOccurred ())
107
- _ , err = svcClient .Write (svc2 , clients.WriteOpts {Ctx : ctx })
108
- Expect (err ).NotTo (HaveOccurred ())
109
91
110
- // should return the port from gloo service in other-ns
111
- port , err := setup .GetControlPlaneXdsPort (ctx , svcClient )
112
- Expect (err ).NotTo (HaveOccurred ())
113
- Expect (port ).To (Equal (int32 (2222 )))
92
+ _ , err = setup .GetControlPlaneService (ctx , "another-ns" , svcClient )
93
+ Expect (err ).To (HaveOccurred ())
94
+ Expect (err ).To (MatchError (setup .NoGlooSvcFoundError ))
114
95
})
115
96
116
- It ("returns error when no gloo service exists in the POD_NAMESPACE namespace" , func () {
117
- err := os .Setenv (statusutils .PodNamespaceEnvName , "other-ns" )
118
- Expect (err ).NotTo (HaveOccurred ())
97
+ It ("returns error when multiple gloo services exist in the namespace" , func () {
98
+ dupeSvc := skkube .NewService ("other-ns" , "duplicate-gloo-service" )
99
+ dupeSvc .Labels = kubeutils .GlooServiceLabels
100
+ dupeSvc .Spec = corev1.ServiceSpec {
101
+ Ports : []corev1.ServicePort {
102
+ {
103
+ Name : kubeutils .GlooXdsPortName ,
104
+ Port : 3333 ,
105
+ },
106
+ },
107
+ }
119
108
120
- // only write svc1
121
- _ , err = svcClient .Write (svc1 , clients.WriteOpts {Ctx : ctx })
109
+ // write both services
110
+ _ , err = svcClient .Write (svc2 , clients.WriteOpts {Ctx : ctx })
111
+ Expect (err ).NotTo (HaveOccurred ())
112
+ _ , err = svcClient .Write (dupeSvc , clients.WriteOpts {Ctx : ctx })
122
113
Expect (err ).NotTo (HaveOccurred ())
123
114
124
- _ , err = setup .GetControlPlaneXdsPort (ctx , svcClient )
115
+ _ , err = setup .GetControlPlaneService (ctx , otherNS , svcClient )
125
116
Expect (err ).To (HaveOccurred ())
126
- Expect (skerrors . IsNotExist ( err )) .To (BeTrue ( ))
117
+ Expect (err ).To (MatchError ( setup . MultipleGlooSvcFoundError ))
127
118
})
119
+ })
128
120
129
- It ("returns error when the expected port name is not found" , func () {
130
- err := os .Setenv (statusutils .PodNamespaceEnvName , "other-ns" )
131
- Expect (err ).NotTo (HaveOccurred ())
121
+ Context ("xds host" , func () {
122
+ It ("get FQDN for service" , func () {
123
+ svc := skkube .NewService (defaults .GlooSystem , kubeutils .GlooServiceName )
124
+ xdsHost := setup .GetControlPlaneXdsHost (svc )
125
+ Expect (xdsHost ).To (Equal ("gloo.gloo-system.svc.cluster.local" ))
126
+ })
127
+ })
132
128
133
- // modify the port name
134
- svc2 .Spec .Ports [0 ].Name = "test-name"
135
- _ , err = svcClient .Write (svc2 , clients.WriteOpts {Ctx : ctx })
129
+ Context ("xds port" , func () {
130
+ It ("returns xds port" , func () {
131
+ svc := skkube .NewService (defaults .GlooSystem , kubeutils .GlooServiceName )
132
+ svc .Spec = corev1.ServiceSpec {
133
+ Ports : []corev1.ServicePort {
134
+ {
135
+ Name : kubeutils .GlooXdsPortName ,
136
+ Port : 1111 ,
137
+ },
138
+ },
139
+ }
140
+
141
+ port , err := setup .GetControlPlaneXdsPort (svc )
136
142
Expect (err ).NotTo (HaveOccurred ())
143
+ Expect (port ).To (Equal (int32 (1111 )))
144
+ })
145
+
146
+ It ("returns error when the expected port name is not found" , func () {
147
+ svc := skkube .NewService (defaults .GlooSystem , kubeutils .GlooServiceName )
148
+ svc .Spec = corev1.ServiceSpec {
149
+ Ports : []corev1.ServicePort {
150
+ {
151
+ Name : "not-the-right-name" ,
152
+ Port : 1111 ,
153
+ },
154
+ },
155
+ }
137
156
138
- _ , err = setup .GetControlPlaneXdsPort (ctx , svcClient )
157
+ _ , err : = setup .GetControlPlaneXdsPort (svc )
139
158
Expect (err ).To (HaveOccurred ())
140
159
Expect (err ).To (MatchError (setup .NoXdsPortFoundError ))
141
160
})
0 commit comments