diff --git a/internal/k8s/pod/option.go b/internal/k8s/pod/option.go index de78fb592c4..3952d648f8d 100644 --- a/internal/k8s/pod/option.go +++ b/internal/k8s/pod/option.go @@ -18,6 +18,8 @@ package pod import ( + "context" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/manager" ) @@ -47,7 +49,7 @@ func WithOnErrorFunc(f func(err error)) Option { } } -func WithOnReconcileFunc(f func(podList map[string][]Pod)) Option { +func WithOnReconcileFunc(f func(ctx context.Context, podList map[string][]Pod)) Option { return func(r *reconciler) error { r.onReconcile = f return nil diff --git a/internal/k8s/pod/pod.go b/internal/k8s/pod/pod.go index 0459b249751..4828a2a47c5 100644 --- a/internal/k8s/pod/pod.go +++ b/internal/k8s/pod/pod.go @@ -40,7 +40,7 @@ type reconciler struct { name string namespace string onError func(err error) - onReconcile func(podList map[string][]Pod) + onReconcile func(ctx context.Context, podList map[string][]Pod) lopts []client.ListOption } @@ -156,7 +156,7 @@ func (r *reconciler) Reconcile(ctx context.Context, _ reconcile.Request) (res re } if r.onReconcile != nil { - r.onReconcile(pods) + r.onReconcile(ctx, pods) } return } diff --git a/pkg/discoverer/k8s/service/discover.go b/pkg/discoverer/k8s/service/discover.go index bf999947735..32f81e8893d 100644 --- a/pkg/discoverer/k8s/service/discover.go +++ b/pkg/discoverer/k8s/service/discover.go @@ -137,7 +137,7 @@ func New(selector *config.Selectors, opts ...Option) (dsc Discoverer, err error) pod.WithOnErrorFunc(func(err error) { log.Error("failed to reconcile:", err) }), - pod.WithOnReconcileFunc(func(podList map[string][]pod.Pod) { + pod.WithOnReconcileFunc(func(_ context.Context, podList map[string][]pod.Pod) { log.Debugf("pod resource reconciled\t%#v", podList) for name, pods := range podList { if len(pods) > d.maxPods { diff --git a/pkg/index/operator/service/operator.go b/pkg/index/operator/service/operator.go index e946715256f..c07214f8ce9 100644 --- a/pkg/index/operator/service/operator.go +++ b/pkg/index/operator/service/operator.go @@ -68,9 +68,7 @@ func New(agentName string, opts ...Option) (o Operator, err error) { }), pod.WithNamespace(operator.namespace), // TODO: - pod.WithOnReconcileFunc(func(podList map[string][]pod.Pod) { - log.Debugf("reconciled pod list: %v", podList) - }), + pod.WithOnReconcileFunc(operator.podOnReconcile), pod.WithLabels(podLabelSelector), )) k8sOpts = append(k8sOpts, podOpts) @@ -129,3 +127,13 @@ func (o *operator) Start(ctx context.Context) (<-chan error, error) { return ech, nil } + +func (o *operator) podOnReconcile(ctx context.Context, podList map[string][]pod.Pod) { + for k, v := range podList { + log.Debug("key", k) + for _, pod := range v { + log.Debug("name", pod.Name) + log.Debug("annotations", pod.Annotations) + } + } +}