Skip to content

Commit

Permalink
Assume instance exists within eventual-consistency grace period
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermckinnon committed Sep 17, 2024
1 parent d7e05d5 commit c463646
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/providers/v1/instances_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ package aws

import (
"context"
"time"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
cloudprovider "k8s.io/cloud-provider"
)

const (
instanceExistsGracePeriod = 2 * time.Minute
)

func (c *Cloud) getProviderID(ctx context.Context, node *v1.Node) (string, error) {
if node.Spec.ProviderID != "" {
return node.Spec.ProviderID, nil
Expand All @@ -44,6 +49,11 @@ func (c *Cloud) getProviderID(ctx context.Context, node *v1.Node) (string, error
// InstanceExists returns true if the instance for the given node exists according to the cloud provider.
// Use the node.name or node.spec.providerID field to find the node in the cloud provider.
func (c *Cloud) InstanceExists(ctx context.Context, node *v1.Node) (bool, error) {
if time.Since(node.CreationTimestamp.Time) < instanceExistsGracePeriod {
// recently-launched EC2 instances may not appear in `ec2:DescribeInstances`
// we assume that the instance exists until the eventual-consistency grace period elapses
return true, nil
}
providerID, err := c.getProviderID(ctx, node)
if err != nil {
return false, err
Expand Down

0 comments on commit c463646

Please sign in to comment.