Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow PriorityClass names with 'system-' prefix for user defined priority classes #59382

Merged
merged 2 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/apis/scheduling/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const (
// that do not specify any priority class and there is no priority class
// marked as default.
DefaultPriorityWhenNoDefaultClassExists = 0
// SystemPriorityClassPrefix is the prefix reserved for system priority class names. Other priority
// classes are not allowed to start with this prefix.
SystemPriorityClassPrefix = "system-"
)

// +genclient
Expand Down
14 changes: 11 additions & 3 deletions pkg/apis/scheduling/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ limitations under the License.
package validation

import (
"strings"

"k8s.io/apimachinery/pkg/util/validation/field"
apivalidation "k8s.io/kubernetes/pkg/apis/core/validation"
"k8s.io/kubernetes/pkg/apis/scheduling"
)

// ValidatePriorityClassName can be used to check whether the given priority
// class name is valid.
var ValidatePriorityClassName = apivalidation.NameIsDNSSubdomain
// ValidatePriorityClassName checks whether the given priority class name is valid.
func ValidatePriorityClassName(name string, prefix bool) []string {
var allErrs []string
if strings.HasPrefix(name, scheduling.SystemPriorityClassPrefix) {
allErrs = append(allErrs, "priority class names with '"+scheduling.SystemPriorityClassPrefix+"' prefix are reserved for system use only")
}
allErrs = append(allErrs, apivalidation.NameIsDNSSubdomain(name, prefix)...)
return allErrs
}

// ValidatePriorityClass tests whether required fields in the PriorityClass are
// set correctly.
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/scheduling/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func TestValidatePriorityClass(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "tier&1", Namespace: ""},
Value: 100,
},
"invalid system name": {
ObjectMeta: metav1.ObjectMeta{Name: scheduling.SystemPriorityClassPrefix + "test"},
Value: 100,
},
}

for k, v := range errorCases {
Expand Down
2 changes: 2 additions & 0 deletions plugin/pkg/admission/priority/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
)

// SystemPriorityClasses defines special priority classes which are used by system critical pods that should not be preempted by workload pods.
// NOTE: In order to avoid conflict of names with user-defined priority classes, all the names must
// start with scheduling.SystemPriorityClassPrefix which is by default "system-".
var SystemPriorityClasses = map[string]int32{
"system-cluster-critical": SystemCriticalPriority,
"system-node-critical": SystemCriticalPriority + 1000,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we manage the magic numbers like 1000? At least we should indicate why it is 1000.
WDYT, Bobby?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wgliang, the exact value of priority does not have any significance, only the relative value of priority compared to other priorites matters. So, if system-node-critical value was SystemCriticalPriority + 1, it would have had the same effect as SystemCriticalPriority + 1000, but we choose to use a larger number so that we can add more priority classes between the two existing ones if there is a need in the future.

Expand Down