Skip to content

Commit da2e811

Browse files
committed
fix: add informer resync period for node status watcher
Also use a constant everywhere in informers. Add some debug logs. Might fix #9991 Signed-off-by: Andrey Smirnov <[email protected]>
1 parent 9b957df commit da2e811

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

internal/app/machined/pkg/controllers/k8s/endpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (ctrl *EndpointController) watchKubernetesEndpoint(ctx context.Context, r c
269269

270270
func kubernetesEndpointWatcher(ctx context.Context, logger *zap.Logger, client *kubernetes.Client) (chan *corev1.Endpoints, func(), error) {
271271
informerFactory := informers.NewSharedInformerFactoryWithOptions(
272-
client.Clientset, 30*time.Second,
272+
client.Clientset, constants.KubernetesInformerDefaultResyncPeriod,
273273
informers.WithNamespace(corev1.NamespaceDefault),
274274
informers.WithTweakListOptions(func(options *v1.ListOptions) {
275275
options.FieldSelector = fields.OneTermEqualSelector("metadata.name", "kubernetes").String()

internal/app/machined/pkg/controllers/k8s/internal/nodewatch/nodewatch.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"fmt"
1111

12+
"go.uber.org/zap"
1213
corev1 "k8s.io/api/core/v1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
"k8s.io/apimachinery/pkg/fields"
@@ -17,6 +18,7 @@ import (
1718
"k8s.io/client-go/tools/cache"
1819

1920
"github.com/siderolabs/talos/pkg/kubernetes"
21+
"github.com/siderolabs/talos/pkg/machinery/constants"
2022
)
2123

2224
// NodeWatcher defines a NodeWatcher-based node watcher.
@@ -46,10 +48,12 @@ func (r *NodeWatcher) Get() (*corev1.Node, error) {
4648
}
4749

4850
// Watch starts watching Node state and notifies on updates via notify channel.
49-
func (r *NodeWatcher) Watch(ctx context.Context) (<-chan struct{}, <-chan error, func(), error) {
51+
func (r *NodeWatcher) Watch(ctx context.Context, logger *zap.Logger) (<-chan struct{}, <-chan error, func(), error) {
52+
logger.Debug("starting node watcher", zap.String("nodename", r.nodename))
53+
5054
informerFactory := informers.NewSharedInformerFactoryWithOptions(
5155
r.client.Clientset,
52-
0,
56+
constants.KubernetesInformerDefaultResyncPeriod,
5357
informers.WithTweakListOptions(
5458
func(opts *metav1.ListOptions) {
5559
opts.FieldSelector = fields.OneTermEqualSelector(metav1.ObjectNameField, r.nodename).String()
@@ -88,7 +92,11 @@ func (r *NodeWatcher) Watch(ctx context.Context) (<-chan struct{}, <-chan error,
8892

8993
informerFactory.Start(ctx.Done())
9094

95+
logger.Debug("waiting for node cache sync")
96+
9197
informerFactory.WaitForCacheSync(ctx.Done())
9298

99+
logger.Debug("node cache sync done")
100+
93101
return notifyCh, watchErrCh, informerFactory.Shutdown, nil
94102
}

internal/app/machined/pkg/controllers/k8s/node_status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ func (ctrl *NodeStatusController) Run(ctx context.Context, r controller.Runtime,
158158
var watchCtx context.Context
159159
watchCtx, watchCtxCancel = context.WithCancel(ctx) //nolint:govet
160160

161-
notifyCh, watchErrCh, notifyCloser, err = nodewatcher.Watch(watchCtx)
161+
notifyCh, watchErrCh, notifyCloser, err = nodewatcher.Watch(watchCtx, logger)
162162
if err != nil {
163-
return fmt.Errorf("error setting up registry watcher: %w", err) //nolint:govet
163+
return fmt.Errorf("error setting up node watcher: %w", err) //nolint:govet
164164
}
165165
}
166166

internal/integration/base/k8s.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
"k8s.io/kubectl/pkg/scheme"
5252

5353
taloskubernetes "github.com/siderolabs/talos/pkg/kubernetes"
54+
"github.com/siderolabs/talos/pkg/machinery/constants"
5455
)
5556

5657
// K8sSuite is a base suite for K8s tests.
@@ -813,9 +814,12 @@ func (k8sSuite *K8sSuite) SetupNodeInformer(ctx context.Context, nodeName string
813814

814815
watchCh := make(chan *corev1.Node)
815816

816-
informerFactory := informers.NewSharedInformerFactoryWithOptions(k8sSuite.Clientset, 30*time.Second, informers.WithTweakListOptions(func(options *metav1.ListOptions) {
817-
options.FieldSelector = metadataKeyName + nodeName
818-
}))
817+
informerFactory := informers.NewSharedInformerFactoryWithOptions(
818+
k8sSuite.Clientset, constants.KubernetesInformerDefaultResyncPeriod,
819+
informers.WithTweakListOptions(func(options *metav1.ListOptions) {
820+
options.FieldSelector = metadataKeyName + nodeName
821+
}),
822+
)
819823

820824
nodeInformer := informerFactory.Core().V1().Nodes().Informer()
821825
_, err := nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{

internal/pkg/discovery/registry/kubernetes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"net/netip"
1313
"strconv"
1414
"strings"
15-
"time"
1615

1716
"github.com/siderolabs/gen/value"
1817
"github.com/siderolabs/gen/xslices"
@@ -265,7 +264,7 @@ func (r *Kubernetes) List(localNodeName string) ([]*cluster.AffiliateSpec, error
265264

266265
// Watch starts watching Node state and notifies on updates via notify channel.
267266
func (r *Kubernetes) Watch(ctx context.Context, logger *zap.Logger) (<-chan struct{}, func(), error) {
268-
informerFactory := informers.NewSharedInformerFactory(r.client.Clientset, 30*time.Second)
267+
informerFactory := informers.NewSharedInformerFactory(r.client.Clientset, constants.KubernetesInformerDefaultResyncPeriod)
269268

270269
notifyCh := make(chan struct{}, 1)
271270

pkg/machinery/constants/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,9 @@ const (
12381238

12391239
// RegistrydListenAddress is the address to listen on for the registryd service.
12401240
RegistrydListenAddress = "127.0.0.1:3172"
1241+
1242+
// KubernetesInformerDefaultResyncPeriod is the default resync period for Kubernetes informers.
1243+
KubernetesInformerDefaultResyncPeriod = 30 * time.Second
12411244
)
12421245

12431246
// See https://linux.die.net/man/3/klogctl

0 commit comments

Comments
 (0)