Skip to content

Commit f97ef42

Browse files
authored
Merge pull request kubernetes#10630 from spotinst/fix-ocean-userdata
Spotinst: Avoid unnecessary duplication of tasks
2 parents e9abf8d + 5f30cde commit f97ef42

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pkg/model/spotinstmodel/instance_group.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,6 @@ func (b *InstanceGroupModelBuilder) buildOcean(c *fi.ModelBuilderContext, igs ..
376376
klog.V(4).Infof("Detected default launch spec: %q", b.AutoscalingGroupName(ig))
377377
}
378378

379-
// Rename the instance group to avoid duplicate tasks with same name.
380-
ig.Name = fi.StringValue(ocean.Name)
381-
382379
// Image.
383380
ocean.ImageID = fi.String(ig.Spec.Image)
384381

@@ -493,8 +490,8 @@ func (b *InstanceGroupModelBuilder) buildOcean(c *fi.ModelBuilderContext, igs ..
493490
}
494491

495492
// Create a Launch Spec for each instance group.
496-
for _, ig := range igs {
497-
if err := b.buildLaunchSpec(c, ig, ocean); err != nil {
493+
for _, g := range igs {
494+
if err := b.buildLaunchSpec(c, g, ig, ocean); err != nil {
498495
return fmt.Errorf("error building launch spec: %v", err)
499496
}
500497
}
@@ -506,7 +503,7 @@ func (b *InstanceGroupModelBuilder) buildOcean(c *fi.ModelBuilderContext, igs ..
506503
}
507504

508505
func (b *InstanceGroupModelBuilder) buildLaunchSpec(c *fi.ModelBuilderContext,
509-
ig *kops.InstanceGroup, ocean *spotinsttasks.Ocean) (err error) {
506+
ig, igOcean *kops.InstanceGroup, ocean *spotinsttasks.Ocean) (err error) {
510507

511508
klog.V(4).Infof("Building instance group as LaunchSpec: %q", b.AutoscalingGroupName(ig))
512509
launchSpec := &spotinsttasks.LaunchSpec{
@@ -544,9 +541,13 @@ func (b *InstanceGroupModelBuilder) buildLaunchSpec(c *fi.ModelBuilderContext,
544541
ocean.MaxSize = fi.Int64(fi.Int64Value(ocean.MaxSize) + fi.Int64Value(maxSize))
545542

546543
// User data.
547-
launchSpec.UserData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig)
548-
if err != nil {
549-
return fmt.Errorf("error building user data: %v", err)
544+
if ig.Name == igOcean.Name {
545+
launchSpec.UserData = ocean.UserData
546+
} else {
547+
launchSpec.UserData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig)
548+
if err != nil {
549+
return fmt.Errorf("error building user data: %v", err)
550+
}
550551
}
551552

552553
// Instance profile.

0 commit comments

Comments
 (0)