Skip to content

Commit f3313af

Browse files
committed
BUG/MINOR: add k8s logs and fix k8s resync for endpoints and endpointslices
1 parent 98c8d3f commit f3313af

File tree

6 files changed

+58
-73
lines changed

6 files changed

+58
-73
lines changed

pkg/haproxy/api/runtime.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ func (c *clientNative) SyncBackendSrvs(backend *store.RuntimeBackend, portUpdate
8383
if backend.Name == "" {
8484
return nil
8585
}
86-
logger.Tracef("updating backend %s for haproxy servers update (address and state) through socket", backend.Name)
86+
logger.Tracef("[RUNTIME] [BACKEND] [SERVER] updating backend %s for haproxy servers update (address and state) through socket", backend.Name)
8787
haproxySrvs := backend.HAProxySrvs
8888
addresses := backend.Endpoints.Addresses
89-
logger.Tracef("backend %s: list of servers %+v", backend.Name, haproxySrvs)
90-
logger.Tracef("backend %s: list of endpoints addresses %+v", backend.Name, addresses)
89+
logger.Tracef("[RUNTIME] [BACKEND] [SERVER] backend %s: list of servers %+v", backend.Name, haproxySrvs)
90+
logger.Tracef("[RUNTIME] [BACKEND] [SERVER] backend %s: list of endpoints addresses %+v", backend.Name, addresses)
9191
// Disable stale entries from HAProxySrvs
9292
// and provide list of Disabled Srvs
9393
var disabled []*store.HAProxySrv
@@ -114,8 +114,8 @@ func (c *clientNative) SyncBackendSrvs(backend *store.RuntimeBackend, portUpdate
114114
delete(addresses, newAddr)
115115
}
116116

117-
logger.Tracef("backend %s: list of servers after treatment %+v", backend.Name, haproxySrvs)
118-
logger.Tracef("backend %s: list of endpoints addresses after treatment %+v", backend.Name, addresses)
117+
logger.Tracef("[RUNTIME] [BACKEND] [SERVER] backend %s: list of servers after treatment %+v", backend.Name, haproxySrvs)
118+
logger.Tracef("[RUNTIME] [BACKEND] [SERVER] backend %s: list of endpoints addresses after treatment %+v", backend.Name, addresses)
119119

120120
// Dynamically updates HAProxy backend servers with HAProxySrvs content
121121
var addrErr, stateErr error
@@ -124,18 +124,19 @@ func (c *clientNative) SyncBackendSrvs(backend *store.RuntimeBackend, portUpdate
124124
continue
125125
}
126126
if srv.Address == "" {
127-
logger.Tracef("backend %s: server '%s' changed status to %v", backend.Name, srv.Name, "maint")
127+
logger.Tracef("[RUNTIME] [BACKEND] [SERVER] [SOCKET] backend %s: server '%s' changed status to %v", backend.Name, srv.Name, "maint")
128128
addrErr = c.SetServerAddr(backend.Name, srv.Name, "127.0.0.1", 0)
129129
stateErr = c.SetServerState(backend.Name, srv.Name, "maint")
130130
} else {
131-
logger.Tracef("backend %s: server '%s' changed status to %v", backend.Name, srv.Name, "ready")
131+
logger.Tracef("[RUNTIME] [BACKEND] [SERVER] [SOCKET] backend %s: server '%s': addr '%s' changed status to %v", backend.Name, srv.Name, srv.Address, "ready")
132132
addrErr = c.SetServerAddr(backend.Name, srv.Name, srv.Address, int(backend.Endpoints.Port))
133133
stateErr = c.SetServerState(backend.Name, srv.Name, "ready")
134134
}
135135
if addrErr != nil || stateErr != nil {
136136
backend.DynUpdateFailed = true
137137
errors.Add(addrErr)
138138
errors.Add(stateErr)
139+
logger.Errorf("[RUNTIME] [BACKEND] [SERVER] [SOCKET] backend %s: server '%s': addr '%s': addrError '%v': stateError: '%v'", backend.Name, srv.Name, srv.Address, addrErr, stateErr)
139140
}
140141
}
141142
return errors.Result()

pkg/k8s/informers.go

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (k k8s) getNamespaceInfomer(eventChan chan SyncDataEvent, factory informers
5757
Labels: utils.CopyMap(data.Labels),
5858
Status: status,
5959
}
60-
logger.Tracef("%s %s: %s", NAMESPACE, item.Status, item.Name)
60+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", NAMESPACE, item.Status, item.Name)
6161
eventChan <- SyncDataEvent{SyncType: NAMESPACE, Namespace: item.Name, Data: item}
6262
},
6363
DeleteFunc: func(obj interface{}) {
@@ -86,7 +86,7 @@ func (k k8s) getNamespaceInfomer(eventChan chan SyncDataEvent, factory informers
8686
Labels: utils.CopyMap(data.Labels),
8787
Status: status,
8888
}
89-
logger.Tracef("%s %s: %s", NAMESPACE, item.Status, item.Name)
89+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", NAMESPACE, item.Status, item.Name)
9090
eventChan <- SyncDataEvent{SyncType: NAMESPACE, Namespace: item.Name, Data: item}
9191
},
9292
UpdateFunc: func(oldObj, newObj interface{}) {
@@ -114,7 +114,7 @@ func (k k8s) getNamespaceInfomer(eventChan chan SyncDataEvent, factory informers
114114
if item1.Equal(item2) {
115115
return
116116
}
117-
logger.Tracef("%s %s: %s", SERVICE, item2.Status, item2.Name)
117+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", NAMESPACE, item2.Status, item2.Name)
118118
eventChan <- SyncDataEvent{SyncType: NAMESPACE, Namespace: item2.Name, Data: item2}
119119
},
120120
},
@@ -158,12 +158,13 @@ func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, factory informers.
158158
Port: int64(sp.Port),
159159
})
160160
}
161-
logger.Tracef("%s %s: %s", SERVICE, item.Status, item.Name)
161+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", SERVICE, item.Status, item.Name)
162162
eventChan <- SyncDataEvent{SyncType: SERVICE, Namespace: item.Namespace, Data: item}
163163
if k.publishSvc != nil && k.publishSvc.Namespace == item.Namespace && k.publishSvc.Name == item.Name {
164164
// item copy because of ADDED handler in events.go which must modify the STATUS based solely on addresses
165165
itemCopy := *item
166166
itemCopy.Addresses = getServiceAddresses(data)
167+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", PUBLISH_SERVICE, item.Status, item.Name)
167168
eventChan <- SyncDataEvent{SyncType: PUBLISH_SERVICE, Namespace: item.Namespace, Data: &itemCopy}
168169
}
169170
},
@@ -186,10 +187,11 @@ func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, factory informers.
186187
if data.Spec.Type == corev1.ServiceTypeExternalName {
187188
item.DNS = data.Spec.ExternalName
188189
}
189-
logger.Tracef("%s %s: %s", SERVICE, item.Status, item.Name)
190+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", SERVICE, item.Status, item.Name)
190191
eventChan <- SyncDataEvent{SyncType: SERVICE, Namespace: item.Namespace, Data: item}
191192
if k.publishSvc != nil && k.publishSvc.Namespace == item.Namespace && k.publishSvc.Name == item.Name {
192193
item.Addresses = getServiceAddresses(data)
194+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", PUBLISH_SERVICE, item.Status, item.Name)
193195
eventChan <- SyncDataEvent{SyncType: PUBLISH_SERVICE, Namespace: data.Namespace, Data: item}
194196
}
195197
},
@@ -252,11 +254,12 @@ func (k k8s) getServiceInformer(eventChan chan SyncDataEvent, factory informers.
252254
if item2.Equal(item1) {
253255
return
254256
}
255-
logger.Tracef("%s %s: %s", SERVICE, item2.Status, item2.Name)
257+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", SERVICE, item2.Status, item2.Name)
256258
eventChan <- SyncDataEvent{SyncType: SERVICE, Namespace: item2.Namespace, Data: item2}
257259

258260
if k.publishSvc != nil && k.publishSvc.Namespace == item2.Namespace && k.publishSvc.Name == item2.Name {
259261
item2.Addresses = getServiceAddresses(data2)
262+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", PUBLISH_SERVICE, item2.Status, item2.Name)
260263
eventChan <- SyncDataEvent{SyncType: PUBLISH_SERVICE, Namespace: item2.Namespace, Data: item2}
261264
}
262265
},
@@ -286,7 +289,7 @@ func (k k8s) getSecretInformer(eventChan chan SyncDataEvent, factory informers.S
286289
Data: data.Data,
287290
Status: status,
288291
}
289-
logger.Tracef("%s %s: %s", SECRET, item.Status, item.Name)
292+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", SECRET, item.Status, item.Name)
290293
eventChan <- SyncDataEvent{SyncType: SECRET, Namespace: item.Namespace, Data: item}
291294
},
292295
DeleteFunc: func(obj interface{}) {
@@ -302,7 +305,7 @@ func (k k8s) getSecretInformer(eventChan chan SyncDataEvent, factory informers.S
302305
Data: data.Data,
303306
Status: status,
304307
}
305-
logger.Tracef("%s %s: %s", SECRET, item.Status, item.Name)
308+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", SECRET, item.Status, item.Name)
306309
eventChan <- SyncDataEvent{SyncType: SECRET, Namespace: item.Namespace, Data: item}
307310
},
308311
UpdateFunc: func(oldObj, newObj interface{}) {
@@ -332,7 +335,7 @@ func (k k8s) getSecretInformer(eventChan chan SyncDataEvent, factory informers.S
332335
if item2.Equal(item1) {
333336
return
334337
}
335-
logger.Tracef("%s %s: %s", SECRET, item2.Status, item2.Name)
338+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", SECRET, item2.Status, item2.Name)
336339
eventChan <- SyncDataEvent{SyncType: SECRET, Namespace: item2.Namespace, Data: item2}
337340
},
338341
},
@@ -362,7 +365,7 @@ func (k k8s) getConfigMapInformer(eventChan chan SyncDataEvent, factory informer
362365
Annotations: store.CopyAnnotations(data.Data),
363366
Status: status,
364367
}
365-
logger.Tracef("%s %s: %s", CONFIGMAP, item.Status, item.Name)
368+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", CONFIGMAP, item.Status, item.Name)
366369
eventChan <- SyncDataEvent{SyncType: CONFIGMAP, Namespace: item.Namespace, Data: item}
367370
},
368371
DeleteFunc: func(obj interface{}) {
@@ -378,7 +381,7 @@ func (k k8s) getConfigMapInformer(eventChan chan SyncDataEvent, factory informer
378381
Annotations: store.CopyAnnotations(data.Data),
379382
Status: status,
380383
}
381-
logger.Tracef("%s %s: %s", CONFIGMAP, item.Status, item.Name)
384+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", CONFIGMAP, item.Status, item.Name)
382385
eventChan <- SyncDataEvent{SyncType: CONFIGMAP, Namespace: item.Namespace, Data: item}
383386
},
384387
UpdateFunc: func(oldObj, newObj interface{}) {
@@ -408,7 +411,7 @@ func (k k8s) getConfigMapInformer(eventChan chan SyncDataEvent, factory informer
408411
if item2.Equal(item1) {
409412
return
410413
}
411-
logger.Tracef("%s %s: %s", CONFIGMAP, item2.Status, item2.Name)
414+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", CONFIGMAP, item2.Status, item2.Name)
412415
eventChan <- SyncDataEvent{SyncType: CONFIGMAP, Namespace: item2.Namespace, Data: item2}
413416
},
414417
},
@@ -477,28 +480,25 @@ func (k k8s) getEndpointsInformer(eventChan chan SyncDataEvent, factory informer
477480
if errors.Is(err, ErrIgnored) {
478481
return
479482
}
480-
logger.Tracef("%s %s: %s", ENDPOINTS, item.Status, item.Service)
483+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s %s", ENDPOINTS, item.Status, item.Service, item.SliceName)
481484
eventChan <- SyncDataEvent{SyncType: ENDPOINTS, Namespace: item.Namespace, Data: item}
482485
},
483486
DeleteFunc: func(obj interface{}) {
484487
item, err := k.convertToEndpoints(obj, store.DELETED)
485488
if errors.Is(err, ErrIgnored) {
486489
return
487490
}
488-
logger.Tracef("%s %s: %s", ENDPOINTS, item.Status, item.Service)
491+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s %s", ENDPOINTS, item.Status, item.Service, item.SliceName)
489492
eventChan <- SyncDataEvent{SyncType: ENDPOINTS, Namespace: item.Namespace, Data: item}
490493
},
491494
UpdateFunc: func(oldObj, newObj interface{}) {
492-
item1, err := k.convertToEndpoints(oldObj, store.EMPTY)
495+
_, err := k.convertToEndpoints(oldObj, store.EMPTY)
493496
if errors.Is(err, ErrIgnored) {
494497
return
495498
}
496499
item2, _ := k.convertToEndpoints(newObj, store.MODIFIED)
497-
if item2.Equal(item1) {
498-
return
499-
}
500500
// fix modified state for ones that are deleted,new,same
501-
logger.Tracef("%s %s: %s", ENDPOINTS, item2.Status, item2.Service)
501+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s %s", ENDPOINTS, item2.Status, item2.Service, item2.SliceName)
502502
eventChan <- SyncDataEvent{SyncType: ENDPOINTS, Namespace: item2.Namespace, Data: item2}
503503
},
504504
})
@@ -544,7 +544,7 @@ func (k k8s) addIngressClassHandlers(eventChan chan SyncDataEvent, informer cach
544544
logger.Errorf("%s: Invalid data from k8s api, %s", INGRESS_CLASS, obj)
545545
return
546546
}
547-
logger.Tracef("%s %s: %s", INGRESS_CLASS, item.Status, item.Name)
547+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", INGRESS_CLASS, item.Status, item.Name)
548548
eventChan <- SyncDataEvent{SyncType: INGRESS_CLASS, Data: item}
549549
},
550550
DeleteFunc: func(obj interface{}) {
@@ -554,7 +554,7 @@ func (k k8s) addIngressClassHandlers(eventChan chan SyncDataEvent, informer cach
554554
return
555555
}
556556
item.Status = store.DELETED
557-
logger.Tracef("%s %s: %s", INGRESS_CLASS, item.Status, item.Name)
557+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", INGRESS_CLASS, item.Status, item.Name)
558558
eventChan <- SyncDataEvent{SyncType: INGRESS_CLASS, Data: item}
559559
},
560560
UpdateFunc: func(oldObj, newObj interface{}) {
@@ -565,7 +565,7 @@ func (k k8s) addIngressClassHandlers(eventChan chan SyncDataEvent, informer cach
565565
}
566566
item.Status = store.MODIFIED
567567

568-
logger.Tracef("%s %s: %s", INGRESS_CLASS, item.Status, item.Name)
568+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", INGRESS_CLASS, item.Status, item.Name)
569569
eventChan <- SyncDataEvent{SyncType: INGRESS_CLASS, Data: item}
570570
},
571571
},
@@ -583,7 +583,7 @@ func (k k8s) addIngressHandlers(eventChan chan SyncDataEvent, informer cache.Sha
583583
return
584584
}
585585
item.Status = store.ADDED
586-
logger.Tracef("%s %s: %s", INGRESS, item.Status, item.Name)
586+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", INGRESS, item.Status, item.Name)
587587
eventChan <- SyncDataEvent{SyncType: INGRESS, Namespace: item.Namespace, Data: item}
588588
},
589589
DeleteFunc: func(obj interface{}) {
@@ -593,7 +593,7 @@ func (k k8s) addIngressHandlers(eventChan chan SyncDataEvent, informer cache.Sha
593593
return
594594
}
595595
item.Status = store.DELETED
596-
logger.Tracef("%s %s: %s", INGRESS, item.Status, item.Name)
596+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", INGRESS, item.Status, item.Name)
597597
eventChan <- SyncDataEvent{SyncType: INGRESS, Namespace: item.Namespace, Data: item}
598598
},
599599
UpdateFunc: func(oldObj, newObj interface{}) {
@@ -603,7 +603,7 @@ func (k k8s) addIngressHandlers(eventChan chan SyncDataEvent, informer cache.Sha
603603
return
604604
}
605605
item.Status = store.MODIFIED
606-
logger.Tracef("%s %s: %s", INGRESS, item.Status, item.Name)
606+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", INGRESS, item.Status, item.Name)
607607
eventChan <- SyncDataEvent{SyncType: INGRESS, Namespace: item.Namespace, Data: item}
608608
},
609609
},
@@ -618,28 +618,25 @@ func (k k8s) addEndpointSliceHandlers(eventChan chan SyncDataEvent, informer cac
618618
if errors.Is(err, ErrIgnored) {
619619
return
620620
}
621-
logger.Tracef("%s %s: %s", ENDPOINTS, item.Status, item.Service)
621+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s %s", ENDPOINTS, item.Status, item.Service, item.SliceName)
622622
eventChan <- SyncDataEvent{SyncType: ENDPOINTS, Namespace: item.Namespace, Data: item}
623623
},
624624
DeleteFunc: func(obj interface{}) {
625625
item, err := k.convertToEndpoints(obj, store.DELETED)
626626
if errors.Is(err, ErrIgnored) {
627627
return
628628
}
629-
logger.Tracef("%s %s: %s", ENDPOINTS, item.Status, item.Service)
629+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s %s", ENDPOINTS, item.Status, item.Service, item.SliceName)
630630
eventChan <- SyncDataEvent{SyncType: ENDPOINTS, Namespace: item.Namespace, Data: item}
631631
},
632632
UpdateFunc: func(oldObj, newObj interface{}) {
633-
item1, err := k.convertToEndpoints(oldObj, store.EMPTY)
633+
_, err := k.convertToEndpoints(oldObj, store.EMPTY)
634634
if errors.Is(err, ErrIgnored) {
635635
return
636636
}
637637
item2, _ := k.convertToEndpoints(newObj, store.MODIFIED)
638-
if item2.Equal(item1) {
639-
return
640-
}
641638
// fix modified state for ones that are deleted,new,same
642-
logger.Tracef("%s %s: %s", ENDPOINTS, item2.Status, item2.Service)
639+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s %s", ENDPOINTS, item2.Status, item2.Service, item2.SliceName)
643640
eventChan <- SyncDataEvent{SyncType: ENDPOINTS, Namespace: item2.Namespace, Data: item2}
644641
},
645642
})
@@ -794,7 +791,7 @@ func manageGatewayClass(gatewayclass *gatewayv1beta1.GatewayClass, eventChan cha
794791
Generation: gatewayclass.Generation,
795792
Status: status,
796793
}
797-
logger.Tracef("%s %s: %s", GATEWAYCLASS, item.Status, item.Name)
794+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", GATEWAYCLASS, item.Status, item.Name)
798795
eventChan <- SyncDataEvent{SyncType: GATEWAYCLASS, Data: &item}
799796
}
800797

@@ -841,7 +838,7 @@ func manageGateway(gateway *gatewayv1beta1.Gateway, eventChan chan SyncDataEvent
841838
Generation: gateway.Generation,
842839
Status: status,
843840
}
844-
logger.Tracef("%s %s: %s", GATEWAY, item.Status, item.Name)
841+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", GATEWAY, item.Status, item.Name)
845842
eventChan <- SyncDataEvent{SyncType: GATEWAY, Namespace: item.Namespace, Data: &item}
846843
}
847844

@@ -904,7 +901,7 @@ func manageTCPRoute(tcproute *gatewayv1alpha2.TCPRoute, eventChan chan SyncDataE
904901
Generation: tcproute.Generation,
905902
Status: status,
906903
}
907-
logger.Tracef("%s %s: %s", TCPROUTE, item.Status, item.Name)
904+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", TCPROUTE, item.Status, item.Name)
908905
eventChan <- SyncDataEvent{SyncType: TCPROUTE, Namespace: item.Namespace, Data: &item}
909906
}
910907

@@ -978,6 +975,6 @@ func manageReferenceGrant(referenceGrant *gatewayv1alpha2.ReferenceGrant, eventC
978975
}
979976
}
980977

981-
logger.Tracef("%s %s: %s", REFERENCEGRANT, item.Status, item.Name)
978+
logger.Tracef("[RUNTIME] [K8s] %s %s: %s", REFERENCEGRANT, item.Status, item.Name)
982979
eventChan <- SyncDataEvent{SyncType: REFERENCEGRANT, Namespace: item.Namespace, Data: &item}
983980
}

pkg/k8s/main.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ import (
4040
gatewaynetworking "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
4141
)
4242

43-
var logger = utils.GetK8sAPILogger()
43+
var logger = utils.GetLogger()
4444

4545
// TRACE_API outputs all k8s events received from k8s API
4646
const (
47-
TRACE_API = false //nolint:golint,stylecheck
4847
CRSGroupVersionV1alpha1 = "core.haproxy.org/v1alpha1"
4948
CRSGroupVersionV1alpha2 = "core.haproxy.org/v1alpha2"
5049
GATEWAY_API_VERSION = "v0.5.1" //nolint:golint,stylecheck
@@ -86,10 +85,6 @@ type k8s struct {
8685
}
8786

8887
func New(osArgs utils.OSArgs, whitelist map[string]struct{}, publishSvc *utils.NamespaceValue) K8s { //nolint:ireturn
89-
if !TRACE_API {
90-
logger.SetLevel(utils.Info)
91-
}
92-
9388
restconfig, err := getRestConfig(osArgs)
9489
logger.Panic(err)
9590
builtInClient := k8sclientset.NewForConfigOrDie(restconfig)

0 commit comments

Comments
 (0)