Skip to content

Address MetalLB CRDs Race Condition #99

@shakir85

Description

@shakir85

Some ideas to give the API Server enough time to reigster the custom resources before start deploying CRDs

Option 1

In the metal-crd module, add this:

resource "null_resource" "wait_for_metallb_crds" {
  provisioner "local-exec" {
    command = <<EOT
    for crd in ipaddresspools.metallb.io l2advertisements.metallb.io; do
      echo "Waiting for CRD $crd to be registered..."
      until kubectl get crd $crd >/dev/null 2>&1; do
        sleep 5
      done
    done
    EOT
  }
}

Then make the resources depend on it

resource "kubernetes_manifest" "ip_address_pool" {
  manifest = { ... }
  depends_on = [null_resource.wait_for_metallb_crds]
}

Option 2

It looks like Terraform 1.13+ has a time_sleep resource
https://github.com/hashicorp/terraform-provider-time/blob/main/docs/resources/sleep.md

Maybe combine MetalLB chart and its CRDs in a single module and do something like this

resource "time_sleep" "wait_30s" {
  depends_on = [helm_release.metallb] # or wherever CRDs are applied
  create_duration = "30s"
}

Then depend on it

resource "kubernetes_manifest" "ip_address_pool" {
  depends_on = [time_sleep.wait_30s]
}

Option 3

Handle this outsitde Terraform/grunt, in GHA for example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions