terraform-provider-kubernetes icon indicating copy to clipboard operation
terraform-provider-kubernetes copied to clipboard

kubernetes_job_v1 does not support suspend field

Open davgia opened this issue 1 year ago • 3 comments

I am creating this new issue because the original one has been closed without resolving it (#1739).

Terraform Version, Provider Version and Kubernetes Version

Terraform version: v1.9.6
Kubernetes provider version: v2.32.0
Kubernetes version: v1.30.6-eks-7f9249a

Affected Resource(s)

  • kubernetes_job_v1

Terraform Configuration Files

resource "kubernetes_job_v1" "restore_db" {
  metadata {
    name      = "restore-db"
    namespace = data.kubernetes_namespace_v1.database_management.id
  }

  spec {
    suspend = true # <--- this field does not exist
    backoff_limit = 1
    template {
      metadata {
        labels = local.restore_common_labels
      }
      spec {
        restart_policy = "Never"
        container {
          name  = "database-restorer"
          image = "mcr.microsoft.com/mssql-tools"
          command = [
            "/bin/bash",
            "-c"
          ]
          args = [
            "/opt/mssql-tools/bin/sqlcmd -V16 -b -S $DATABASE_INSTANCE -U $MASTER_USERNAME -i /data/restore_db.sql"
          ]
          env {
            name  = "DATABASE_INSTANCE"
            value = "${data.aws_db_instance.target.address},${data.aws_db_instance.target.db_instance_port}"
          }
          env {
            name  = "MASTER_USERNAME"
            value = local.rds_master_username
          }
          env_from {
            secret_ref {
              name = kubernetes_secret_v1.restore_db.metadata.0.name
            }
          }
          volume_mount {
            name       = "script-volume"
            mount_path = "/data"
          }
        }
        volume {
          name = "script-volume"
          config_map {
            name = kubernetes_config_map_v1.restore_db.metadata.0.name
          }
        }
      }
    }
  }
}

Output

│ Error: Unsupported argument
│
│   on db_restore.tf line 53, in resource "kubernetes_job_v1" "restore_db":
│   53:     suspend = true
│
│ An argument named "suspend" is not expected here.

Steps to Reproduce

  1. terraform validate

Expected Behavior

What should have happened?

Kubernetes job spec support the suspend field since v1.21, I should be able to specify the suspend field in the kubernetes_job_v1 resource too.

Actual Behavior

What actually happened? I cannot specify the suspend field, terraform rejects it. It is strange because kubernetes_cronjob_v1 supports it.

davgia avatar Nov 22 '24 09:11 davgia

I'd like to take a look at the issue.

marsskop avatar Jan 28 '25 10:01 marsskop

So. I think the main reason suspend was not implemented for a Job resource is existence of wait_for_completion which tells Terraform to wait until the Job either succeeds or fails. If suspend is set to true, wait_for_completion cannot be set to true, because it is unclear when (and whether at all) the user sets suspend to false and resumes the job.

A proposal:

  • do not allow setting both suspend and wait_for_completion to true at the same time
  • suspend is allowed to change, and changing suspend leads to resource update in-place
"suspend": {
	Type:        schema.TypeBool,
	Optional:    true,
	ForceNew:    false,
	Description: "Tells the controller to suspend subsequent executions, and terminate all active executions. suspend and wait_for_completion cannot be both set to true. Defaults to false. More info: https://kubernetes.io/docs/concepts/workloads/controllers/job/#suspending-a-job",
},

What do you think?

marsskop avatar Feb 01 '25 19:02 marsskop

Hi @marsskop,

for me your proposal is sound.

davgia avatar Feb 01 '25 19:02 davgia