Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions internal/pkg/deploy/cloudformation/stack/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ func convertAdvancedCount(a manifest.AdvancedCount) (*template.AdvancedCount, er
// convertCapacityProviders transforms the manifest fields into a format
// parsable by the templates pkg.
func convertCapacityProviders(a manifest.AdvancedCount) []*template.CapacityProviderStrategy {
if a.IsEmpty() {
return nil
}
// return if autoscaling range specified without spot scaling
if !a.Range.IsEmpty() && a.Range.Value != nil {
if a.Spot == nil && a.Range.RangeConfig.SpotFrom == nil {
return nil
}
var cps []*template.CapacityProviderStrategy
Expand All @@ -147,27 +143,25 @@ func convertCapacityProviders(a manifest.AdvancedCount) []*template.CapacityProv
Weight: aws.Int(1),
CapacityProvider: capacityProviderFargateSpot,
})
rc := a.Range.RangeConfig
// Return if only spot is specifed as count
if a.Range.IsEmpty() {
if rc.SpotFrom == nil {
return cps
}
// Scaling with spot
rc := a.Range.RangeConfig
if !rc.IsEmpty() {
spotFrom := aws.IntValue(rc.SpotFrom)
min := aws.IntValue(rc.Min)
// If spotFrom value is not equal to the autoscaling min, then
// the base value on the Fargate Capacity provider must be set
// to one less than spotFrom
if spotFrom > min {
base := spotFrom - 1
fgCapacity := &template.CapacityProviderStrategy{
Base: aws.Int(base),
Weight: aws.Int(0),
CapacityProvider: capacityProviderFargate,
}
cps = append(cps, fgCapacity)
spotFrom := aws.IntValue(rc.SpotFrom)
min := aws.IntValue(rc.Min)
// If spotFrom value is not equal to the autoscaling min, then
// the base value on the Fargate Capacity provider must be set
// to one less than spotFrom
if spotFrom > min {
base := spotFrom - 1
fgCapacity := &template.CapacityProviderStrategy{
Base: aws.Int(base),
Weight: aws.Int(0),
CapacityProvider: capacityProviderFargate,
}
cps = append(cps, fgCapacity)
}
return cps
}
Expand Down
11 changes: 11 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/transformers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,17 @@ func Test_convertCapacityProviders(t *testing.T) {
},
expected: nil,
},
"returns nil if no spot config specified with min max": {
input: manifest.AdvancedCount{
Range: manifest.Range{
RangeConfig: manifest.RangeConfig{
Min: aws.Int(1),
Max: aws.Int(10),
},
},
},
expected: nil,
},
}

for name, tc := range testCases {
Expand Down
7 changes: 0 additions & 7 deletions internal/pkg/manifest/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@ func (c *Count) UnmarshalYAML(value *yaml.Node) error {
}
}

if c.AdvancedCount.Spot != nil && (c.AdvancedCount.hasAutoscaling()) {
return &errFieldMutualExclusive{
firstField: "spot",
secondField: "range/cpu_percentage/memory_percentage/requests/response_time/queue_delay",
}
}

if !c.AdvancedCount.IsEmpty() {
// Successfully unmarshalled AdvancedCount fields, return
return nil
Expand Down
11 changes: 0 additions & 11 deletions internal/pkg/manifest/svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,6 @@ func TestCount_UnmarshalYAML(t *testing.T) {
},
},
},

"Error if mutually exclusive fields are specified": {
inContent: []byte(`count:
spot: 1
cpu_percentage: 30
`),
wantedError: &errFieldMutualExclusive{
firstField: "spot",
secondField: "range/cpu_percentage/memory_percentage/requests/response_time/queue_delay",
},
},
"Error if unmarshalable": {
inContent: []byte(`count: badNumber
`),
Expand Down