Skip to content

Commit

Permalink
Merge pull request kubernetes#124113 from krzysdabro/nodeipam-pooling
Browse files Browse the repository at this point in the history
nodeipam: poll nodes immediately
  • Loading branch information
k8s-ci-robot authored Apr 18, 2024
2 parents 183aca3 + 170d143 commit 3188cbd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pkg/controller/nodeipam/ipam/cidr_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const (
)

// nodePollInterval is used in listing node
// This is a variable instead of a const to enable testing.
var nodePollInterval = 10 * time.Second

// CIDRAllocator is an interface implemented by things that know how
Expand Down Expand Up @@ -116,8 +115,7 @@ type nodeReservedCIDRs struct {

// New creates a new CIDR range allocator.
func New(ctx context.Context, kubeClient clientset.Interface, cloud cloudprovider.Interface, nodeInformer informers.NodeInformer, allocatorType CIDRAllocatorType, allocatorParams CIDRAllocatorParams) (CIDRAllocator, error) {
logger := klog.FromContext(ctx)
nodeList, err := listNodes(logger, kubeClient)
nodeList, err := listNodes(ctx, kubeClient)
if err != nil {
return nil, err
}
Expand All @@ -132,13 +130,15 @@ func New(ctx context.Context, kubeClient clientset.Interface, cloud cloudprovide
}
}

func listNodes(logger klog.Logger, kubeClient clientset.Interface) (*v1.NodeList, error) {
func listNodes(ctx context.Context, kubeClient clientset.Interface) (*v1.NodeList, error) {
var nodeList *v1.NodeList
logger := klog.FromContext(ctx)

// We must poll because apiserver might not be up. This error causes
// controller manager to restart.
if pollErr := wait.Poll(nodePollInterval, apiserverStartupGracePeriod, func() (bool, error) {
if pollErr := wait.PollUntilContextTimeout(ctx, nodePollInterval, apiserverStartupGracePeriod, true, func(ctx context.Context) (bool, error) {
var err error
nodeList, err = kubeClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
nodeList, err = kubeClient.CoreV1().Nodes().List(ctx, metav1.ListOptions{
FieldSelector: fields.Everything().String(),
LabelSelector: labels.Everything().String(),
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/nodeipam/ipam/controller_legacyprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func NewController(
func (c *Controller) Start(logger klog.Logger, nodeInformer informers.NodeInformer) error {
logger.Info("Starting IPAM controller", "config", c.config)

nodes, err := listNodes(logger, c.adapter.k8s)
ctx := klog.NewContext(context.TODO(), logger)
nodes, err := listNodes(ctx, c.adapter.k8s)
if err != nil {
return err
}
Expand Down

0 comments on commit 3188cbd

Please sign in to comment.