Skip to content

Commit

Permalink
Merge pull request kubernetes#10630 from spotinst/fix-ocean-userdata
Browse files Browse the repository at this point in the history
Spotinst: Avoid unnecessary duplication of tasks
  • Loading branch information
k8s-ci-robot authored Jan 22, 2021
2 parents e9abf8d + 5f30cde commit f97ef42
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/model/spotinstmodel/instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,6 @@ func (b *InstanceGroupModelBuilder) buildOcean(c *fi.ModelBuilderContext, igs ..
klog.V(4).Infof("Detected default launch spec: %q", b.AutoscalingGroupName(ig))
}

// Rename the instance group to avoid duplicate tasks with same name.
ig.Name = fi.StringValue(ocean.Name)

// Image.
ocean.ImageID = fi.String(ig.Spec.Image)

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

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

func (b *InstanceGroupModelBuilder) buildLaunchSpec(c *fi.ModelBuilderContext,
ig *kops.InstanceGroup, ocean *spotinsttasks.Ocean) (err error) {
ig, igOcean *kops.InstanceGroup, ocean *spotinsttasks.Ocean) (err error) {

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

// User data.
launchSpec.UserData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig)
if err != nil {
return fmt.Errorf("error building user data: %v", err)
if ig.Name == igOcean.Name {
launchSpec.UserData = ocean.UserData
} else {
launchSpec.UserData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig)
if err != nil {
return fmt.Errorf("error building user data: %v", err)
}
}

// Instance profile.
Expand Down

0 comments on commit f97ef42

Please sign in to comment.