@@ -24,10 +24,10 @@ import (
24
24
"text/template"
25
25
26
26
log "github.com/sirupsen/logrus"
27
- networkingv1alpha3 "istio.io/client-go/pkg/apis/networking/v1alpha3 "
27
+ networkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1 "
28
28
istioclient "istio.io/client-go/pkg/clientset/versioned"
29
29
istioinformers "istio.io/client-go/pkg/informers/externalversions"
30
- networkingv1alpha3informer "istio.io/client-go/pkg/informers/externalversions/networking/v1alpha3 "
30
+ networkingv1beta1informer "istio.io/client-go/pkg/informers/externalversions/networking/v1beta1 "
31
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
32
"k8s.io/apimachinery/pkg/labels"
33
33
kubeinformers "k8s.io/client-go/informers"
@@ -57,7 +57,7 @@ type gatewaySource struct {
57
57
combineFQDNAnnotation bool
58
58
ignoreHostnameAnnotation bool
59
59
serviceInformer coreinformers.ServiceInformer
60
- gatewayInformer networkingv1alpha3informer .GatewayInformer
60
+ gatewayInformer networkingv1beta1informer .GatewayInformer
61
61
}
62
62
63
63
// NewIstioGatewaySource creates a new gatewaySource with the given config.
@@ -81,18 +81,18 @@ func NewIstioGatewaySource(
81
81
informerFactory := kubeinformers .NewSharedInformerFactoryWithOptions (kubeClient , 0 , kubeinformers .WithNamespace (namespace ))
82
82
serviceInformer := informerFactory .Core ().V1 ().Services ()
83
83
istioInformerFactory := istioinformers .NewSharedInformerFactory (istioClient , 0 )
84
- gatewayInformer := istioInformerFactory .Networking ().V1alpha3 ().Gateways ()
84
+ gatewayInformer := istioInformerFactory .Networking ().V1beta1 ().Gateways ()
85
85
86
86
// Add default resource event handlers to properly initialize informer.
87
- serviceInformer .Informer ().AddEventHandler (
87
+ _ , _ = serviceInformer .Informer ().AddEventHandler (
88
88
cache.ResourceEventHandlerFuncs {
89
89
AddFunc : func (obj interface {}) {
90
90
log .Debug ("service added" )
91
91
},
92
92
},
93
93
)
94
94
95
- gatewayInformer .Informer ().AddEventHandler (
95
+ _ , _ = gatewayInformer .Informer ().AddEventHandler (
96
96
cache.ResourceEventHandlerFuncs {
97
97
AddFunc : func (obj interface {}) {
98
98
log .Debug ("gateway added" )
@@ -127,7 +127,7 @@ func NewIstioGatewaySource(
127
127
// Endpoints returns endpoint objects for each host-target combination that should be processed.
128
128
// Retrieves all gateway resources in the source's namespace(s).
129
129
func (sc * gatewaySource ) Endpoints (ctx context.Context ) ([]* endpoint.Endpoint , error ) {
130
- gwList , err := sc .istioClient .NetworkingV1alpha3 ().Gateways (sc .namespace ).List (ctx , metav1.ListOptions {})
130
+ gwList , err := sc .istioClient .NetworkingV1beta1 ().Gateways (sc .namespace ).List (ctx , metav1.ListOptions {})
131
131
if err != nil {
132
132
return nil , err
133
133
}
@@ -140,12 +140,14 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e
140
140
141
141
var endpoints []* endpoint.Endpoint
142
142
143
+ log .Debugf ("Found %d gateways in namespace %s" , len (gateways ), sc .namespace )
144
+
143
145
for _ , gateway := range gateways {
144
146
// Check controller annotation to see if we are responsible.
145
147
controller , ok := gateway .Annotations [controllerAnnotationKey ]
146
148
if ok && controller != controllerAnnotationValue {
147
- log .Debugf ("Skipping gateway %s/%s because controller value does not match, found: %s, required: %s" ,
148
- gateway .Namespace , gateway .Name , controller , controllerAnnotationValue )
149
+ log .Debugf ("Skipping gateway %s/%s,%s because controller value does not match, found: %s, required: %s" ,
150
+ gateway .Namespace , gateway .APIVersion , gateway . Name , controller , controllerAnnotationValue )
149
151
continue
150
152
}
151
153
@@ -168,6 +170,8 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e
168
170
}
169
171
}
170
172
173
+ log .Debugf ("Processing gateway '%s/%s.%s' and hosts %q" , gateway .Namespace , gateway .APIVersion , gateway .Name , strings .Join (gwHostnames , "," ))
174
+
171
175
if len (gwHostnames ) == 0 {
172
176
log .Debugf ("No hostnames could be generated from gateway %s/%s" , gateway .Namespace , gateway .Name )
173
177
continue
@@ -183,10 +187,11 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e
183
187
continue
184
188
}
185
189
186
- log .Debugf ("Endpoints generated from gateway: %s/%s: %v " , gateway .Namespace , gateway .Name , gwEndpoints )
190
+ log .Debugf ("Endpoints generated from %q ' %s/%s.%s' : %q " , gateway .Kind , gateway . Namespace , gateway . APIVersion , gateway .Name , gwEndpoints )
187
191
endpoints = append (endpoints , gwEndpoints ... )
188
192
}
189
193
194
+ // TODO: sort on endpoint creation
190
195
for _ , ep := range endpoints {
191
196
sort .Sort (ep .Targets )
192
197
}
@@ -198,11 +203,11 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e
198
203
func (sc * gatewaySource ) AddEventHandler (ctx context.Context , handler func ()) {
199
204
log .Debug ("Adding event handler for Istio Gateway" )
200
205
201
- sc .gatewayInformer .Informer ().AddEventHandler (eventHandlerFunc (handler ))
206
+ _ , _ = sc .gatewayInformer .Informer ().AddEventHandler (eventHandlerFunc (handler ))
202
207
}
203
208
204
209
// filterByAnnotations filters a list of configs by a given annotation selector.
205
- func (sc * gatewaySource ) filterByAnnotations (gateways []* networkingv1alpha3 .Gateway ) ([]* networkingv1alpha3 .Gateway , error ) {
210
+ func (sc * gatewaySource ) filterByAnnotations (gateways []* networkingv1beta1 .Gateway ) ([]* networkingv1beta1 .Gateway , error ) {
206
211
selector , err := annotations .ParseFilter (sc .annotationFilter )
207
212
if err != nil {
208
213
return nil , err
@@ -213,7 +218,7 @@ func (sc *gatewaySource) filterByAnnotations(gateways []*networkingv1alpha3.Gate
213
218
return gateways , nil
214
219
}
215
220
216
- var filteredList []* networkingv1alpha3 .Gateway
221
+ var filteredList []* networkingv1beta1 .Gateway
217
222
218
223
for _ , gw := range gateways {
219
224
// include if the annotations match the selector
@@ -225,7 +230,7 @@ func (sc *gatewaySource) filterByAnnotations(gateways []*networkingv1alpha3.Gate
225
230
return filteredList , nil
226
231
}
227
232
228
- func (sc * gatewaySource ) targetsFromIngress (ctx context.Context , ingressStr string , gateway * networkingv1alpha3 .Gateway ) (endpoint.Targets , error ) {
233
+ func (sc * gatewaySource ) targetsFromIngress (ctx context.Context , ingressStr string , gateway * networkingv1beta1 .Gateway ) (endpoint.Targets , error ) {
229
234
namespace , name , err := ParseIngress (ingressStr )
230
235
if err != nil {
231
236
return nil , fmt .Errorf ("failed to parse Ingress annotation on Gateway (%s/%s): %w" , gateway .Namespace , gateway .Name , err )
@@ -251,7 +256,7 @@ func (sc *gatewaySource) targetsFromIngress(ctx context.Context, ingressStr stri
251
256
return targets , nil
252
257
}
253
258
254
- func (sc * gatewaySource ) targetsFromGateway (ctx context.Context , gateway * networkingv1alpha3 .Gateway ) (endpoint.Targets , error ) {
259
+ func (sc * gatewaySource ) targetsFromGateway (ctx context.Context , gateway * networkingv1beta1 .Gateway ) (endpoint.Targets , error ) {
255
260
targets := annotations .TargetsFromTargetAnnotation (gateway .Annotations )
256
261
if len (targets ) > 0 {
257
262
return targets , nil
@@ -266,22 +271,21 @@ func (sc *gatewaySource) targetsFromGateway(ctx context.Context, gateway *networ
266
271
}
267
272
268
273
// endpointsFromGatewayConfig extracts the endpoints from an Istio Gateway Config object
269
- func (sc * gatewaySource ) endpointsFromGateway (ctx context.Context , hostnames []string , gateway * networkingv1alpha3 .Gateway ) ([]* endpoint.Endpoint , error ) {
274
+ func (sc * gatewaySource ) endpointsFromGateway (ctx context.Context , hostnames []string , gateway * networkingv1beta1 .Gateway ) ([]* endpoint.Endpoint , error ) {
270
275
var endpoints []* endpoint.Endpoint
271
276
var err error
272
277
273
- resource := fmt .Sprintf ("gateway/%s/%s" , gateway .Namespace , gateway .Name )
274
-
275
- ttl := annotations .TTLFromAnnotations (gateway .Annotations , resource )
278
+ targets , err := sc .targetsFromGateway (ctx , gateway )
279
+ if err != nil {
280
+ return nil , err
281
+ }
276
282
277
- targets := annotations .TargetsFromTargetAnnotation (gateway .Annotations )
278
283
if len (targets ) == 0 {
279
- targets , err = sc .targetsFromGateway (ctx , gateway )
280
- if err != nil {
281
- return nil , err
282
- }
284
+ return endpoints , nil
283
285
}
284
286
287
+ resource := fmt .Sprintf ("gateway/%s/%s" , gateway .Namespace , gateway .Name )
288
+ ttl := annotations .TTLFromAnnotations (gateway .Annotations , resource )
285
289
providerSpecific , setIdentifier := annotations .ProviderSpecificAnnotations (gateway .Annotations )
286
290
287
291
for _ , host := range hostnames {
@@ -291,7 +295,7 @@ func (sc *gatewaySource) endpointsFromGateway(ctx context.Context, hostnames []s
291
295
return endpoints , nil
292
296
}
293
297
294
- func (sc * gatewaySource ) hostNamesFromGateway (gateway * networkingv1alpha3 .Gateway ) ([]string , error ) {
298
+ func (sc * gatewaySource ) hostNamesFromGateway (gateway * networkingv1beta1 .Gateway ) ([]string , error ) {
295
299
var hostnames []string
296
300
for _ , server := range gateway .Spec .Servers {
297
301
for _ , host := range server .Hosts {
0 commit comments