Skip to content

Commit

Permalink
fix(ocean/עcp): resolved issues with vng resource_limits (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadkesarwani committed Nov 30, 2022
1 parent 9b6eee7 commit 313b3e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,23 +558,11 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
Type: schema.TypeInt,
Optional: true,
Default: -1,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "-1" && new == "null" {
return true
}
return false
},
},
string(MinInstanceCount): {
Type: schema.TypeInt,
Optional: true,
Default: -1,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "-1" && new == "null" {
return true
}
return false
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,18 +992,20 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
commons.OceanGKELaunchSpec,
ResourceLimits,
&schema.Schema{
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
string(MaxInstanceCount): {
Type: schema.TypeInt,
Optional: true,
Default: -1,
},
string(MinInstanceCount): {
Type: schema.TypeInt,
Optional: true,
Default: -1,
},
},
},
Expand Down Expand Up @@ -1281,7 +1283,7 @@ func expandStorage(data interface{}) (*gcp.Storage, error) {
func expandResourceLimits(data interface{}) (*gcp.ResourceLimits, error) {
var resourceLimits *gcp.ResourceLimits
updated := 0
list := data.(*schema.Set).List()
list := data.([]interface{})
for _, v := range list {
attr, ok := v.(map[string]interface{})
if !ok {
Expand All @@ -1290,14 +1292,18 @@ func expandResourceLimits(data interface{}) (*gcp.ResourceLimits, error) {

r := &gcp.ResourceLimits{}

if v, ok := attr[string(MaxInstanceCount)].(int); ok {
if v, ok := attr[string(MaxInstanceCount)].(int); ok && v >= 0 {
updated = 1
r.SetMaxInstanceCount(spotinst.Int(v))
} else {
r.SetMaxInstanceCount(nil)
}

if v, ok := attr[string(MinInstanceCount)].(int); ok {
if v, ok := attr[string(MinInstanceCount)].(int); ok && v >= 0 {
updated = 1
r.SetMinInstanceCount(spotinst.Int(v))
} else {
r.SetMinInstanceCount(nil)
}

resourceLimits = r
Expand Down Expand Up @@ -1388,6 +1394,10 @@ func flattenResourceLimits(resourceLimits *gcp.ResourceLimits) []interface{} {
if resourceLimits != nil {
result := make(map[string]interface{})

value := spotinst.Int(-1)
result[string(MinInstanceCount)] = value
result[string(MaxInstanceCount)] = value

if resourceLimits.MaxInstanceCount != nil {
result[string(MaxInstanceCount)] = spotinst.IntValue(resourceLimits.MaxInstanceCount)
}
Expand Down

0 comments on commit 313b3e4

Please sign in to comment.