-
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.
Signed-off-by: tombokombo <[email protected]>
- Loading branch information
1 parent
13af977
commit eae8a2d
Showing
3 changed files
with
75 additions
and
0 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
73 changes: 73 additions & 0 deletions
73
cluster-autoscaler/processors/nodeinfosprovider/asg_tag_resource_node_info_provider.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,73 @@ | ||
/* | ||
Copyright 2022 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 nodeinfosprovider | ||
|
||
import ( | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
apiv1 "k8s.io/api/core/v1" | ||
"k8s.io/autoscaler/cluster-autoscaler/context" | ||
"k8s.io/autoscaler/cluster-autoscaler/utils/errors" | ||
"k8s.io/autoscaler/cluster-autoscaler/utils/taints" | ||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework" | ||
) | ||
|
||
// AsgTagResourceNodeInfoProvider is a wrapper for MixedTemplateNodeInfoProvider. | ||
type AsgTagResourceNodeInfoProvider struct { | ||
mixedTemplateNodeInfoProvider *MixedTemplateNodeInfoProvider | ||
} | ||
|
||
// NewAsgTagResourceNodeInfoProvider returns AsgTagResourceNodeInfoProvider. | ||
func NewAsgTagResourceNodeInfoProvider(t *time.Duration) *AsgTagResourceNodeInfoProvider { | ||
return &AsgTagResourceNodeInfoProvider{ | ||
mixedTemplateNodeInfoProvider: NewMixedTemplateNodeInfoProvider(t), | ||
} | ||
} | ||
|
||
// Process returns the nodeInfos set for this cluster. | ||
func (p *AsgTagResourceNodeInfoProvider) Process(ctx *context.AutoscalingContext, nodes []*apiv1.Node, daemonsets []*appsv1.DaemonSet, ignoredTaints taints.TaintKeySet, currentTime time.Time) (map[string]*schedulerframework.NodeInfo, errors.AutoscalerError) { | ||
nodeInfos, err := p.mixedTemplateNodeInfoProvider.Process(ctx, nodes, daemonsets, ignoredTaints, currentTime) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// Add annotatios to the NodeInfo to use later in expander. | ||
nodeGroups := ctx.CloudProvider.NodeGroups() | ||
for _, ng := range nodeGroups { | ||
if nodeInfo, ok := nodeInfos[ng.Id()]; ok { | ||
template, err := ng.TemplateNodeInfo() | ||
if err != nil { | ||
continue | ||
} | ||
for resourceName, val := range template.Node().Status.Capacity { | ||
if _, ok := nodeInfo.Node().Status.Capacity[resourceName]; !ok { | ||
nodeInfo.Node().Status.Capacity[resourceName] = val | ||
} | ||
} | ||
for resourceName, val := range template.Node().Status.Allocatable { | ||
if _, ok := nodeInfo.Node().Status.Allocatable[resourceName]; !ok { | ||
nodeInfo.Node().Status.Allocatable[resourceName] = val | ||
} | ||
} | ||
} | ||
} | ||
return nodeInfos, nil | ||
} | ||
|
||
// CleanUp cleans up processor's internal structures. | ||
func (p *AsgTagResourceNodeInfoProvider) CleanUp() { | ||
} |