fix(spot/ocean): avoid unnecessary duplication of tasks

This commit is contained in:
liranp 2021-01-21 20:47:05 +02:00
parent 43d294f4bd
commit 5f30cdedf9
No known key found for this signature in database
GPG Key ID: D5F03857002C1A93
1 changed files with 10 additions and 9 deletions

View File

@ -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)
@ -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)
}
}
@ -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{
@ -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.