Skip to content

Commit

Permalink
make node names unique in tests (#1598)
Browse files Browse the repository at this point in the history
- make node names unique with a sequential ID
- if the node already exists, log a debug message
  • Loading branch information
tzneal authored Mar 30, 2022
1 parent 3739122 commit 9e31a3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions pkg/cloudprovider/fake/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
"fmt"
"strings"
"sync"
"sync/atomic"

"github.com/Pallinder/go-randomdata"

"k8s.io/apimachinery/pkg/util/sets"

"github.com/Pallinder/go-randomdata"
"knative.dev/pkg/apis"

"github.com/aws/karpenter/pkg/cloudprovider/aws/apis/v1alpha1"
Expand All @@ -35,6 +37,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var sequentialNodeID uint64

type CloudProvider struct {
InstanceTypes []cloudprovider.InstanceType

Expand All @@ -53,7 +57,7 @@ func (c *CloudProvider) Create(ctx context.Context, nodeRequest *cloudprovider.N
c.mu.Lock()
c.CreateCalls = append(c.CreateCalls, nodeRequest)
c.mu.Unlock()
name := strings.ToLower(randomdata.SillyName())
name := fmt.Sprintf("n%04d-%s", atomic.AddUint64(&sequentialNodeID, 1), strings.ToLower(randomdata.SillyName()))
instance := nodeRequest.InstanceTypeOptions[0]
var zone, capacityType string
for _, o := range instance.Offerings() {
Expand Down
4 changes: 3 additions & 1 deletion pkg/controllers/provisioning/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ func (p *Provisioner) launch(ctx context.Context, node *scheduling.Node) error {
// ourselves to enforce the binding decision and enable images to be pulled
// before the node is fully Ready.
if _, err := p.coreV1Client.Nodes().Create(ctx, k8sNode, metav1.CreateOptions{}); err != nil {
if !errors.IsAlreadyExists(err) {
if errors.IsAlreadyExists(err) {
logging.FromContext(ctx).Debugf("node %s already registered", k8sNode.Name)
} else {
return fmt.Errorf("creating node %s, %w", k8sNode.Name, err)
}
}
Expand Down

0 comments on commit 9e31a3f

Please sign in to comment.