Skip to content

Commit 5c8ef0c

Browse files
mathieu prigentSkYNewZ
authored andcommitted
fix schema vs api
1 parent 1669dd6 commit 5c8ef0c

File tree

2 files changed

+49
-52
lines changed

2 files changed

+49
-52
lines changed

ovh/resource_cloud_project_kube_nodepool.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,28 +154,28 @@ func resourceCloudProjectKubeNodePool() *schema.Resource {
154154
Schema: map[string]*schema.Schema{
155155
"metadata": {
156156
Description: "metadata",
157-
Optional: true,
157+
Required: true,
158158
Type: schema.TypeSet,
159159
MaxItems: 1,
160160
Set: CustomSchemaSetFunc(),
161161
Elem: &schema.Resource{
162162
Schema: map[string]*schema.Schema{
163163
"finalizers": {
164164
Description: "finalizers",
165-
Optional: true,
165+
Required: true,
166166
Type: schema.TypeList,
167167
Elem: &schema.Schema{Type: schema.TypeString},
168168
},
169169
"labels": {
170170
Description: "labels",
171-
Optional: true,
171+
Required: true,
172172
Type: schema.TypeMap,
173173
Elem: &schema.Schema{Type: schema.TypeString},
174174
Set: schema.HashString,
175175
},
176176
"annotations": {
177177
Description: "annotations",
178-
Optional: true,
178+
Required: true,
179179
Type: schema.TypeMap,
180180
Elem: &schema.Schema{Type: schema.TypeString},
181181
Set: schema.HashString,
@@ -185,20 +185,20 @@ func resourceCloudProjectKubeNodePool() *schema.Resource {
185185
},
186186
"spec": {
187187
Description: "spec",
188-
Optional: true,
188+
Required: true,
189189
Type: schema.TypeSet,
190190
MaxItems: 1,
191191
Set: CustomSchemaSetFunc(),
192192
Elem: &schema.Resource{
193193
Schema: map[string]*schema.Schema{
194194
"unschedulable": {
195195
Description: "unschedulable",
196-
Optional: true,
196+
Required: true,
197197
Type: schema.TypeBool,
198198
},
199199
"taints": {
200200
Description: "taints",
201-
Optional: true,
201+
Required: true,
202202
Type: schema.TypeList,
203203
Elem: &schema.Schema{
204204
Type: schema.TypeMap,

ovh/types_cloud_project_kube_nodepool.go

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
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 {
3233
type TaintEffectType int
3334

3435
type 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

4041
type CloudProjectKubeNodePoolTemplateMetadata struct {
@@ -45,12 +46,12 @@ type CloudProjectKubeNodePoolTemplateMetadata struct {
4546

4647
type CloudProjectKubeNodePoolTemplateSpec struct {
4748
Taints []Taint `json:"taints"`
48-
Unschedulable *bool `json:"unschedulable"`
49+
Unschedulable bool `json:"unschedulable"`
4950
}
5051

5152
type 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

5657
type CloudProjectKubeNodePoolUpdateOpts struct {
@@ -96,8 +97,8 @@ func (opts *CloudProjectKubeNodePoolCreateOpts) FromResource(d *schema.ResourceD
9697
func 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

Comments
 (0)