Skip to content
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

[BUG] runtime error: index out of range [0] with length 0 #427

Closed
NMamont opened this issue Jun 6, 2023 · 1 comment · Fixed by #433
Closed

[BUG] runtime error: index out of range [0] with length 0 #427

NMamont opened this issue Jun 6, 2023 · 1 comment · Fixed by #433
Assignees
Labels
Product: Managed Kubernetes Service Status: Coming Soon The feature will hit GA usually in less than 2 months Type: Bug

Comments

@NMamont
Copy link

NMamont commented Jun 6, 2023

Describe the bug

I've already created a node pool, with only annotations in template attributes. After upgrading the provider from 0.27 to 0.30 version, I faced that for this node pool tf tried to update each time the template block, so I decided to add labels also, to avoid these trash messages.

  ~ resource "ovh_cloud_project_kube_nodepool" "this" {
        id               = "xxx"
        name             = "nodepool-xxx"
        # (18 unchanged attributes hidden)

      - template {
          - metadata {
              - annotations = {
                  - "class" = "general"
                  - "type"  = "infra-nodes"
                } -> null
              - finalizers  = [] -> null
              - labels      = {} -> null
            }
        }
      + template {
          + metadata {
              + annotations = {
                  + "class" = "general"
                  + "type"  = "infra-nodes"
                }
              + finalizers  = []
            }

          + spec {
              + taints        = []
              + unschedulable = false
            }
        }
    }
      - template {
          - metadata {
              - annotations = {
                  - "class" = "general"
                  - "type"  = "infra-nodes"
                } -> null
              - finalizers  = [] -> null
              - labels      = {} -> null
            }
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

But after adding labels, the provider was crushed with panic.

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

OVH Terraform Provider Version

terraform -v
Terraform v1.2.9
on darwin_amd64
+ provider registry.terraform.io/ovh/ovh v0.30.0

Your version of Terraform is out of date! The latest version
is 1.4.6. You can update by downloading from https://www.terraform.io/downloads.html

Affected Resource(s)

Please list the resources as a list, for example:

  • ovh_cloud_project_kube_nodepool

If this issue appears to affect multiple resources, it may be an issue with Terraform's core.

Terraform Configuration Files

resource "ovh_cloud_project_kube_nodepool" "this" {
  service_name  = var.service_name
  kube_id       = ovh_cloud_project_kube.mycluster.id
  for_each      = { for k, v in local.node_pools : k => v }
  autoscale     = lookup(each.value, "autoscale", var.node_pool_default["autoscale"])
  name          = lookup(each.value, "name", var.node_pool_default["autoscale"])
  flavor_name   = lookup(each.value, "flavor_name", var.node_pool_default["flavor_name"])
  desired_nodes = lookup(each.value, "desired_nodes", var.node_pool_default["desired_nodes"])
  max_nodes     = lookup(each.value, "max_nodes", var.node_pool_default["max_nodes"])
  min_nodes     = lookup(each.value, "min_nodes", var.node_pool_default["min_nodes"])
  template {
    metadata {
      annotations = lookup(each.value, "annotations", var.node_pool_default["annotations"])
      labels      = lookup(each.value, "labels", var.node_pool_default["labels"])
    }
    spec {
      taints = lookup(each.value, "taints", var.node_pool_default["taints"])
      unschedulable = lookup(each.value, "unschedulable", var.node_pool_default["unschedulable"])
    }
  }
}


locals {
  node_pools = [
    {
      autoscale     = true
      name          = "xxx"
      flavor_name   = "b2-7"
      desired_nodes = 4
      max_nodes     = 7
      min_nodes     = 4
      annotations = {
        type  = "infra-nodes"
        class = "general"
      }
      labels = {
        type  = "infra-nodes"
        class = "general"
      }
    }
    ]
    
 variable "node_pool_default" {
  type = any
  default = {
    name          = "default-node-pool"
    flavor_name   = "d2-8"
    autoscale     = true
    desired_nodes = 1
    max_nodes     = 2
    min_nodes     = 1
    annotations   = {}
    labels        = {}
    taints        = []
    unschedulable = false
  }
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.
https://gist.github.com/NMamont/ab2669bfe26d529d7f7d164e04cd4fa2

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

Terraform should update labels field for nodepool

Terraform will perform the following actions:

  # ovh_cloud_project_kube_nodepool.this["0"] will be updated in-place
  ~ resource "ovh_cloud_project_kube_nodepool" "this" {
        id               = "xxx"
        name             = "nodepool-xxx"
        # (18 unchanged attributes hidden)

      + template {
          + metadata {
              + annotations = {
                  + "class" = "general"
                  + "type"  = "infra-nodes"
                }
              + finalizers  = []
              + labels      = {
                  + "class" = "general"
                  + "type"  = "infra-nodes"
                }
            }

          + spec {
              + taints        = []
              + unschedulable = false
            }
        }
      - template {
          - metadata {
              - annotations = {
                  - "class" = "general"
                  - "type"  = "infra-nodes"
                } -> null
              - finalizers  = [] -> null
              - labels      = {} -> null
            }
        }
    }

Actual Behavior

Terraform crashed on update operation

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

References

Additional context

@yomovh
Copy link
Contributor

yomovh commented Jun 15, 2023

Thanks for your issue. I have redirected it to the appropriate team.

matprig pushed a commit to matprig/terraform-provider-ovh-k8s that referenced this issue Jun 16, 2023
spec in template is optional
matprig pushed a commit to matprig/terraform-provider-ovh-k8s that referenced this issue Jun 16, 2023
remove setting to nil when deserialize
matprig pushed a commit to matprig/terraform-provider-ovh-k8s that referenced this issue Jun 16, 2023
return empty template if not specified
@matprig matprig mentioned this issue Jun 26, 2023
13 tasks
@yomovh yomovh added Status: Coming Soon The feature will hit GA usually in less than 2 months and removed Status: Triage labels Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Product: Managed Kubernetes Service Status: Coming Soon The feature will hit GA usually in less than 2 months Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants