Skip to content

Commit cc14f05

Browse files
authored
Merge pull request #433 from matprig/fix/427
Fix/427
2 parents 9a594f0 + 1b01ec5 commit cc14f05

File tree

4 files changed

+251
-213
lines changed

4 files changed

+251
-213
lines changed

ovh/resource_cloud_project_kube_nodepool.go

Lines changed: 12 additions & 12 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,
@@ -259,8 +259,8 @@ func resourceCloudProjectKubeNodePoolCreate(d *schema.ResourceData, meta interfa
259259
return err
260260
}
261261

262-
log.Printf("[DEBUG] Waiting for nodepool %s to be READY", res.Id)
263-
err = waitForCloudProjectKubeNodePoolReady(config.OVHClient, serviceName, kubeId, res.Id, d.Timeout(schema.TimeoutCreate))
262+
log.Printf("[DEBUG] Waiting for nodepool %s to be READY or ERROR", res.Id)
263+
err = waitForCloudProjectKubeNodePoolWithStateTarget(config.OVHClient, serviceName, kubeId, res.Id, d.Timeout(schema.TimeoutCreate), []string{"READY", "ERROR"})
264264
if err != nil {
265265
return fmt.Errorf("timeout while waiting nodepool %s to be READY: %w", res.Id, err)
266266
}
@@ -314,7 +314,7 @@ func resourceCloudProjectKubeNodePoolUpdate(d *schema.ResourceData, meta interfa
314314
}
315315

316316
log.Printf("[DEBUG] Waiting for nodepool %s to be READY", d.Id())
317-
err = waitForCloudProjectKubeNodePoolReady(config.OVHClient, serviceName, kubeId, d.Id(), d.Timeout(schema.TimeoutUpdate))
317+
err = waitForCloudProjectKubeNodePoolWithStateTarget(config.OVHClient, serviceName, kubeId, d.Id(), d.Timeout(schema.TimeoutUpdate), []string{"READY"})
318318
if err != nil {
319319
return fmt.Errorf("timeout while waiting nodepool %s to be READY: %w", d.Id(), err)
320320
}
@@ -355,10 +355,10 @@ func cloudProjectKubeNodePoolExists(serviceName, kubeId, id string, client *ovh.
355355
return client.Get(endpoint, res)
356356
}
357357

358-
func waitForCloudProjectKubeNodePoolReady(client *ovh.Client, serviceName, kubeId, id string, timeout time.Duration) error {
358+
func waitForCloudProjectKubeNodePoolWithStateTarget(client *ovh.Client, serviceName, kubeId, id string, timeout time.Duration, stateTargets []string) error {
359359
stateConf := &resource.StateChangeConf{
360360
Pending: []string{"INSTALLING", "UPDATING", "REDEPLOYING", "RESIZING", "DOWNSCALING", "UPSCALING"},
361-
Target: []string{"READY"},
361+
Target: stateTargets,
362362
Refresh: func() (interface{}, string, error) {
363363
res := &CloudProjectKubeNodePoolResponse{}
364364
endpoint := fmt.Sprintf("/cloud/project/%s/kube/%s/nodepool/%s", serviceName, kubeId, id)

ovh/resource_cloud_project_kube_nodepool_test.go

Lines changed: 95 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -75,100 +75,113 @@ func testSweepCloudProjectKubeNodePool(region string) error {
7575

7676
var testAccCloudProjectKubeNodePoolConfig = `
7777
resource "ovh_cloud_project_kube" "cluster" {
78-
service_name = "%s"
79-
name = "%s"
80-
region = "%s"
81-
version = "%s"
78+
service_name = "%s"
79+
name = "%s"
80+
region = "%s"
81+
version = "%s"
8282
}
8383
8484
resource "ovh_cloud_project_kube_nodepool" "pool" {
85-
service_name = ovh_cloud_project_kube.cluster.service_name
86-
kube_id = ovh_cloud_project_kube.cluster.id
87-
name = ovh_cloud_project_kube.cluster.name
88-
flavor_name = "b2-7"
89-
desired_nodes = 1
90-
min_nodes = 0
91-
max_nodes = 1
92-
template {
93-
metadata {
94-
annotations = {
95-
a1 = "av1"
96-
}
97-
finalizers = ["finalizer.extensions/v1beta1"]
98-
labels = {
99-
l1 = "lv1"
100-
}
101-
}
102-
spec {
103-
unschedulable = false
104-
taints = [
105-
{
106-
effect = "PreferNoSchedule"
107-
key = "t1"
108-
value = "tv1"
109-
}
110-
]
111-
}
112-
}
85+
service_name = ovh_cloud_project_kube.cluster.service_name
86+
kube_id = ovh_cloud_project_kube.cluster.id
87+
name = ovh_cloud_project_kube.cluster.name
88+
flavor_name = "b2-7"
89+
desired_nodes = 1
90+
min_nodes = 0
91+
max_nodes = 1
92+
template {
93+
metadata {
94+
annotations = {
95+
a1 = "av1"
96+
}
97+
finalizers = ["finalizer.extensions/v1beta1"]
98+
labels = {
99+
l1 = "lv1"
100+
}
101+
}
102+
spec {
103+
unschedulable = false
104+
taints = [
105+
{
106+
effect = "PreferNoSchedule"
107+
key = "t1"
108+
value = "tv1"
109+
}
110+
]
111+
}
112+
}
113113
}
114+
114115
`
115116

116117
var testAccCloudProjectKubeNodePoolConfigUpdated = `
117118
resource "ovh_cloud_project_kube" "cluster" {
118-
service_name = "%s"
119-
name = "%s"
120-
region = "%s"
121-
version = "%s"
119+
service_name = "%s"
120+
name = "%s"
121+
region = "%s"
122+
version = "%s"
122123
}
123124
124125
resource "ovh_cloud_project_kube_nodepool" "pool" {
125-
service_name = ovh_cloud_project_kube.cluster.service_name
126-
kube_id = ovh_cloud_project_kube.cluster.id
127-
name = ovh_cloud_project_kube.cluster.name
128-
flavor_name = "b2-7"
129-
desired_nodes = 2
130-
min_nodes = 0
131-
max_nodes = 2
132-
template {
133-
metadata {
134-
annotations = {
135-
a2 = "av2"
136-
}
137-
labels = {
138-
l2 = "lv2"
139-
}
140-
}
141-
}
126+
service_name = ovh_cloud_project_kube.cluster.service_name
127+
kube_id = ovh_cloud_project_kube.cluster.id
128+
name = ovh_cloud_project_kube.cluster.name
129+
flavor_name = "b2-7"
130+
desired_nodes = 2
131+
min_nodes = 0
132+
max_nodes = 2
133+
template {
134+
metadata {
135+
annotations = {
136+
a2 = "av2"
137+
}
138+
finalizers = []
139+
labels = {
140+
l2 = "lv2"
141+
}
142+
}
143+
spec {
144+
unschedulable = false
145+
taints = []
146+
}
147+
}
142148
}
149+
143150
`
144151

145152
var testAccCloudProjectKubeNodePoolConfigUpdatedScaleToZero = `
146153
resource "ovh_cloud_project_kube" "cluster" {
147-
service_name = "%s"
148-
name = "%s"
149-
region = "%s"
150-
version = "%s"
154+
service_name = "%s"
155+
name = "%s"
156+
region = "%s"
157+
version = "%s"
151158
}
152159
153160
resource "ovh_cloud_project_kube_nodepool" "pool" {
154-
service_name = ovh_cloud_project_kube.cluster.service_name
155-
kube_id = ovh_cloud_project_kube.cluster.id
156-
name = ovh_cloud_project_kube.cluster.name
157-
flavor_name = "b2-7"
158-
desired_nodes = 0
159-
min_nodes = 0
160-
max_nodes = 2
161-
template {
162-
metadata {
163-
annotations = {
164-
a2 = "av2"
165-
}
166-
labels = {
167-
l2 = "lv2"
168-
}
169-
}
170-
}
161+
service_name = ovh_cloud_project_kube.cluster.service_name
162+
kube_id = ovh_cloud_project_kube.cluster.id
163+
name = ovh_cloud_project_kube.cluster.name
164+
flavor_name = "b2-7"
165+
desired_nodes = 0
166+
min_nodes = 0
167+
max_nodes = 2
168+
template {
169+
metadata {
170+
annotations = {
171+
a2 = "av2"
172+
}
173+
finalizers = []
174+
labels = {
175+
l2 = "lv2"
176+
}
177+
}
178+
spec {
179+
unschedulable = false
180+
taints = []
181+
}
182+
}
171183
}
184+
172185
`
173186

174187
func TestAccCloudProjectKubeNodePool(t *testing.T) {
@@ -218,9 +231,11 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
218231
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "desired_nodes", "1"),
219232
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "min_nodes", "0"),
220233
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "max_nodes", "1"),
234+
221235
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.annotations.a1", "av1"),
222236
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.finalizers.0", "finalizer.extensions/v1beta1"),
223237
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.labels.l1", "lv1"),
238+
224239
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.0.effect", "PreferNoSchedule"),
225240
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.0.key", "t1"),
226241
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.0.value", "tv1"),
@@ -239,10 +254,13 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
239254
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "desired_nodes", "2"),
240255
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "min_nodes", "0"),
241256
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "max_nodes", "2"),
257+
242258
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.annotations.a2", "av2"),
243259
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.finalizers.#", "0"),
244260
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.labels.l2", "lv2"),
261+
245262
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.#", "0"),
263+
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.unschedulable", "false"),
246264
),
247265
},
248266
{
@@ -257,10 +275,13 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
257275
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "desired_nodes", "0"),
258276
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "min_nodes", "0"),
259277
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "max_nodes", "2"),
278+
260279
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.annotations.a2", "av2"),
261280
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.finalizers.#", "0"),
262281
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.labels.l2", "lv2"),
282+
263283
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.#", "0"),
284+
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.unschedulable", "false"),
264285
),
265286
},
266287
{

0 commit comments

Comments
 (0)