-
Notifications
You must be signed in to change notification settings - Fork 444
/
resource_clientset.go
283 lines (247 loc) · 8.13 KB
/
resource_clientset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package kube2e
import (
"context"
gatewayv1 "github.com/solo-io/gloo/projects/gateway/pkg/api/v1"
externalrl "github.com/solo-io/gloo/projects/gloo/pkg/api/external/solo/ratelimit"
gloov1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/gloo/test/helpers"
"github.com/solo-io/solo-kit/pkg/api/external/kubernetes/service"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/factory"
"github.com/solo-io/solo-kit/pkg/api/v1/clients/kube"
kubecache "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/cache"
skkube "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
var _ helpers.ResourceClientSet = new(KubeResourceClientSet)
// KubeResourceClientSet is a set of ResourceClients
type KubeResourceClientSet struct {
gatewayClient gatewayv1.GatewayClient
httpGatewayClient gatewayv1.MatchableHttpGatewayClient
virtualServiceClient gatewayv1.VirtualServiceClient
routeTableClient gatewayv1.RouteTableClient
virtualHostOptionClient gatewayv1.VirtualHostOptionClient
routeOptionClient gatewayv1.RouteOptionClient
upstreamGroupClient gloov1.UpstreamGroupClient
upstreamClient gloov1.UpstreamClient
proxyClient gloov1.ProxyClient
rateLimitConfigClient externalrl.RateLimitConfigClient
serviceClient skkube.ServiceClient
settingsClient gloov1.SettingsClient
kubeClient *kubernetes.Clientset
}
func NewKubeResourceClientSet(ctx context.Context, cfg *rest.Config) (*KubeResourceClientSet, error) {
resourceClientSet := &KubeResourceClientSet{}
kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
return nil, err
}
resourceClientSet.kubeClient = kubeClient
cache := kube.NewKubeCache(ctx)
kubeCoreCache, err := kubecache.NewKubeCoreCache(ctx, kubeClient)
if err != nil {
return nil, err
}
// Gateway
gatewayClientFactory := &factory.KubeResourceClientFactory{
Crd: gatewayv1.GatewayCrd,
Cfg: cfg,
SharedCache: cache,
}
gatewayClient, err := gatewayv1.NewGatewayClient(ctx, gatewayClientFactory)
if err != nil {
return nil, err
}
if err = gatewayClient.Register(); err != nil {
return nil, err
}
resourceClientSet.gatewayClient = gatewayClient
// HttpGateway
httpGatewayClientFactory := &factory.KubeResourceClientFactory{
Crd: gatewayv1.MatchableHttpGatewayCrd,
Cfg: cfg,
SharedCache: cache,
}
httpGatewayClient, err := gatewayv1.NewMatchableHttpGatewayClient(ctx, httpGatewayClientFactory)
if err != nil {
return nil, err
}
if err = httpGatewayClient.Register(); err != nil {
return nil, err
}
resourceClientSet.httpGatewayClient = httpGatewayClient
// VirtualService
virtualServiceClientFactory := &factory.KubeResourceClientFactory{
Crd: gatewayv1.VirtualServiceCrd,
Cfg: cfg,
SharedCache: cache,
}
virtualServiceClient, err := gatewayv1.NewVirtualServiceClient(ctx, virtualServiceClientFactory)
if err != nil {
return nil, err
}
if err = virtualServiceClient.Register(); err != nil {
return nil, err
}
resourceClientSet.virtualServiceClient = virtualServiceClient
// RouteTable
routeTableClientFactory := &factory.KubeResourceClientFactory{
Crd: gatewayv1.RouteTableCrd,
Cfg: cfg,
SharedCache: cache,
}
routeTableClient, err := gatewayv1.NewRouteTableClient(ctx, routeTableClientFactory)
if err != nil {
return nil, err
}
if err = routeTableClient.Register(); err != nil {
return nil, err
}
resourceClientSet.routeTableClient = routeTableClient
// UpstreamGroup
upstreamGroupClientFactory := &factory.KubeResourceClientFactory{
Crd: gloov1.UpstreamGroupCrd,
Cfg: cfg,
SharedCache: cache,
}
upstreamGroupClient, err := gloov1.NewUpstreamGroupClient(ctx, upstreamGroupClientFactory)
if err != nil {
return nil, err
}
if err = upstreamGroupClient.Register(); err != nil {
return nil, err
}
resourceClientSet.upstreamGroupClient = upstreamGroupClient
// Upstream
upstreamClientFactory := &factory.KubeResourceClientFactory{
Crd: gloov1.UpstreamCrd,
Cfg: cfg,
SharedCache: cache,
}
upstreamClient, err := gloov1.NewUpstreamClient(ctx, upstreamClientFactory)
if err != nil {
return nil, err
}
if err = upstreamClient.Register(); err != nil {
return nil, err
}
resourceClientSet.upstreamClient = upstreamClient
// Proxy
proxyClientFactory := &factory.KubeResourceClientFactory{
Crd: gloov1.ProxyCrd,
Cfg: cfg,
SharedCache: cache,
}
proxyClient, err := gloov1.NewProxyClient(ctx, proxyClientFactory)
if err != nil {
return nil, err
}
if err = proxyClient.Register(); err != nil {
return nil, err
}
resourceClientSet.proxyClient = proxyClient
// RateLimitConfig
rateLimitConfigClientFactory := &factory.KubeResourceClientFactory{
Crd: externalrl.RateLimitConfigCrd,
Cfg: cfg,
SharedCache: cache,
}
rateLimitConfigClient, err := externalrl.NewRateLimitConfigClient(ctx, rateLimitConfigClientFactory)
if err != nil {
return nil, err
}
if err = rateLimitConfigClient.Register(); err != nil {
return nil, err
}
resourceClientSet.rateLimitConfigClient = rateLimitConfigClient
// VirtualHostOption
virtualHostOptionClientFactory := &factory.KubeResourceClientFactory{
Crd: gatewayv1.VirtualHostOptionCrd,
Cfg: cfg,
SharedCache: cache,
}
virtualHostOptionClient, err := gatewayv1.NewVirtualHostOptionClient(ctx, virtualHostOptionClientFactory)
if err != nil {
return nil, err
}
if err = virtualHostOptionClient.Register(); err != nil {
return nil, err
}
resourceClientSet.virtualHostOptionClient = virtualHostOptionClient
// RouteOption
routeOptionClientFactory := &factory.KubeResourceClientFactory{
Crd: gatewayv1.RouteOptionCrd,
Cfg: cfg,
SharedCache: cache,
}
routeOptionClient, err := gatewayv1.NewRouteOptionClient(ctx, routeOptionClientFactory)
if err != nil {
return nil, err
}
if err = routeOptionClient.Register(); err != nil {
return nil, err
}
resourceClientSet.routeOptionClient = routeOptionClient
// Settings
settingsClientFactory := &factory.KubeResourceClientFactory{
Crd: gloov1.SettingsCrd,
Cfg: cfg,
SharedCache: kube.NewKubeCache(ctx),
}
settingsClient, err := gloov1.NewSettingsClient(ctx, settingsClientFactory)
if err != nil {
return nil, err
}
if err = settingsClient.Register(); err != nil {
return nil, err
}
resourceClientSet.settingsClient = settingsClient
// Kube Service
resourceClientSet.serviceClient = service.NewServiceClient(kubeClient, kubeCoreCache)
return resourceClientSet, nil
}
func (k KubeResourceClientSet) GatewayClient() gatewayv1.GatewayClient {
return k.gatewayClient
}
func (k KubeResourceClientSet) HttpGatewayClient() gatewayv1.MatchableHttpGatewayClient {
return k.httpGatewayClient
}
func (k KubeResourceClientSet) VirtualServiceClient() gatewayv1.VirtualServiceClient {
return k.virtualServiceClient
}
func (k KubeResourceClientSet) RouteTableClient() gatewayv1.RouteTableClient {
return k.routeTableClient
}
func (k KubeResourceClientSet) VirtualHostOptionClient() gatewayv1.VirtualHostOptionClient {
return k.virtualHostOptionClient
}
func (k KubeResourceClientSet) RouteOptionClient() gatewayv1.RouteOptionClient {
return k.routeOptionClient
}
func (k KubeResourceClientSet) UpstreamGroupClient() gloov1.UpstreamGroupClient {
return k.upstreamGroupClient
}
func (k KubeResourceClientSet) UpstreamClient() gloov1.UpstreamClient {
return k.upstreamClient
}
func (k KubeResourceClientSet) ProxyClient() gloov1.ProxyClient {
return k.proxyClient
}
func (k KubeResourceClientSet) RateLimitConfigClient() externalrl.RateLimitConfigClient {
return k.rateLimitConfigClient
}
func (k KubeResourceClientSet) SettingsClient() gloov1.SettingsClient {
return k.settingsClient
}
func (k KubeResourceClientSet) SecretClient() gloov1.SecretClient {
panic("unsupported")
}
func (k KubeResourceClientSet) ArtifactClient() gloov1.ArtifactClient {
panic("unsupported")
}
func (k KubeResourceClientSet) KubeClients() *kubernetes.Clientset {
return k.kubeClient
}
func (k KubeResourceClientSet) ServiceClient() skkube.ServiceClient {
return k.serviceClient
}