Skip to content

Fix/427 #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 22, 2023
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
24 changes: 12 additions & 12 deletions ovh/resource_cloud_project_kube_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,28 @@ func resourceCloudProjectKubeNodePool() *schema.Resource {
Schema: map[string]*schema.Schema{
"metadata": {
Description: "metadata",
Optional: true,
Required: true,
Type: schema.TypeSet,
MaxItems: 1,
Set: CustomSchemaSetFunc(),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"finalizers": {
Description: "finalizers",
Optional: true,
Required: true,
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
},
"labels": {
Description: "labels",
Optional: true,
Required: true,
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"annotations": {
Description: "annotations",
Optional: true,
Required: true,
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Expand All @@ -185,20 +185,20 @@ func resourceCloudProjectKubeNodePool() *schema.Resource {
},
"spec": {
Description: "spec",
Optional: true,
Required: true,
Type: schema.TypeSet,
MaxItems: 1,
Set: CustomSchemaSetFunc(),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"unschedulable": {
Description: "unschedulable",
Optional: true,
Required: true,
Type: schema.TypeBool,
},
"taints": {
Description: "taints",
Optional: true,
Required: true,
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeMap,
Expand Down Expand Up @@ -259,8 +259,8 @@ func resourceCloudProjectKubeNodePoolCreate(d *schema.ResourceData, meta interfa
return err
}

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

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

func waitForCloudProjectKubeNodePoolReady(client *ovh.Client, serviceName, kubeId, id string, timeout time.Duration) error {
func waitForCloudProjectKubeNodePoolWithStateTarget(client *ovh.Client, serviceName, kubeId, id string, timeout time.Duration, stateTargets []string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{"INSTALLING", "UPDATING", "REDEPLOYING", "RESIZING", "DOWNSCALING", "UPSCALING"},
Target: []string{"READY"},
Target: stateTargets,
Refresh: func() (interface{}, string, error) {
res := &CloudProjectKubeNodePoolResponse{}
endpoint := fmt.Sprintf("/cloud/project/%s/kube/%s/nodepool/%s", serviceName, kubeId, id)
Expand Down
169 changes: 95 additions & 74 deletions ovh/resource_cloud_project_kube_nodepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,100 +75,113 @@ func testSweepCloudProjectKubeNodePool(region string) error {

var testAccCloudProjectKubeNodePoolConfig = `
resource "ovh_cloud_project_kube" "cluster" {
service_name = "%s"
name = "%s"
region = "%s"
version = "%s"
service_name = "%s"
name = "%s"
region = "%s"
version = "%s"
}

resource "ovh_cloud_project_kube_nodepool" "pool" {
service_name = ovh_cloud_project_kube.cluster.service_name
kube_id = ovh_cloud_project_kube.cluster.id
name = ovh_cloud_project_kube.cluster.name
flavor_name = "b2-7"
desired_nodes = 1
min_nodes = 0
max_nodes = 1
template {
metadata {
annotations = {
a1 = "av1"
}
finalizers = ["finalizer.extensions/v1beta1"]
labels = {
l1 = "lv1"
}
}
spec {
unschedulable = false
taints = [
{
effect = "PreferNoSchedule"
key = "t1"
value = "tv1"
}
]
}
}
service_name = ovh_cloud_project_kube.cluster.service_name
kube_id = ovh_cloud_project_kube.cluster.id
name = ovh_cloud_project_kube.cluster.name
flavor_name = "b2-7"
desired_nodes = 1
min_nodes = 0
max_nodes = 1
template {
metadata {
annotations = {
a1 = "av1"
}
finalizers = ["finalizer.extensions/v1beta1"]
labels = {
l1 = "lv1"
}
}
spec {
unschedulable = false
taints = [
{
effect = "PreferNoSchedule"
key = "t1"
value = "tv1"
}
]
}
}
}

`

var testAccCloudProjectKubeNodePoolConfigUpdated = `
resource "ovh_cloud_project_kube" "cluster" {
service_name = "%s"
name = "%s"
region = "%s"
version = "%s"
service_name = "%s"
name = "%s"
region = "%s"
version = "%s"
}

resource "ovh_cloud_project_kube_nodepool" "pool" {
service_name = ovh_cloud_project_kube.cluster.service_name
kube_id = ovh_cloud_project_kube.cluster.id
name = ovh_cloud_project_kube.cluster.name
flavor_name = "b2-7"
desired_nodes = 2
min_nodes = 0
max_nodes = 2
template {
metadata {
annotations = {
a2 = "av2"
}
labels = {
l2 = "lv2"
}
}
}
service_name = ovh_cloud_project_kube.cluster.service_name
kube_id = ovh_cloud_project_kube.cluster.id
name = ovh_cloud_project_kube.cluster.name
flavor_name = "b2-7"
desired_nodes = 2
min_nodes = 0
max_nodes = 2
template {
metadata {
annotations = {
a2 = "av2"
}
finalizers = []
labels = {
l2 = "lv2"
}
}
spec {
unschedulable = false
taints = []
}
}
}

`

var testAccCloudProjectKubeNodePoolConfigUpdatedScaleToZero = `
resource "ovh_cloud_project_kube" "cluster" {
service_name = "%s"
name = "%s"
region = "%s"
version = "%s"
service_name = "%s"
name = "%s"
region = "%s"
version = "%s"
}

resource "ovh_cloud_project_kube_nodepool" "pool" {
service_name = ovh_cloud_project_kube.cluster.service_name
kube_id = ovh_cloud_project_kube.cluster.id
name = ovh_cloud_project_kube.cluster.name
flavor_name = "b2-7"
desired_nodes = 0
min_nodes = 0
max_nodes = 2
template {
metadata {
annotations = {
a2 = "av2"
}
labels = {
l2 = "lv2"
}
}
}
service_name = ovh_cloud_project_kube.cluster.service_name
kube_id = ovh_cloud_project_kube.cluster.id
name = ovh_cloud_project_kube.cluster.name
flavor_name = "b2-7"
desired_nodes = 0
min_nodes = 0
max_nodes = 2
template {
metadata {
annotations = {
a2 = "av2"
}
finalizers = []
labels = {
l2 = "lv2"
}
}
spec {
unschedulable = false
taints = []
}
}
}

`

func TestAccCloudProjectKubeNodePool(t *testing.T) {
Expand Down Expand Up @@ -218,9 +231,11 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "desired_nodes", "1"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "min_nodes", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "max_nodes", "1"),

resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.annotations.a1", "av1"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.finalizers.0", "finalizer.extensions/v1beta1"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.labels.l1", "lv1"),

resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.0.effect", "PreferNoSchedule"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.0.key", "t1"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.0.value", "tv1"),
Expand All @@ -239,10 +254,13 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "desired_nodes", "2"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "min_nodes", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "max_nodes", "2"),

resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.annotations.a2", "av2"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.finalizers.#", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.labels.l2", "lv2"),

resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.#", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.unschedulable", "false"),
),
},
{
Expand All @@ -257,10 +275,13 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "desired_nodes", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "min_nodes", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "max_nodes", "2"),

resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.annotations.a2", "av2"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.finalizers.#", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.labels.l2", "lv2"),

resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.#", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.unschedulable", "false"),
),
},
{
Expand Down
Loading