Skip to content

Commit

Permalink
Update WithOnReconcileFunc signature to include context
Browse files Browse the repository at this point in the history
  • Loading branch information
ykadowak committed Feb 19, 2024
1 parent 32ead97 commit 102bd67
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion internal/k8s/pod/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package pod

import (
"context"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
Expand Down Expand Up @@ -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 {

Check warning on line 52 in internal/k8s/pod/option.go

View check run for this annotation

Codecov / codecov/patch

internal/k8s/pod/option.go#L52

Added line #L52 was not covered by tests
return func(r *reconciler) error {
r.onReconcile = f
return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/k8s/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)

Check warning on line 159 in internal/k8s/pod/pod.go

View check run for this annotation

Codecov / codecov/patch

internal/k8s/pod/pod.go#L159

Added line #L159 was not covered by tests
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/discoverer/k8s/service/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check warning on line 140 in pkg/discoverer/k8s/service/discover.go

View check run for this annotation

Codecov / codecov/patch

pkg/discoverer/k8s/service/discover.go#L140

Added line #L140 was not covered by tests
log.Debugf("pod resource reconciled\t%#v", podList)
for name, pods := range podList {
if len(pods) > d.maxPods {
Expand Down
14 changes: 11 additions & 3 deletions pkg/index/operator/service/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func New(agentName string, opts ...Option) (o Operator, err error) {
}),

Check warning on line 68 in pkg/index/operator/service/operator.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/operator/service/operator.go#L60-L68

Added lines #L60 - L68 were not covered by tests
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)
Expand Down Expand Up @@ -129,3 +127,13 @@ func (o *operator) Start(ctx context.Context) (<-chan error, error) {

return ech, nil

Check warning on line 128 in pkg/index/operator/service/operator.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/operator/service/operator.go#L128

Added line #L128 was not covered by tests
}

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)
}

Check warning on line 137 in pkg/index/operator/service/operator.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/operator/service/operator.go#L131-L137

Added lines #L131 - L137 were not covered by tests
}
}

0 comments on commit 102bd67

Please sign in to comment.