Skip to content

Commit b72bec7

Browse files
committed
Updated all non-error/warning logs to commented out and with a vap TODO
1 parent ba84f91 commit b72bec7

File tree

9 files changed

+184
-1
lines changed

9 files changed

+184
-1
lines changed

npm/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var DefaultConfig = Config{
5555
},
5656

5757
// Setting LogLevel to "info" by default. Set to "debug" to get application insight logs (creates a listener that outputs diagnosticMessageWriter logs).
58-
LogLevel: "debug",
58+
LogLevel: "info",
5959
}
6060

6161
type GrpcServerConfig struct {

npm/pkg/controlplane/controllers/v2/namespaceController.go

+26
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,17 @@ func (nsc *NamespaceController) Run(stopCh <-chan struct{}) {
164164
defer utilruntime.HandleCrash()
165165
defer nsc.workqueue.ShutDown()
166166

167+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
168+
// klog.Info("Starting Namespace controller\n")
169+
// klog.Info("Starting workers")
167170
// Launch workers to process namespace resources
168171
go wait.Until(nsc.runWorker, time.Second, stopCh)
169172

173+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
174+
// klog.Info("Started workers")
170175
<-stopCh
176+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
177+
// klog.Info("Shutting down workers")
171178
}
172179

173180
func (nsc *NamespaceController) runWorker() {
@@ -205,6 +212,8 @@ func (nsc *NamespaceController) processNextWorkItem() bool {
205212
// Finally, if no error occurs we Forget this item so it does not
206213
// get queued again until another change happens.
207214
nsc.workqueue.Forget(obj)
215+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
216+
// klog.Infof("Successfully synced '%s'", key)
208217
return nil
209218
}(obj)
210219
if err != nil {
@@ -316,6 +325,8 @@ func (nsc *NamespaceController) syncAddNamespace(nsObj *corev1.Namespace) error
316325
// Add the namespace to its label's ipset list.
317326
for nsLabelKey, nsLabelVal := range nsObj.ObjectMeta.Labels {
318327
nsLabelKeyValue := util.GetIpSetFromLabelKV(nsLabelKey, nsLabelVal)
328+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
329+
// klog.Infof("Adding namespace %s to ipset list %s and %s", nsObj.ObjectMeta.Name, nsLabelKey, nsLabelKeyValue)
319330
labelIPSets := []*ipsets.IPSetMetadata{
320331
ipsets.NewIPSetMetadata(nsLabelKey, ipsets.KeyLabelOfNamespace),
321332
ipsets.NewIPSetMetadata(nsLabelKeyValue, ipsets.KeyValueLabelOfNamespace),
@@ -338,6 +349,8 @@ func (nsc *NamespaceController) syncAddNamespace(nsObj *corev1.Namespace) error
338349
func (nsc *NamespaceController) syncUpdateNamespace(newNsObj *corev1.Namespace) (metrics.OperationKind, error) {
339350
var err error
340351
newNsName, newNsLabel := newNsObj.ObjectMeta.Name, newNsObj.ObjectMeta.Labels
352+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
353+
// klog.Infof("NAMESPACE UPDATING:\n namespace: [%s/%v]", newNsName, newNsLabel)
341354

342355
// If previous syncAddNamespace failed for some reasons
343356
// before caching npm namespace object or syncUpdateNamespace is called due to namespace creation event,
@@ -366,6 +379,8 @@ func (nsc *NamespaceController) syncUpdateNamespace(newNsObj *corev1.Namespace)
366379
}
367380
toBeRemoved := []*ipsets.IPSetMetadata{ipsets.NewIPSetMetadata(newNsName, ipsets.Namespace)}
368381

382+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
383+
// klog.Infof("Deleting namespace %s from ipset list %s", newNsName, nsLabelVal)
369384
if err = nsc.dp.RemoveFromList(labelSet, toBeRemoved); err != nil {
370385
metrics.SendErrorLogAndMetric(util.NSID, "[UpdateNamespace] Error: failed to delete namespace %s from ipset list %s with err: %v", newNsName, nsLabelVal, err)
371386
return metrics.UpdateOp, fmt.Errorf("failed to remove from list during sync update namespace with err %w", err)
@@ -381,6 +396,9 @@ func (nsc *NamespaceController) syncUpdateNamespace(newNsObj *corev1.Namespace)
381396

382397
// Add the namespace to its label's ipset list.
383398
for _, nsLabelVal := range addToIPSets {
399+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
400+
// klog.Infof("Adding namespace %s to ipset list %s", newNsName, nsLabelVal)
401+
384402
var labelSet []*ipsets.IPSetMetadata
385403
if util.IsKeyValueLabelSetName(nsLabelVal) {
386404
labelSet = []*ipsets.IPSetMetadata{ipsets.NewIPSetMetadata(nsLabelVal, ipsets.KeyValueLabelOfNamespace)}
@@ -412,24 +430,32 @@ func (nsc *NamespaceController) syncUpdateNamespace(newNsObj *corev1.Namespace)
412430

413431
// cleanDeletedNamespace handles deleting namespace from ipset.
414432
func (nsc *NamespaceController) cleanDeletedNamespace(cachedNsKey string) error {
433+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
434+
// klog.Infof("NAMESPACE DELETING: [%s]", cachedNsKey)
415435
cachedNsObj, exists := nsc.npmNamespaceCache.NsMap[cachedNsKey]
416436
if !exists {
417437
return nil
418438
}
439+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
440+
// klog.Infof("NAMESPACE DELETING cached labels: [%s/%v]", cachedNsKey, cachedNsObj.LabelsMap)
419441

420442
var err error
421443
toBeDeletedNs := []*ipsets.IPSetMetadata{ipsets.NewIPSetMetadata(cachedNsKey, ipsets.Namespace)}
422444
// Delete the namespace from its label's ipset list.
423445
for nsLabelKey, nsLabelVal := range cachedNsObj.LabelsMap {
424446

425447
labelKey := ipsets.NewIPSetMetadata(nsLabelKey, ipsets.KeyLabelOfNamespace)
448+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
449+
// klog.Infof("Deleting namespace %s from ipset list %s", cachedNsKey, labelKey)
426450
if err = nsc.dp.RemoveFromList(labelKey, toBeDeletedNs); err != nil {
427451
metrics.SendErrorLogAndMetric(util.NSID, "[DeleteNamespace] Error: failed to delete namespace %s from ipset list %s with err: %v", cachedNsKey, labelKey, err)
428452
return fmt.Errorf("failed to clean deleted namespace when deleting key with err %w", err)
429453
}
430454

431455
labelIpsetName := util.GetIpSetFromLabelKV(nsLabelKey, nsLabelVal)
432456
labelKeyValue := ipsets.NewIPSetMetadata(labelIpsetName, ipsets.KeyValueLabelOfNamespace)
457+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
458+
// klog.Infof("Deleting namespace %s from ipset list %s", cachedNsKey, labelIpsetName)
433459
if err = nsc.dp.RemoveFromList(labelKeyValue, toBeDeletedNs); err != nil {
434460
metrics.SendErrorLogAndMetric(util.NSID, "[DeleteNamespace] Error: failed to delete namespace %s from ipset list %s with err: %v", cachedNsKey, labelIpsetName, err)
435461
return fmt.Errorf("failed to clean deleted namespace when deleting key value with err %w", err)

npm/pkg/controlplane/controllers/v2/networkPolicyController.go

+8
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,15 @@ func (c *NetworkPolicyController) Run(stopCh <-chan struct{}) {
148148
defer utilruntime.HandleCrash()
149149
defer c.workqueue.ShutDown()
150150

151+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
152+
// klog.Infof("Starting Network Policy worker")
151153
go wait.Until(c.runWorker, time.Second, stopCh)
152154

155+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
156+
// klog.Infof("Started Network Policy worker")
153157
<-stopCh
158+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
159+
// klog.Info("Shutting down Network Policy workers")
154160
}
155161

156162
func (c *NetworkPolicyController) runWorker() {
@@ -187,6 +193,8 @@ func (c *NetworkPolicyController) processNextWorkItem() bool {
187193
// Finally, if no error occurs we Forget this item so it does not
188194
// get queued again until another change happens.
189195
c.workqueue.Forget(obj)
196+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
197+
// klog.Infof("Successfully synced '%s'", key)
190198
return nil
191199
}(obj)
192200
if err != nil {

npm/pkg/controlplane/controllers/v2/podController.go

+43
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ func (c *PodController) deletePod(obj interface{}) {
170170
}
171171
}
172172

173+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
174+
// klog.Infof("[POD DELETE EVENT] for %s in %s", podObj.Name, podObj.Namespace)
173175
if isHostNetworkPod(podObj) {
174176
return
175177
}
@@ -190,9 +192,15 @@ func (c *PodController) Run(stopCh <-chan struct{}) {
190192
defer utilruntime.HandleCrash()
191193
defer c.workqueue.ShutDown()
192194

195+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
196+
// klog.Infof("Starting Pod worker")
193197
go wait.Until(c.runWorker, time.Second, stopCh)
194198

199+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
200+
// klog.Info("Started Pod workers")
195201
<-stopCh
202+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
203+
// klog.Info("Shutting down Pod workers")
196204
}
197205

198206
func (c *PodController) runWorker() {
@@ -230,6 +238,8 @@ func (c *PodController) processNextWorkItem() bool {
230238
// Finally, if no error occurs we Forget this item so it does not
231239
// get queued again until another change happens.
232240
c.workqueue.Forget(obj)
241+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
242+
// klog.Infof("Successfully synced '%s'", key)
233243
return nil
234244
}(obj)
235245
if err != nil {
@@ -342,6 +352,10 @@ func (c *PodController) syncPod(key string) error {
342352
}
343353

344354
func (c *PodController) syncAddedPod(podObj *corev1.Pod) error {
355+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
356+
// klog.Infof("POD CREATING: [%s/%s/%s/%s/%+v/%s]", string(podObj.GetUID()), podObj.Namespace,
357+
// podObj.Name, podObj.Spec.NodeName, podObj.Labels, podObj.Status.PodIP)
358+
345359
if !util.IsIPV4(podObj.Status.PodIP) {
346360
msg := fmt.Sprintf("[syncAddedPod] warning: ADD POD [%s/%s/%s/%+v] ignored as the PodIP is not valid ipv4 address. ip: [%s]", podObj.Namespace,
347361
podObj.Name, podObj.Spec.NodeName, podObj.Labels, podObj.Status.PodIP)
@@ -361,6 +375,8 @@ func (c *PodController) syncAddedPod(podObj *corev1.Pod) error {
361375
namespaceSet := []*ipsets.IPSetMetadata{ipsets.NewIPSetMetadata(podObj.Namespace, ipsets.Namespace)}
362376

363377
// Add the pod ip information into namespace's ipset.
378+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
379+
// klog.Infof("Adding pod %s (ip : %s) to ipset %s", podKey, podObj.Status.PodIP, podObj.Namespace)
364380
if err = c.dp.AddToSets(namespaceSet, podMetadata); err != nil {
365381
return fmt.Errorf("[syncAddedPod] Error: failed to add pod to namespace ipset with err: %w", err)
366382
}
@@ -378,13 +394,18 @@ func (c *PodController) syncAddedPod(podObj *corev1.Pod) error {
378394
targetSetKeyValue := ipsets.NewIPSetMetadata(labelKeyValue, ipsets.KeyValueLabelOfPod)
379395
allSets := []*ipsets.IPSetMetadata{targetSetKey, targetSetKeyValue}
380396

397+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
398+
// klog.Infof("Creating ipsets %+v and %+v if they do not exist", targetSetKey, targetSetKeyValue)
399+
// klog.Infof("Adding pod %s (ip : %s) to ipset %s and %s", podKey, npmPodObj.PodIP, labelKey, labelKeyValue)
381400
if err = c.dp.AddToSets(allSets, podMetadata); err != nil {
382401
return fmt.Errorf("[syncAddedPod] Error: failed to add pod to label ipset with err: %w", err)
383402
}
384403
npmPodObj.AppendLabels(map[string]string{labelKey: labelVal}, common.AppendToExistingLabels)
385404
}
386405

387406
// Add pod's named ports from its ipset.
407+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
408+
// klog.Infof("Adding named port ipsets")
388409
containerPorts := common.GetContainerPortList(podObj)
389410
if err = c.manageNamedPortIpsets(containerPorts, podKey, npmPodObj.PodIP, podObj.Spec.NodeName, addNamedPort); err != nil {
390411
return fmt.Errorf("[syncAddedPod] Error: failed to add pod to named port ipset with err: %w", err)
@@ -418,6 +439,8 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
418439
c.npmNamespaceCache.Unlock()
419440

420441
cachedNpmPod, exists := c.podMap[podKey]
442+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
443+
// klog.Infof("[syncAddAndUpdatePod] updating Pod with key %s", podKey)
421444
// No cached npmPod exists. start adding the pod in a cache
422445
if !exists {
423446
return metrics.CreateOp, c.syncAddedPod(newPodObj)
@@ -433,11 +456,18 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
433456
// NPM should clean up existing references of cached pod obj and its IP.
434457
// then, re-add new pod obj.
435458
if cachedNpmPod.PodIP != newPodObj.Status.PodIP {
459+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
460+
// klog.Infof("Pod (Namespace:%s, Name:%s, newUid:%s), has cachedPodIp:%s which is different from PodIp:%s",
461+
// newPodObj.Namespace, newPodObj.Name, string(newPodObj.UID), cachedNpmPod.PodIP, newPodObj.Status.PodIP)
436462

463+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
464+
// klog.Infof("Deleting cached Pod with key:%s first due to IP Mistmatch", podKey)
437465
if er := c.cleanUpDeletedPod(podKey); er != nil {
438466
return metrics.UpdateOp, er
439467
}
440468

469+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
470+
// klog.Infof("Adding back Pod with key:%s after IP Mistmatch", podKey)
441471
return metrics.UpdateOp, c.syncAddedPod(newPodObj)
442472
}
443473

@@ -451,6 +481,8 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
451481
cachedPodMetadata := dataplane.NewPodMetadata(podKey, cachedNpmPod.PodIP, newPodMetadata.NodeName)
452482
// Delete the pod from its label's ipset.
453483
for _, removeIPSetName := range deleteFromIPSets {
484+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
485+
// klog.Infof("Deleting pod %s (ip : %s) from ipset %s", podKey, cachedNpmPod.PodIP, removeIPSetName)
454486

455487
var toRemoveSet *ipsets.IPSetMetadata
456488
if util.IsKeyValueLabelSetName(removeIPSetName) {
@@ -472,13 +504,18 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
472504
// Add the pod to its label's ipset.
473505
for _, addIPSetName := range addToIPSets {
474506

507+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
508+
// klog.Infof("Creating ipset %s if it doesn't already exist", addIPSetName)
509+
475510
var toAddSet *ipsets.IPSetMetadata
476511
if util.IsKeyValueLabelSetName(addIPSetName) {
477512
toAddSet = ipsets.NewIPSetMetadata(addIPSetName, ipsets.KeyValueLabelOfPod)
478513
} else {
479514
toAddSet = ipsets.NewIPSetMetadata(addIPSetName, ipsets.KeyLabelOfPod)
480515
}
481516

517+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
518+
// klog.Infof("Adding pod %s (ip : %s) to ipset %s", podKey, newPodObj.Status.PodIP, addIPSetName)
482519
if err = c.dp.AddToSets([]*ipsets.IPSetMetadata{toAddSet}, newPodMetadata); err != nil {
483520
return metrics.UpdateOp, fmt.Errorf("[syncAddAndUpdatePod] Error: failed to add pod to label ipset with err: %w", err)
484521
}
@@ -521,6 +558,8 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
521558

522559
// cleanUpDeletedPod cleans up all ipset associated with this pod
523560
func (c *PodController) cleanUpDeletedPod(cachedNpmPodKey string) error {
561+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
562+
// klog.Infof("[cleanUpDeletedPod] deleting Pod with key %s", cachedNpmPodKey)
524563
// If cached npmPod does not exist, return nil
525564
cachedNpmPod, exist := c.podMap[cachedNpmPodKey]
526565
if !exist {
@@ -540,6 +579,8 @@ func (c *PodController) cleanUpDeletedPod(cachedNpmPodKey string) error {
540579
// Get lists of podLabelKey and podLabelKey + podLavelValue ,and then start deleting them from ipsets
541580
for labelKey, labelVal := range cachedNpmPod.Labels {
542581
labelKeyValue := util.GetIpSetFromLabelKV(labelKey, labelVal)
582+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
583+
// klog.Infof("Deleting pod %s (ip : %s) from ipsets %s and %s", cachedNpmPodKey, cachedNpmPod.PodIP, labelKey, labelKeyValue)
543584
if err = c.dp.RemoveFromSets(
544585
[]*ipsets.IPSetMetadata{
545586
ipsets.NewIPSetMetadata(labelKey, ipsets.KeyLabelOfPod),
@@ -572,6 +613,8 @@ func (c *PodController) manageNamedPortIpsets(portList []corev1.ContainerPort, p
572613
return nil
573614
}
574615
for _, port := range portList {
616+
// TODO: Refactor non-error/warning klogs with Vap and set the following logs to "debug" level
617+
// klog.Infof("port is %+v", port)
575618
if port.Name == "" {
576619
continue
577620
}

0 commit comments

Comments
 (0)