-
Notifications
You must be signed in to change notification settings - Fork 432
/
resource_clientset.go
191 lines (173 loc) · 5.62 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
package kube2e
import (
"context"
gatewayv1 "github.com/solo-io/gloo/projects/gateway/pkg/api/v1"
gloov1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/gloo/projects/gloo/pkg/api/v1/gloosnapshot"
"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"
)
// ResourceClientSet is a set of ResourceClients
type ResourceClientSet 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
ServiceClient skkube.ServiceClient
}
func NewKubeResourceClientSet(ctx context.Context, cfg *rest.Config) (*ResourceClientSet, error) {
resourceClientSet := &ResourceClientSet{}
kubeClient, err := kubernetes.NewForConfig(cfg)
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
// 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
// Kube Service
resourceClientSet.ServiceClient = service.NewServiceClient(kubeClient, kubeCoreCache)
return resourceClientSet, nil
}
func (r ResourceClientSet) WriteSnapshot(ctx context.Context, snapshot *gloosnapshot.ApiSnapshot) error {
// TODO
return nil
}
func (r ResourceClientSet) DeleteSnapshot(ctx context.Context, snapshot *gloosnapshot.ApiSnapshot) error {
// TODO
return nil
}