Skip to content

Commit

Permalink
Update apis for release v1.1.1
Browse files Browse the repository at this point in the history
Signed-off-by: Siyu Wang <[email protected]>
  • Loading branch information
FillZpp committed Jan 16, 2023
1 parent 15e9a59 commit bc0d6f6
Show file tree
Hide file tree
Showing 4 changed files with 728 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.22

KOORD_VERSION ?= v1.1.0
KOORD_VERSION ?= v1.1.1

# Set license header files.
LICENSE_HEADER_GO ?= hack/boilerplate/boilerplate.go.txt
Expand Down
59 changes: 59 additions & 0 deletions extension/descheduling.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2022 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package extension

import (
"fmt"
"strconv"
)

const (
// AnnotationEvictionCost indicates the eviction cost. It can be used to set to an int32.
// Although the K8s community has [Pod Deletion Cost #2255](https://github.com/kubernetes/enhancements/issues/2255),
// it is not a general mechanism. To avoid conflicts with components that use `Pod Deletion Cost`,
// users can individually mark the eviction cost for Pods.
// The implicit eviction cost for pods that don't set the annotation is 0, negative values are permitted.
// If set the cost with `math.MaxInt32`, it means the Pod will not be evicted.
// Pods with lower eviction cost are preferred to be evicted before pods with higher eviction cost.
// If a batch of Pods to be evicted have the same priority, they will be sorted by cost,
// and the Pod with the smallest cost will be evicted.
AnnotationEvictionCost = SchedulingDomainPrefix + "/eviction-cost"
)

func GetEvictionCost(annotations map[string]string) (int32, error) {
if value, exist := annotations[AnnotationEvictionCost]; exist {
// values that start with plus sign (e.g, "+10") or leading zeros (e.g., "008") are not valid.
if !validFirstDigit(value) {
return 0, fmt.Errorf("invalid value %q", value)
}

i, err := strconv.ParseInt(value, 10, 32)
if err != nil {
// make sure we default to 0 on error.
return 0, err
}
return int32(i), nil
}
return 0, nil
}

func validFirstDigit(str string) bool {
if len(str) == 0 {
return false
}
return str[0] == '-' || (str[0] == '0' && str == "0") || (str[0] >= '1' && str[0] <= '9')
}
Loading

0 comments on commit bc0d6f6

Please sign in to comment.