alekc / terraform-provider-kubectl

Mozilla Public License 2.0
160 stars 9 forks source link

Support resource status conditions using `wait_for` in `kubectl_manifest` #155

Open jkabonickAtOlo opened 1 month ago

jkabonickAtOlo commented 1 month ago

We have a use-case where we want to wait for specific status conditions to be true on manifests that are installed with this provider. This is currently being done using multiple conditions as mentioned in this comment. However, using an index on a list object is problematic since there is no guarantee of ordering.

I'd like to propose extending the wait_for block, specifically to support waiting for status conditions. The Hashicorp Kubernetes provider offers support for this on its kubernetes_manifest resource. However, there are issues with that provider that prevent us from using it for our use-case.

For example, extending it to allow a new condition block could allow waiting for specific status conditions to be satisfied, in addition to the generic fields provided.

wait_for {
    condition {
      type = "ContainersReady"
      status = "True"
    }
    condition {
      type = "Ready"
      status = "True"
    }
    field {
      key = "status.containerStatuses.[0].ready"
      value = "True"
    }
    field {
      key = "status.phase"
      value = "Running"
    }
    field {
      key = ""status.containerStatuses.[0].ready""
      value = "True"
    }
  }

I'm happy to open a PR if you are open to contributions.

alekc commented 1 month ago

Hi @jkabonickAtOlo,

I am not against this (and proposed implementation above is not a breaking change). All PR are welcome (but please add some tests as well covering new functionality).