mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #32281 from kargakis/remove-duplicate-createdby
Automatic merge from submit-queue controller: remove duplicate created-by annotation from scheduled jobs @erictune @soltysh
This commit is contained in:
commit
f6b8cdadd7
@ -35,10 +35,6 @@ import (
|
|||||||
|
|
||||||
// Utilities for dealing with Jobs and ScheduledJobs and time.
|
// Utilities for dealing with Jobs and ScheduledJobs and time.
|
||||||
|
|
||||||
const (
|
|
||||||
CreatedByAnnotation = "kubernetes.io/created-by"
|
|
||||||
)
|
|
||||||
|
|
||||||
func inActiveList(sj batch.ScheduledJob, uid types.UID) bool {
|
func inActiveList(sj batch.ScheduledJob, uid types.UID) bool {
|
||||||
for _, j := range sj.Status.Active {
|
for _, j := range sj.Status.Active {
|
||||||
if j.UID == uid {
|
if j.UID == uid {
|
||||||
@ -63,7 +59,7 @@ func deleteFromActiveList(sj *batch.ScheduledJob, uid types.UID) {
|
|||||||
|
|
||||||
// getParentUIDFromJob extracts UID of job's parent and whether it was found
|
// getParentUIDFromJob extracts UID of job's parent and whether it was found
|
||||||
func getParentUIDFromJob(j batch.Job) (types.UID, bool) {
|
func getParentUIDFromJob(j batch.Job) (types.UID, bool) {
|
||||||
creatorRefJson, found := j.ObjectMeta.Annotations[CreatedByAnnotation]
|
creatorRefJson, found := j.ObjectMeta.Annotations[api.CreatedByAnnotation]
|
||||||
if !found {
|
if !found {
|
||||||
glog.V(4).Infof("Job with no created-by annotation, name %s namespace %s", j.Name, j.Namespace)
|
glog.V(4).Infof("Job with no created-by annotation, name %s namespace %s", j.Name, j.Namespace)
|
||||||
return types.UID(""), false
|
return types.UID(""), false
|
||||||
@ -198,7 +194,7 @@ func getJobFromTemplate(sj *batch.ScheduledJob, scheduledTime time.Time) (*batch
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
annotations[CreatedByAnnotation] = string(createdByRefJson)
|
annotations[api.CreatedByAnnotation] = string(createdByRefJson)
|
||||||
// We want job names for a given nominal start time to have a deterministic name to avoid the same job being created twice
|
// We want job names for a given nominal start time to have a deterministic name to avoid the same job being created twice
|
||||||
name := fmt.Sprintf("%s-%d", sj.Name, getTimeHash(scheduledTime))
|
name := fmt.Sprintf("%s-%d", sj.Name, getTimeHash(scheduledTime))
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ func TestGetJobFromTemplate(t *testing.T) {
|
|||||||
if len(job.ObjectMeta.Annotations) != 2 {
|
if len(job.ObjectMeta.Annotations) != 2 {
|
||||||
t.Errorf("Wrong number of annotations")
|
t.Errorf("Wrong number of annotations")
|
||||||
}
|
}
|
||||||
v, ok := job.ObjectMeta.Annotations["kubernetes.io/created-by"]
|
v, ok := job.ObjectMeta.Annotations[api.CreatedByAnnotation]
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("Missing created-by annotation")
|
t.Errorf("Missing created-by annotation")
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ func TestGetParentUIDFromJob(t *testing.T) {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Case 2: Has UID annotation
|
// Case 2: Has UID annotation
|
||||||
j.ObjectMeta.Annotations = map[string]string{"kubernetes.io/created-by": `{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ScheduledJob","namespace":"default","name":"pi","uid":"5ef034e0-1890-11e6-8935-42010af0003e","apiVersion":"extensions","resourceVersion":"427339"}}`}
|
j.ObjectMeta.Annotations = map[string]string{api.CreatedByAnnotation: `{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ScheduledJob","namespace":"default","name":"pi","uid":"5ef034e0-1890-11e6-8935-42010af0003e","apiVersion":"extensions","resourceVersion":"427339"}}`}
|
||||||
|
|
||||||
expectedUID := types.UID("5ef034e0-1890-11e6-8935-42010af0003e")
|
expectedUID := types.UID("5ef034e0-1890-11e6-8935-42010af0003e")
|
||||||
|
|
||||||
@ -158,9 +158,9 @@ func TestGroupJobsByParent(t *testing.T) {
|
|||||||
uid1 := types.UID("11111111-1111-1111-1111-111111111111")
|
uid1 := types.UID("11111111-1111-1111-1111-111111111111")
|
||||||
uid2 := types.UID("22222222-2222-2222-2222-222222222222")
|
uid2 := types.UID("22222222-2222-2222-2222-222222222222")
|
||||||
uid3 := types.UID("33333333-3333-3333-3333-333333333333")
|
uid3 := types.UID("33333333-3333-3333-3333-333333333333")
|
||||||
createdBy1 := map[string]string{"kubernetes.io/created-by": `{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ScheduledJob","namespace":"x","name":"pi","uid":"11111111-1111-1111-1111-111111111111","apiVersion":"extensions","resourceVersion":"111111"}}`}
|
createdBy1 := map[string]string{api.CreatedByAnnotation: `{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ScheduledJob","namespace":"x","name":"pi","uid":"11111111-1111-1111-1111-111111111111","apiVersion":"extensions","resourceVersion":"111111"}}`}
|
||||||
createdBy2 := map[string]string{"kubernetes.io/created-by": `{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ScheduledJob","namespace":"x","name":"pi","uid":"22222222-2222-2222-2222-222222222222","apiVersion":"extensions","resourceVersion":"222222"}}`}
|
createdBy2 := map[string]string{api.CreatedByAnnotation: `{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ScheduledJob","namespace":"x","name":"pi","uid":"22222222-2222-2222-2222-222222222222","apiVersion":"extensions","resourceVersion":"222222"}}`}
|
||||||
createdBy3 := map[string]string{"kubernetes.io/created-by": `{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ScheduledJob","namespace":"y","name":"pi","uid":"33333333-3333-3333-3333-333333333333","apiVersion":"extensions","resourceVersion":"333333"}}`}
|
createdBy3 := map[string]string{api.CreatedByAnnotation: `{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ScheduledJob","namespace":"y","name":"pi","uid":"33333333-3333-3333-3333-333333333333","apiVersion":"extensions","resourceVersion":"333333"}}`}
|
||||||
noCreatedBy := map[string]string{}
|
noCreatedBy := map[string]string{}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user