Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho committed Sep 15, 2024
1 parent 29fab6a commit f65988e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 2 additions & 6 deletions examples/imagelocality/image_locality.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
guestapi "sigs.k8s.io/kube-scheduler-wasm-extension/guest/api"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/api/proto"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/handle/sharedlister/api"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/score"
)

// The two thresholds are used as bounds for the image score range. They correspond to a reasonable size range for
Expand Down Expand Up @@ -41,11 +42,6 @@ func (pl *imageLocality) Score(state guestapi.CycleState, pod proto.Pod, nodeNam
return int32(score), nil
}

const (
// maxNodeScore is the maximum score a Score plugin is expected to return.
maxNodeScore int64 = 100
)

// calculatePriority returns the priority of a node. Given the sumScores of requested images on the node, the node's
// priority is obtained by scaling the maximum priority value with a ratio proportional to the sumScores.
func calculatePriority(sumScores int64, numContainers int) int64 {
Expand All @@ -56,7 +52,7 @@ func calculatePriority(sumScores int64, numContainers int) int64 {
sumScores = maxThreshold
}

return maxNodeScore * (sumScores - minThreshold) / (maxThreshold - minThreshold)
return score.MaxNodeScore * (sumScores - minThreshold) / (maxThreshold - minThreshold)
}

// sumImageScores returns the sum of image scores of all the containers that are already on the node.
Expand Down
4 changes: 2 additions & 2 deletions guest/api/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
// ImageStateSummary provides summarized information about the state of an image.
type ImageStateSummary struct {
// Size of the image
Size int64
Size uint64
// Used to track how many nodes have this image
NumNodes int
NumNodes uint32
}
5 changes: 5 additions & 0 deletions guest/score/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import (
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/plugin"
)

const (
// MaxNodeScore is the maximum score a Score plugin is expected to return.
MaxNodeScore int64 = 100
)

// score is the current plugin assigned with SetPlugin.
var score api.ScorePlugin

Expand Down

0 comments on commit f65988e

Please sign in to comment.