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

Terraform destroy doesn't include propagation policy on cron_job

Open kreynoldsf5 opened this issue 3 years ago • 2 comments

The kubernetes provider doesn't specify a propagation policy on 'destroy' for 'kubernetes_cron_job' resources. This means the cluster will use the default for the resource which, for cron jobs, is 'orphan'. This is inconsistent with the default behavior for 'kubectl' and, I think, not consistent with what provider users would expect.

Terraform Version, Provider Version and Kubernetes Version

Terraform version: TF Cloud current
Kubernetes provider version: 2.8.0
Kubernetes version: v1.21.7

Affected Resource(s)

  • kubernetes_cron_job

Terraform Configuration Files

resource "kubernetes_cron_job" "test_cron" {
  metadata {
    name = "test-cron"
    namespace = var.namespace
  }
  spec {
    schedule = "*/6 * * * *"
    job_template {
      metadata {}
      spec {
        template {
          metadata {}
          spec {
            container {
              name  = "test"
              image = "${var.registry_server}/test"
              termination_message_path   = "/dev/termination-log"
              termination_message_policy = "File"
              image_pull_policy          = "Always"
            }
            restart_policy                   = "OnFailure"
            termination_grace_period_seconds = 30
            dns_policy                       = "ClusterFirst"
            image_pull_secrets {
              name = "registry-secret"
            }
          }
        }
      }
    }
    failed_jobs_history_limit = 1
  }
}

nothing special.

Debug Output

Highly truncated:

 ---[ REQUEST ]---------------------------------------
 DELETE /api/vk8s/namespaces/example/example/apis/batch/v1beta1/namespaces/example/cronjobs/example HTTP/1.1
 {
  "kind": "DeleteOptions",
  "apiVersion": "batch/v1beta1"
 }

 ---[ RESPONSE ]--------------------------------------
 HTTP/2.0 200 OK
 
 {
  "kind": "CronJob",
  "apiVersion": "batch/v1beta1",
  "metadata": {
   "name": "test",
   "namespace": "example",
   "finalizers": [
    "orphan"
   ],
<cut>

Steps to Reproduce

  1. create a 'kubernetes_cron_job'.
  2. Destroy the 'kubernetes_cron_job'

Expected Behavior

I think most users would expect this operation to work like a 'kubectl delete'.

 Request Body: {"propagationPolicy":"Background"}
 DELETE https://cluster/api/vk8s/namespaces/example/example/apis/batch/v1beta1/namespaces/example/cronjobs/example
 Response Status: 200 OK in 168 milliseconds
 Response Headers:
<cut>
Response Body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success","details":{"name":"example","group":"batch","kind":"cronjobs","uid":"6f8ce71d-3d9d-4997-a0e3-d290c4c35c2d"}}
Warning: batch/v1beta1 CronJob is deprecated in v1.22+, unavailable in v1.25+
cronjob.batch "example" deleted
 GET https://cluster/api/vk8s/namespaces/example/example/apis/batch/v1beta1/namespaces/example/cronjobs?fieldSelector=metadata.name%3Dexample
 Request Headers:
     Accept: application/json
     User-Agent: kubectl/v1.23.4 (darwin/arm64) kubernetes/e6c093d
 Response Status: 200 OK in 102 milliseconds
 Response Headers:
<cut>
I0318 23:07:24.091970   34991 request.go:1181] Response Body: {"kind":"CronJobList","apiVersion":"batch/v1beta1","metadata":{"selfLink":"/apis/batch/v1beta1/namespaces/example/cronjobs","resourceVersion":"1397745967"},"items":[]}

Actual Behavior

No 'propagationPolicy' is included in the DELETE request from the provider.

kreynoldsf5 avatar Mar 22 '22 01:03 kreynoldsf5

Just saw this when using CDK for Terraform.

BasitAli avatar Mar 02 '23 19:03 BasitAli

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

github-actions[bot] avatar Mar 02 '24 00:03 github-actions[bot]