Change:
Is this a BUG REPORT or FEATURE REQUEST?: /kind cleanup /sig scheduling Description: If Pod did not set , admission controller will set to "default value". If the default value are from default priority class, it's better to also set of pod.
can I take this? /assign
, thanks :) I created a PR for functionality, but that'll be great if you can help add some e2e test for it. I can help to shepherd :)
thanks let me have a try :)

Discussion:
} if len(pod.Spec.PriorityClassName) == 0 { var err error <del> priority, err = p.getDefaultPriority() </del> <ins> var pcName string pcName, priority, err = p.getDefaultPriority() </ins> if err != nil { return fmt.Errorf("failed to get default priority class: %v", err) } <ins> pod.Spec.PriorityClassName = pcName </ins> } else { pcName := pod.Spec.PriorityClassName if !priorityClassPermittedInNamespace(pcName, a.GetNamespace()) {

return defaultPC, nil } <del> func (p *priorityPlugin) getDefaultPriority() (int32, error) { </del> <ins> func (p *priorityPlugin) getDefaultPriority() (string, int32, error) { </ins> dpc, err := p.getDefaultPriorityClass() if err != nil { <del> return 0, err </del> <ins> return "", 0, err </ins> } if dpc != nil { <del> return dpc.Value, nil </del> <ins> return dpc.Name, dpc.Value, nil </ins> } <del> return int32(scheduling.DefaultPriorityWhenNoDefaultClassExists), nil </del> <ins> return "", int32(scheduling.DefaultPriorityWhenNoDefaultClassExists), nil </ins> }

updatedDefaultClass1.GlobalDefault = false tests := []struct { <del> name                  string classesBefore         []*scheduling.PriorityClass classesAfter          []*scheduling.PriorityClass attributes            admission.Attributes expectedDefaultBefore int32 expectedDefaultAfter  int32 </del> <ins> name                      string classesBefore             []*scheduling.PriorityClass classesAfter              []*scheduling.PriorityClass attributes                admission.Attributes expectedDefaultBefore     int32 expectedDefaultNameBefore string expectedDefaultAfter      int32 expectedDefaultNameAfter  string </ins> }{ { <del> name:                  "simple resolution with a default class", classesBefore:         []*scheduling.PriorityClass{defaultClass1}, classesAfter:          []*scheduling.PriorityClass{defaultClass1}, attributes:            nil, expectedDefaultBefore: defaultClass1.Value, expectedDefaultAfter:  defaultClass1.Value, }, { name:                  "add a default class", classesBefore:         []*scheduling.PriorityClass{nondefaultClass1}, classesAfter:          []*scheduling.PriorityClass{nondefaultClass1, defaultClass1}, attributes:            admission.NewAttributesRecord(defaultClass1, nil, pcKind, "", defaultClass1.Name, pcResource, "", admission.Create, false, nil), expectedDefaultBefore: scheduling.DefaultPriorityWhenNoDefaultClassExists, expectedDefaultAfter:  defaultClass1.Value, }, { name:                  "multiple default classes resolves to the minimum value among them", classesBefore:         []*scheduling.PriorityClass{defaultClass1, defaultClass2}, classesAfter:          []*scheduling.PriorityClass{defaultClass2}, attributes:            admission.NewAttributesRecord(nil, nil, pcKind, "", defaultClass1.Name, pcResource, "", admission.Delete, false, nil), expectedDefaultBefore: defaultClass1.Value, expectedDefaultAfter:  defaultClass2.Value, }, { name:                  "delete default priority class", classesBefore:         []*scheduling.PriorityClass{defaultClass1}, classesAfter:          []*scheduling.PriorityClass{}, attributes:            admission.NewAttributesRecord(nil, nil, pcKind, "", defaultClass1.Name, pcResource, "", admission.Delete, false, nil), expectedDefaultBefore: defaultClass1.Value, expectedDefaultAfter:  scheduling.DefaultPriorityWhenNoDefaultClassExists, }, { name:                  "update default class and remove its global default", classesBefore:         []*scheduling.PriorityClass{defaultClass1}, classesAfter:          []*scheduling.PriorityClass{&updatedDefaultClass1}, attributes:            admission.NewAttributesRecord(&updatedDefaultClass1, defaultClass1, pcKind, "", defaultClass1.Name, pcResource, "", admission.Update, false, nil), expectedDefaultBefore: defaultClass1.Value, expectedDefaultAfter:  scheduling.DefaultPriorityWhenNoDefaultClassExists, </del> <ins> name:                      "simple resolution with a default class", classesBefore:             []*scheduling.PriorityClass{defaultClass1}, classesAfter:              []*scheduling.PriorityClass{defaultClass1}, attributes:                nil, expectedDefaultBefore:     defaultClass1.Value, expectedDefaultNameBefore: defaultClass1.Name, expectedDefaultAfter:      defaultClass1.Value, expectedDefaultNameAfter:  defaultClass1.Name, }, { name:                      "add a default class", classesBefore:             []*scheduling.PriorityClass{nondefaultClass1}, classesAfter:              []*scheduling.PriorityClass{nondefaultClass1, defaultClass1}, attributes:                admission.NewAttributesRecord(defaultClass1, nil, pcKind, "", defaultClass1.Name, pcResource, "", admission.Create, false, nil), expectedDefaultBefore:     scheduling.DefaultPriorityWhenNoDefaultClassExists, expectedDefaultNameBefore: "", expectedDefaultAfter:      defaultClass1.Value, expectedDefaultNameAfter:  defaultClass1.Name, }, { name:                      "multiple default classes resolves to the minimum value among them", classesBefore:             []*scheduling.PriorityClass{defaultClass1, defaultClass2}, classesAfter:              []*scheduling.PriorityClass{defaultClass2}, attributes:                admission.NewAttributesRecord(nil, nil, pcKind, "", defaultClass1.Name, pcResource, "", admission.Delete, false, nil), expectedDefaultBefore:     defaultClass1.Value, expectedDefaultNameBefore: defaultClass1.Name, expectedDefaultAfter:      defaultClass2.Value, expectedDefaultNameAfter:  defaultClass2.Name, }, { name:                      "delete default priority class", classesBefore:             []*scheduling.PriorityClass{defaultClass1}, classesAfter:              []*scheduling.PriorityClass{}, attributes:                admission.NewAttributesRecord(nil, nil, pcKind, "", defaultClass1.Name, pcResource, "", admission.Delete, false, nil), expectedDefaultBefore:     defaultClass1.Value, expectedDefaultNameBefore: defaultClass1.Name, expectedDefaultAfter:      scheduling.DefaultPriorityWhenNoDefaultClassExists, expectedDefaultNameAfter:  "", }, { name:                      "update default class and remove its global default", classesBefore:             []*scheduling.PriorityClass{defaultClass1}, classesAfter:              []*scheduling.PriorityClass{&updatedDefaultClass1}, attributes:                admission.NewAttributesRecord(&updatedDefaultClass1, defaultClass1, pcKind, "", defaultClass1.Name, pcResource, "", admission.Update, false, nil), expectedDefaultBefore:     defaultClass1.Value, expectedDefaultNameBefore: defaultClass1.Name, expectedDefaultAfter:      scheduling.DefaultPriorityWhenNoDefaultClassExists, expectedDefaultNameAfter:  "", </ins> }, }

if err := addPriorityClasses(ctrl, test.classesBefore); err != nil { t.Errorf("Test %q: unable to add object to informer: %v", test.name, err) } <del> defaultPriority, err := ctrl.getDefaultPriority() </del> <ins> pcName, defaultPriority, err := ctrl.getDefaultPriority() </ins> if err != nil { t.Errorf("Test %q: unexpected error while getting default priority: %v", test.name, err) } <del> if err == nil && defaultPriority != test.expectedDefaultBefore { t.Errorf("Test %q: expected default priority %d, but got %d", test.name, test.expectedDefaultBefore, defaultPriority) </del> <ins> if err == nil && (defaultPriority != test.expectedDefaultBefore || pcName != test.expectedDefaultNameBefore) { t.Errorf("Test %q: expected default priority %s(%d), but got %s(%d)", test.name, test.expectedDefaultNameBefore, test.expectedDefaultBefore, pcName, defaultPriority) </ins> } if test.attributes != nil { err := ctrl.Validate(test.attributes)

if err := addPriorityClasses(ctrl, test.classesAfter); err != nil { t.Errorf("Test %q: unable to add object to informer: %v", test.name, err) } <del> defaultPriority, err = ctrl.getDefaultPriority() </del> <ins> pcName, defaultPriority, err = ctrl.getDefaultPriority() </ins> if err != nil { t.Errorf("Test %q: unexpected error while getting default priority: %v", test.name, err) } <del> if err == nil && defaultPriority != test.expectedDefaultAfter { t.Errorf("Test %q: expected default priority %d, but got %d", test.name, test.expectedDefaultAfter, defaultPriority) </del> <ins> if err == nil && (defaultPriority != test.expectedDefaultAfter || pcName != test.expectedDefaultNameAfter) { t.Errorf("Test %q: expected default priority %s(%d), but got %s(%d)", test.name, test.expectedDefaultNameAfter, test.expectedDefaultAfter, pcName, defaultPriority) </ins> } } }