-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow balancing by labels exclusively
Adds a new flag `--balance-label` which allows users to balance between node groups exclusively via labels. This gives users the flexibility to specify the similarity logic themselves when --balance-similar-node-groups is in use.
- Loading branch information
Showing
3 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
cluster-autoscaler/processors/nodegroupset/label_nodegroups.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2021 The Kubernetes 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 nodegroupset | ||
|
||
import ( | ||
klog "k8s.io/klog/v2" | ||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" | ||
) | ||
|
||
// CreateLabelNodeInfoComparator returns a comparator that checks for node group similarity using the given labels. | ||
func CreateLabelNodeInfoComparator(labels []string) NodeInfoComparator { | ||
return func(n1, n2 *schedulerframework.NodeInfo) bool { | ||
return areLabelsSame(n1, n2, labels) | ||
} | ||
} | ||
|
||
func areLabelsSame(n1, n2 *schedulerframework.NodeInfo, labels []string) bool { | ||
for _, label := range labels { | ||
val1 := n1.Node().ObjectMeta.Labels[label] | ||
val2 := n2.Node().ObjectMeta.Labels[label] | ||
if val1 != val2 { | ||
klog.V(4).Infof("%s label did not match. %s: %s, %s: %s", label, n1.Node().Name, val1, n2.Node().Name, val2) | ||
return false | ||
} | ||
} | ||
return true | ||
} |