From 209b32684ea76c5a49ebc68b9990746bbd42c414 Mon Sep 17 00:00:00 2001 From: Janet Kuo Date: Tue, 24 Jul 2018 15:04:13 -0700 Subject: [PATCH] Add TTLAfterFinished alpha feature --- pkg/apis/batch/types.go | 12 ++++++++++++ pkg/apis/batch/v1/conversion.go | 2 ++ pkg/features/kube_features.go | 7 +++++++ staging/src/k8s.io/api/batch/v1/types.go | 12 ++++++++++++ 4 files changed, 33 insertions(+) diff --git a/pkg/apis/batch/types.go b/pkg/apis/batch/types.go index 32d921fb6af..d62cdaf3bbb 100644 --- a/pkg/apis/batch/types.go +++ b/pkg/apis/batch/types.go @@ -138,6 +138,18 @@ type JobSpec struct { // Describes the pod that will be created when executing a job. Template api.PodTemplateSpec + + // ttlSecondsAfterFinished limits the lifetime of a Job that has finished + // execution (either Complete or Failed). If this field is set, + // ttlSecondsAfterFinished after the Job finishes, it is eligible to be + // automatically deleted. When the Job is being deleted, its lifecycle + // guarantees (e.g. finalizers) will be honored. If this field is unset, + // the Job won't be automatically deleted. If this field is set to zero, + // the Job becomes eligible to be deleted immediately after it finishes. + // This field is alpha-level and is only honored by servers that enable the + // TTLAfterFinished feature. + // +optional + TTLSecondsAfterFinished *int32 } // JobStatus represents the current state of a Job. diff --git a/pkg/apis/batch/v1/conversion.go b/pkg/apis/batch/v1/conversion.go index 9c20fa93702..7c715542367 100644 --- a/pkg/apis/batch/v1/conversion.go +++ b/pkg/apis/batch/v1/conversion.go @@ -54,6 +54,7 @@ func Convert_batch_JobSpec_To_v1_JobSpec(in *batch.JobSpec, out *batchv1.JobSpec out.Completions = in.Completions out.ActiveDeadlineSeconds = in.ActiveDeadlineSeconds out.BackoffLimit = in.BackoffLimit + out.TTLSecondsAfterFinished = in.TTLSecondsAfterFinished out.Selector = in.Selector if in.ManualSelector != nil { out.ManualSelector = new(bool) @@ -73,6 +74,7 @@ func Convert_v1_JobSpec_To_batch_JobSpec(in *batchv1.JobSpec, out *batch.JobSpec out.Completions = in.Completions out.ActiveDeadlineSeconds = in.ActiveDeadlineSeconds out.BackoffLimit = in.BackoffLimit + out.TTLSecondsAfterFinished = in.TTLSecondsAfterFinished out.Selector = in.Selector if in.ManualSelector != nil { out.ManualSelector = new(bool) diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 9fdefcf71d5..56a7ed33e7d 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -381,6 +381,12 @@ const ( // // Enables control over ProcMountType for containers. ProcMountType utilfeature.Feature = "ProcMountType" + + // owner: @janetkuo + // alpha: v1.12 + // + // Allow TTL controller to clean up Pods and Jobs after they finish. + TTLAfterFinished utilfeature.Feature = "TTLAfterFinished" ) func init() { @@ -445,6 +451,7 @@ var defaultKubernetesFeatureGates = map[utilfeature.Feature]utilfeature.FeatureS SCTPSupport: {Default: false, PreRelease: utilfeature.Alpha}, VolumeSnapshotDataSource: {Default: false, PreRelease: utilfeature.Alpha}, ProcMountType: {Default: false, PreRelease: utilfeature.Alpha}, + TTLAfterFinished: {Default: false, PreRelease: utilfeature.Alpha}, // inherited features from generic apiserver, relisted here to get a conflict if it is changed // unintentionally on either side: diff --git a/staging/src/k8s.io/api/batch/v1/types.go b/staging/src/k8s.io/api/batch/v1/types.go index 84abb1a9015..e9fa61cd045 100644 --- a/staging/src/k8s.io/api/batch/v1/types.go +++ b/staging/src/k8s.io/api/batch/v1/types.go @@ -114,6 +114,18 @@ type JobSpec struct { // Describes the pod that will be created when executing a job. // More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/ Template v1.PodTemplateSpec `json:"template" protobuf:"bytes,6,opt,name=template"` + + // ttlSecondsAfterFinished limits the lifetime of a Job that has finished + // execution (either Complete or Failed). If this field is set, + // ttlSecondsAfterFinished after the Job finishes, it is eligible to be + // automatically deleted. When the Job is being deleted, its lifecycle + // guarantees (e.g. finalizers) will be honored. If this field is unset, + // the Job won't be automatically deleted. If this field is set to zero, + // the Job becomes eligible to be deleted immediately after it finishes. + // This field is alpha-level and is only honored by servers that enable the + // TTLAfterFinished feature. + // +optional + TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"` } // JobStatus represents the current state of a Job.