No need to propagate ttlsecondsafterfinished
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
parent
616033fc0e
commit
83c91ac909
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
// RemoveIrrelevantField used to remove fields that generated by kube-apiserver and no need(or can't) propagate to
|
// RemoveIrrelevantField used to remove fields that generated by kube-apiserver and no need(or can't) propagate to
|
||||||
// member clusters.
|
// member clusters.
|
||||||
func RemoveIrrelevantField(workload *unstructured.Unstructured) error {
|
func RemoveIrrelevantField(workload *unstructured.Unstructured, extraHooks ...func(*unstructured.Unstructured)) error {
|
||||||
// populated by the kubernetes.
|
// populated by the kubernetes.
|
||||||
unstructured.RemoveNestedField(workload.Object, "metadata", "creationTimestamp")
|
unstructured.RemoveNestedField(workload.Object, "metadata", "creationTimestamp")
|
||||||
|
|
||||||
|
@ -61,9 +61,10 @@ func RemoveIrrelevantField(workload *unstructured.Unstructured) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if job.Spec.ManualSelector == nil || !*job.Spec.ManualSelector {
|
if job.Spec.ManualSelector == nil || !*job.Spec.ManualSelector {
|
||||||
return removeGenerateSelectorOfJob(workload)
|
if err = removeGenerateSelectorOfJob(workload); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +82,9 @@ func RemoveIrrelevantField(workload *unstructured.Unstructured) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := range extraHooks {
|
||||||
|
extraHooks[i](workload)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,3 +123,16 @@ func removeGenerateSelectorOfJob(workload *unstructured.Unstructured) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveJobTTLSeconds removes the '.spec.ttlSecondsAfterFinished' from a Job.
|
||||||
|
// The reason for removing it is that the Job propagated by Karmada probably be automatically deleted
|
||||||
|
// from member clusters(by 'ttl-after-finished' controller in member clusters). That will cause a conflict if
|
||||||
|
// Karmada tries to re-create it. See https://github.com/karmada-io/karmada/issues/2197 for more details.
|
||||||
|
//
|
||||||
|
// It is recommended to enable the `ttl-after-finished` controller in the Karmada control plane.
|
||||||
|
// See https://karmada.io/docs/administrator/configuration/configure-controllers#ttl-after-finished for more details.
|
||||||
|
func RemoveJobTTLSeconds(workload *unstructured.Unstructured) {
|
||||||
|
if workload.GetKind() == util.JobKind {
|
||||||
|
unstructured.RemoveNestedField(workload.Object, "spec", "ttlSecondsAfterFinished")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (a *MutatingAdmission) Handle(ctx context.Context, req admission.Request) a
|
||||||
return admission.Errored(http.StatusInternalServerError, err)
|
return admission.Errored(http.StatusInternalServerError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = prune.RemoveIrrelevantField(workloadObj)
|
err = prune.RemoveIrrelevantField(workloadObj, prune.RemoveJobTTLSeconds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to remove irrelevant field for work(%s): %v", work.Name, err)
|
klog.Errorf("Failed to remove irrelevant field for work(%s): %v", work.Name, err)
|
||||||
return admission.Errored(http.StatusInternalServerError, err)
|
return admission.Errored(http.StatusInternalServerError, err)
|
||||||
|
|
Loading…
Reference in New Issue