Deleting a Cron Job

Function

This API is used to delete a cron job.

URI

DELETE /apis/batch/v1beta1/namespaces/{namespace}/cronjobs/{name}

Table 1 describes the parameters of this API.

Table 1 Parameter description

Parameter

Mandatory

Description

pretty

No

If 'true', then the output is pretty printed.

name

Yes

Name of the cron job.

namespace

Yes

Object name and auth scope, such as for teams and projects.

gracePeriodSeconds

No

The duration in seconds before the object should be deleted. Value must be a non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. Zero means immediate deletion.

orphanDependents

No

Deprecated: Use the PropagationPolicy. This field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the "orphan" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.

propagationPolicy

No

Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy. Acceptable values are: 'Orphan' - orphan the dependents; 'Background' - allow the garbage collector to delete the dependents in the background; 'Foreground' - a cascading policy that deletes all dependents in the foreground.

Request

Request parameters:

For the description about request parameters, see Table 2.

Example request:

  • Deleting only the CronJob (the Job and pod are not deleted):
    {
        "kind": "DeleteOptions",
        "apiVersion": "v1",
        "gracePeriodSeconds": 0,
        "propagationPolicy": "Orphan"
    }
  • Deleting the pod, Job, and then the CronJob:
    {
        "kind": "DeleteOptions",
        "apiVersion": "v1",
        "propagationPolicy": "Foreground"
    }
  • Deleting the CronJob, Job, and then the pod:
    {
        "kind": "DeleteOptions",
        "apiVersion": "v1",
        "propagationPolicy": "Background"
    }

Response

Response parameters:

For the description about response parameters, see Table 2.

Example response:

{
  "kind": "CronJob",
  "apiVersion": "batch/v1beta1",
  "metadata": {
    "name": "cronjob-test",
    "namespace": "default",
    "selfLink": "/apis/batch/v1beta1/namespaces/default/cronjobs/cronjob-test",
    "uid": "4d78b666-2200-11e8-96aa-fa163ecd089c",
    "resourceVersion": "441442",
    "creationTimestamp": "2018-03-07T12:08:52Z",
    "deletionTimestamp": "2018-03-07T12:15:11Z",
    "deletionGracePeriodSeconds": 0,
    "annotations": {
      "container.io/container-0": "https://console.huaweicloud.com/swr/dockerimage/nginx.png",
      "description": ""
    },
    "finalizers": [
      "orphan"
    ],
    "enable": true
  },
  "spec": {
    "schedule": "*/59 * * * *",
    "concurrencyPolicy": "Allow",
    "suspend": false,
    "jobTemplate": {
      "metadata": {
        "creationTimestamp": null,
        "enable": true
      },
      "spec": {
        "template": {
          "metadata": {
            "creationTimestamp": null,
            "labels": {
              "sjname": "cronjob-test"
            },
            "enable": true
          },
          "spec": {
            "containers": [
              {
                "name": "container-0",
                "image": "nginx:stable-perl",
                "resources": {

                },
                "lifecycle": {

                },
                "terminationMessagePath": "/dev/termination-log",
                "terminationMessagePolicy": "File",
                "imagePullPolicy": "IfNotPresent"
              }
            ],
            "restartPolicy": "OnFailure",
            "terminationGracePeriodSeconds": 30,
            "dnsPolicy": "ClusterFirst",
            "securityContext": {

            },
            "imagePullSecrets": [
              {
                "name": "default-secret"
              }
            ],
            "schedulerName": "default-scheduler"
          }
        }
      }
    },
    "successfulJobsHistoryLimit": 3,
    "failedJobsHistoryLimit": 1
  },
  "status": {

  }
}

Status Code

Table 2 describes the status code of this API.

Table 2 Status code

Status Code

Description

200

Delete a CronJob resource object successfully.

For the description about error status codes, see Status Code.