@@ -27,23 +27,24 @@ import (
27
27
// API. For external information, it primarily reports the IP or host of the LoadBalancer Service exposing the
28
28
// Ingress Controller, or an external IP specified in the ConfigMap.
29
29
type statusUpdater struct {
30
- client kubernetes.Interface
31
- namespace string
32
- externalServiceName string
33
- externalStatusAddress string
34
- externalServiceAddresses []string
35
- externalServicePorts string
36
- bigIPAddress string
37
- bigIPPorts string
38
- externalEndpoints []v1.ExternalEndpoint
39
- status []api_v1.LoadBalancerIngress
40
- keyFunc func (obj interface {}) (string , error )
41
- ingressLister * storeToIngressLister
42
- virtualServerLister cache.Store
43
- virtualServerRouteLister cache.Store
44
- transportServerLister cache.Store
45
- policyLister cache.Store
46
- confClient k8s_nginx.Interface
30
+ client kubernetes.Interface
31
+ namespace string
32
+ externalServiceName string
33
+ externalStatusAddress string
34
+ externalServiceAddresses []string
35
+ externalServicePorts string
36
+ bigIPAddress string
37
+ bigIPPorts string
38
+ externalEndpoints []v1.ExternalEndpoint
39
+ externalListenerEndpoints []conf_v1alpha1.ExternalEndpoint
40
+ status []api_v1.LoadBalancerIngress
41
+ keyFunc func (obj interface {}) (string , error )
42
+ ingressLister * storeToIngressLister
43
+ virtualServerLister cache.Store
44
+ virtualServerRouteLister cache.Store
45
+ transportServerLister cache.Store
46
+ policyLister cache.Store
47
+ confClient k8s_nginx.Interface
47
48
}
48
49
49
50
func (su * statusUpdater ) UpdateExternalEndpointsForResources (resource []Resource ) error {
@@ -92,6 +93,11 @@ func (su *statusUpdater) UpdateExternalEndpointsForResource(r Resource) error {
92
93
if failed {
93
94
return fmt .Errorf ("not all Resources updated" )
94
95
}
96
+ case * TransportServerConfiguration :
97
+ err := su .updateTransportServerExternalEndpoints (impl .TransportServer )
98
+ if err != nil {
99
+ return fmt .Errorf ("not all Resources updated" )
100
+ }
95
101
}
96
102
97
103
return nil
@@ -284,6 +290,7 @@ func (su *statusUpdater) SaveStatusFromExternalStatus(externalStatusAddress stri
284
290
ips = append (ips , su .externalStatusAddress )
285
291
su .saveStatus (ips )
286
292
su .externalEndpoints = su .generateExternalEndpointsFromStatus (su .status )
293
+ su .externalListenerEndpoints = su .generateExternalListenerEndpointsFromStatus (su .status )
287
294
}
288
295
289
296
// ClearStatusFromExternalService clears the saved status from the External Service
@@ -304,6 +311,7 @@ func (su *statusUpdater) SaveStatusFromExternalService(svc *api_v1.Service) {
304
311
}
305
312
su .saveStatus (ips )
306
313
su .externalEndpoints = su .generateExternalEndpointsFromStatus (su .status )
314
+ su .externalListenerEndpoints = su .generateExternalListenerEndpointsFromStatus (su .status )
307
315
}
308
316
309
317
func (su * statusUpdater ) SaveStatusFromIngressLink (ip string ) {
@@ -318,6 +326,7 @@ func (su *statusUpdater) SaveStatusFromIngressLink(ip string) {
318
326
ips := []string {su .bigIPAddress }
319
327
su .saveStatus (ips )
320
328
su .externalEndpoints = su .generateExternalEndpointsFromStatus (su .status )
329
+ su .externalListenerEndpoints = su .generateExternalListenerEndpointsFromStatus (su .status )
321
330
}
322
331
323
332
func (su * statusUpdater ) ClearStatusFromIngressLink () {
@@ -332,6 +341,7 @@ func (su *statusUpdater) ClearStatusFromIngressLink() {
332
341
ips := []string {}
333
342
su .saveStatus (ips )
334
343
su .externalEndpoints = su .generateExternalEndpointsFromStatus (su .status )
344
+ su .externalListenerEndpoints = su .generateExternalListenerEndpointsFromStatus (su .status )
335
345
}
336
346
337
347
func (su * statusUpdater ) retryUpdateTransportServerStatus (tsCopy * conf_v1alpha1.TransportServer ) error {
@@ -415,7 +425,7 @@ func (su *statusUpdater) UpdateTransportServerStatus(ts *conf_v1alpha1.Transport
415
425
tsCopy .Status .State = state
416
426
tsCopy .Status .Reason = reason
417
427
tsCopy .Status .Message = message
418
- tsCopy .Status .ExternalEndpoints = toAlphaV1 ( su .externalEndpoints )
428
+ tsCopy .Status .ExternalEndpoints = su .externalListenerEndpoints
419
429
420
430
_ , err = su .confClient .K8sV1alpha1 ().TransportServers (tsCopy .Namespace ).UpdateStatus (context .TODO (), tsCopy , metav1.UpdateOptions {})
421
431
if err != nil {
@@ -425,18 +435,6 @@ func (su *statusUpdater) UpdateTransportServerStatus(ts *conf_v1alpha1.Transport
425
435
return err
426
436
}
427
437
428
- func toAlphaV1 (endpoints []v1.ExternalEndpoint ) []conf_v1alpha1.ExternalEndpoint {
429
- var alphaEndpoints []conf_v1alpha1.ExternalEndpoint
430
- for _ , endpoint := range endpoints {
431
- alphaEndpoint := conf_v1alpha1.ExternalEndpoint {
432
- IP : endpoint .IP ,
433
- Ports : endpoint .Ports ,
434
- }
435
- alphaEndpoints = append (alphaEndpoints , alphaEndpoint )
436
- }
437
- return alphaEndpoints
438
- }
439
-
440
438
func hasTsStatusChanged (ts * conf_v1alpha1.TransportServer , state string , reason string , message string ) bool {
441
439
if ts .Status .State != state {
442
440
return true
@@ -571,6 +569,28 @@ func (su *statusUpdater) UpdateVirtualServerRouteStatus(vsr *conf_v1.VirtualServ
571
569
return err
572
570
}
573
571
572
+ func (su * statusUpdater ) updateTransportServerExternalEndpoints (ts * conf_v1alpha1.TransportServer ) error {
573
+ tsLatest , exists , err := su .transportServerLister .Get (ts )
574
+ if err != nil {
575
+ glog .V (3 ).Infof ("error getting TransportServer from Store: %v" , err )
576
+ return err
577
+ }
578
+ if ! exists {
579
+ glog .V (3 ).Infof ("TransportServer doesn't exist in Store" )
580
+ return nil
581
+ }
582
+
583
+ tsCopy := tsLatest .(* conf_v1alpha1.TransportServer ).DeepCopy ()
584
+ tsCopy .Status .ExternalEndpoints = su .externalListenerEndpoints
585
+
586
+ _ , err = su .confClient .K8sV1alpha1 ().TransportServers (ts .Namespace ).UpdateStatus (context .TODO (), tsCopy , metav1.UpdateOptions {})
587
+ if err != nil {
588
+ glog .V (3 ).Infof ("error setting TransportServer %v/%v status, retrying: %v" , tsCopy .Namespace , tsCopy .Name , err )
589
+ return su .retryUpdateTransportServerStatus (tsCopy )
590
+ }
591
+ return err
592
+ }
593
+
574
594
func (su * statusUpdater ) updateVirtualServerExternalEndpoints (vs * conf_v1.VirtualServer ) error {
575
595
// Get a pristine VirtualServer from the Store
576
596
vsLatest , exists , err := su .virtualServerLister .Get (vs )
@@ -632,6 +652,21 @@ func (su *statusUpdater) generateExternalEndpointsFromStatus(status []api_v1.Loa
632
652
return externalEndpoints
633
653
}
634
654
655
+ func (su * statusUpdater ) generateExternalListenerEndpointsFromStatus (status []api_v1.LoadBalancerIngress ) []conf_v1alpha1.ExternalEndpoint {
656
+ var externalEndpoints []conf_v1alpha1.ExternalEndpoint
657
+ for _ , lb := range status {
658
+ port := su .externalServicePorts
659
+ if su .bigIPPorts != "" {
660
+ port = su .bigIPPorts
661
+ }
662
+
663
+ endpoint := conf_v1alpha1.ExternalEndpoint {IP : lb .IP , Port : port }
664
+ externalEndpoints = append (externalEndpoints , endpoint )
665
+ }
666
+
667
+ return externalEndpoints
668
+ }
669
+
635
670
func hasPolicyStatusChanged (pol * v1.Policy , state string , reason string , message string ) bool {
636
671
return pol .Status .State != state || pol .Status .Reason != reason || pol .Status .Message != message
637
672
}
0 commit comments