Skip to content

Commit

Permalink
logging enhancements to track down pod.list issue
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Trent <[email protected]>
  • Loading branch information
trent-s committed Jun 20, 2024
1 parent 7f6b73b commit e0ea62c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 10 additions & 6 deletions internal/controller/labelgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,17 @@ func (r *LabelGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// Get list of pods matching the label group and namespace
podsInNamespace, err := r.filterPodsInNamespace(ctx, labelGroup.Namespace, labelGroup.Status.KubernetesLabels)

r.Logger.V(5).Info(fmt.Sprintf("[Reconcile] LabelName: %s", labelGroup.Name)) // trace
r.Logger.V(5).Info(fmt.Sprintf("[Reconcile] Namespace: %s", labelGroup.Namespace)) // trace
r.Logger.V(5).Info(fmt.Sprintf("[Reconcile] podNamesinNamespace: %s", podsInNamespace)) // trace

if err != nil || len(podsInNamespace) == 0 {
r.Logger.V(0).Error(err, "[Reconcile] Couldn't get pods for the labels provided.")
r.Logger.V(5).Info(fmt.Sprintf("[Reconcile] labelGroup: %#v", labelGroup)) // trace
r.Logger.V(5).Info("[Reconcile] Unable to get podlist.") // trace
r.Logger.V(5).Info(fmt.Sprintf("[Reconcile] LabelName: %s", labelGroup.Name)) // trace
r.Logger.V(5).Info(fmt.Sprintf("[Reconcile] Namespace: %s", labelGroup.Namespace)) // trace
r.Logger.V(5).Info(fmt.Sprintf("[Reconcile] KubernetesLabels: %#v", labelGroup.Status.KubernetesLabels)) // trace
r.Logger.V(5).Info(fmt.Sprintf("[Reconcile] podNamesinNamespace: %s", podsInNamespace)) // trace
r.Logger.V(5).Info(fmt.Sprintf("[Reconcile] ctx: %#v", ctx)) // trace
if err != nil {
r.Logger.V(0).Error(err, "[Reconcile] ERROR: Couldn't get pods for the labels provided.")
}

return ctrl.Result{}, err
}

Expand Down
12 changes: 9 additions & 3 deletions internal/controller/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,30 @@ func (r *LabelGroupReconciler) filterPodsInNamespace(ctx context.Context, namesp
// List pods in the specified namespace with label selector applied
var podList v1.PodList
if err := r.Client.List(ctx, &podList, listOptions); err != nil {
r.Logger.V(5).Info(fmt.Sprintf("[filterPodsInNamespace] labelSelector: %#v", labelSelector))
r.Logger.V(5).Info(fmt.Sprintf("[filterPodsInNamespace] ctx: %#v", ctx))
r.Logger.V(5).Info(fmt.Sprintf("[filterPodsInNamespace] podList: %#v", podList))
r.Logger.V(5).Info(fmt.Sprintf("[filterPodsInNamespace] listOptions: %#v", listOptions))
r.Logger.V(0).Error(err, "[filterPodsInNamespace] List Error:")
return nil, err
}

var podNames []string
for _, pod := range podList.Items {
podNames = append(podNames, pod.Name)
}

return podNames, nil
}

// Functions to get data from the cluster
func (r *LabelGroupReconciler) GetPodNamesMatchingLabels(ctx context.Context, labelGroup *susqlv1.LabelGroup) ([]string, []string, error) {
pods := &v1.PodList{}
r.Logger.V(5).Info(fmt.Sprintf("[GetPodNamesMatchingLabels] pods: %#v", pods))

r.Logger.V(5).Info(fmt.Sprintf("[LabelGroup] pods: %#v", labelGroup))

if err := r.List(ctx, pods, client.UnsafeDisableDeepCopy, (client.MatchingLabels)(labelGroup.Status.KubernetesLabels)); err != nil {
r.Logger.V(5).Info(fmt.Sprintf("[GetPodNamesMatchingLabels] pods: %#v", pods))
r.Logger.V(5).Info(fmt.Sprintf("[GetPodNamesMatchingLabels] labelgroup: %#v", labelGroup))
r.Logger.V(0).Error(err, "[GetPodNamesMatchingLabels] List Error:")
return nil, nil, err
}

Expand Down

0 comments on commit e0ea62c

Please sign in to comment.