55 "encoding/json"
66 "errors"
77 "fmt"
8+ "log"
89
910 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1011 "github.com/ovh/terraform-provider-ovh/ovh/helpers"
@@ -32,9 +33,9 @@ type CloudProjectKubeNodePoolCreateOpts struct {
3233type TaintEffectType int
3334
3435type Taint struct {
35- Effect TaintEffectType `json:"effect,omitempty "`
36- Key string `json:"key,omitempty "`
37- Value string `json:"value,omitempty "`
36+ Effect TaintEffectType `json:"effect"`
37+ Key string `json:"key"`
38+ Value string `json:"value"`
3839}
3940
4041type CloudProjectKubeNodePoolTemplateMetadata struct {
@@ -45,12 +46,12 @@ type CloudProjectKubeNodePoolTemplateMetadata struct {
4546
4647type CloudProjectKubeNodePoolTemplateSpec struct {
4748 Taints []Taint `json:"taints"`
48- Unschedulable * bool `json:"unschedulable"`
49+ Unschedulable bool `json:"unschedulable"`
4950}
5051
5152type CloudProjectKubeNodePoolTemplate struct {
52- Metadata * CloudProjectKubeNodePoolTemplateMetadata `json:"metadata,omitempty "`
53- Spec * CloudProjectKubeNodePoolTemplateSpec `json:"spec,omitempty "`
53+ Metadata CloudProjectKubeNodePoolTemplateMetadata `json:"metadata"`
54+ Spec CloudProjectKubeNodePoolTemplateSpec `json:"spec"`
5455}
5556
5657type CloudProjectKubeNodePoolUpdateOpts struct {
@@ -96,8 +97,8 @@ func (opts *CloudProjectKubeNodePoolCreateOpts) FromResource(d *schema.ResourceD
9697func loadNodelPoolTemplateFromResource (i interface {}) (* CloudProjectKubeNodePoolTemplate , error ) {
9798 // initialize map variables to explicit empty map
9899 template := CloudProjectKubeNodePoolTemplate {
99- Metadata : & CloudProjectKubeNodePoolTemplateMetadata {},
100- Spec : & CloudProjectKubeNodePoolTemplateSpec {},
100+ Metadata : CloudProjectKubeNodePoolTemplateMetadata {},
101+ Spec : CloudProjectKubeNodePoolTemplateSpec {},
101102 }
102103
103104 templateSet := i .(* schema.Set ).List ()
@@ -145,28 +146,29 @@ func loadNodelPoolTemplateFromResource(i interface{}) (*CloudProjectKubeNodePool
145146
146147 // spec.taints
147148 taints := spec ["taints" ].([]interface {})
148- data : = make ([]Taint , 0 )
149+ template . Spec . Taints = make ([]Taint , 0 )
149150 for _ , taint := range taints {
150151 effectString := taint .(map [string ]interface {})["effect" ].(string )
151152 effect := TaintEffecTypeToID [effectString ]
152153 if effect == NotATaint {
153154 return nil , fmt .Errorf ("effect: %s is not a allowable taint %#v" , effectString , TaintEffecTypeToID )
154155 }
155156
156- data = append (data , Taint {
157+ template . Spec . Taints = append (template . Spec . Taints , Taint {
157158 Effect : effect ,
158159 Key : taint .(map [string ]interface {})["key" ].(string ),
159160 Value : taint .(map [string ]interface {})["value" ].(string ),
160161 })
161162 }
162- template .Spec .Taints = data
163163
164164 // spec.unschedulable
165- template .Spec .Unschedulable = helpers . GetNilBoolPointerFromData ( spec , "unschedulable" )
165+ template .Spec .Unschedulable = spec [ "unschedulable" ].( bool )
166166 }
167167 }
168168 }
169169
170+ log .Printf ("[DEBUG] >>>>>>>>>>>>>>>>>>>>>>>>>>%#+v" , templateSet )
171+
170172 return & template , nil
171173}
172174
@@ -262,51 +264,46 @@ func (v CloudProjectKubeNodePoolResponse) ToMap() map[string]interface{} {
262264 obj ["template" ] = []map [string ]interface {}{{}}
263265
264266 // template.metadata
265- if v .Template .Metadata != nil {
266- data := make (map [string ]interface {})
267- if vv := v .Template .Metadata .Finalizers ; vv != nil && len (vv ) > 0 {
268- data ["finalizers" ] = vv
269- }
267+ data := make (map [string ]interface {})
268+ if vv := v .Template .Metadata .Finalizers ; vv != nil && len (vv ) > 0 {
269+ data ["finalizers" ] = vv
270+ }
270271
271- if vv := v .Template .Metadata .Labels ; vv != nil && len (vv ) > 0 {
272- data ["labels" ] = vv
273- }
272+ if vv := v .Template .Metadata .Labels ; vv != nil && len (vv ) > 0 {
273+ data ["labels" ] = vv
274+ }
274275
275- if vv := v .Template .Metadata .Annotations ; vv != nil && len (vv ) > 0 {
276- data ["annotations" ] = vv
277- }
276+ if vv := v .Template .Metadata .Annotations ; vv != nil && len (vv ) > 0 {
277+ data ["annotations" ] = vv
278+ }
278279
279- if len (data ) > 0 {
280- obj ["template" ].([]map [string ]interface {})[0 ]["metadata" ] = []map [string ]interface {}{data }
281- }
280+ if len (data ) > 0 {
281+ obj ["template" ].([]map [string ]interface {})[0 ]["metadata" ] = []map [string ]interface {}{data }
282282 }
283283
284284 // template.spec
285- if v .Template .Spec != nil {
286- data := make (map [string ]interface {})
287- if vv := v .Template .Spec .Taints ; vv != nil && len (vv ) > 0 {
288- var taints []map [string ]interface {}
289- for _ , taint := range vv {
290- t := map [string ]interface {}{
291- "effect" : taint .Effect .String (),
292- "key" : taint .Key ,
293- "value" : taint .Value ,
294- }
295-
296- taints = append (taints , t )
285+ data = make (map [string ]interface {})
286+ if vv := v .Template .Spec .Taints ; vv != nil && len (vv ) > 0 {
287+ var taints []map [string ]interface {}
288+ for _ , taint := range vv {
289+ t := map [string ]interface {}{
290+ "effect" : taint .Effect .String (),
291+ "key" : taint .Key ,
292+ "value" : taint .Value ,
297293 }
298294
299- data [ " taints" ] = taints
295+ taints = append ( taints , t )
300296 }
301297
302- if vv := v .Template .Spec .Unschedulable ; vv != nil {
303- data ["unschedulable" ] = vv
304- }
298+ data ["taints" ] = taints
299+ }
305300
306- if len (data ) > 0 {
307- obj ["template" ].([]map [string ]interface {})[0 ]["spec" ] = []map [string ]interface {}{data }
308- }
301+ data ["unschedulable" ] = v .Template .Spec .Unschedulable
302+
303+ if len (data ) > 0 {
304+ obj ["template" ].([]map [string ]interface {})[0 ]["spec" ] = []map [string ]interface {}{data }
309305 }
306+
310307 }
311308
312309 // Delete the entire template if it's empty
0 commit comments