Skip to content

Commit 9920bdb

Browse files
authored
Merge pull request kubernetes#2948 from towca/jtuznik/node-info-processor
Add NodeInfoProcessor for proccesing nodeInfosForNodeGroups
2 parents 8e19a64 + 8f1efc9 commit 9920bdb

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

cluster-autoscaler/core/scale_test_common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
processor_callbacks "k8s.io/autoscaler/cluster-autoscaler/processors/callbacks"
3535
"k8s.io/autoscaler/cluster-autoscaler/processors/nodegroups"
3636
"k8s.io/autoscaler/cluster-autoscaler/processors/nodegroupset"
37+
"k8s.io/autoscaler/cluster-autoscaler/processors/nodeinfos"
3738
"k8s.io/autoscaler/cluster-autoscaler/processors/status"
3839
"k8s.io/autoscaler/cluster-autoscaler/simulator"
3940
"k8s.io/autoscaler/cluster-autoscaler/utils/errors"
@@ -138,6 +139,7 @@ func NewTestProcessors() *processors.AutoscalingProcessors {
138139
ScaleDownStatusProcessor: &status.NoOpScaleDownStatusProcessor{},
139140
AutoscalingStatusProcessor: &status.NoOpAutoscalingStatusProcessor{},
140141
NodeGroupManager: nodegroups.NewDefaultNodeGroupManager(),
142+
NodeInfoProcessor: nodeinfos.NewDefaultNodeInfoProcessor(),
141143
}
142144
}
143145

cluster-autoscaler/core/static_autoscaler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError
269269
return autoscalerError.AddPrefix("failed to build node infos for node groups: ")
270270
}
271271

272+
nodeInfosForGroups, err = a.processors.NodeInfoProcessor.Process(autoscalingContext, nodeInfosForGroups)
273+
if err != nil {
274+
klog.Errorf("Failed to process nodeInfos: %v", err)
275+
return errors.ToAutoscalerError(errors.InternalError, err)
276+
}
277+
272278
if typedErr := a.updateClusterState(allNodes, nodeInfosForGroups, currentTime); typedErr != nil {
273279
klog.Errorf("Failed to update cluster state: %v", typedErr)
274280
return typedErr
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package nodeinfos
18+
19+
import (
20+
"k8s.io/autoscaler/cluster-autoscaler/context"
21+
"k8s.io/kubernetes/pkg/scheduler/nodeinfo"
22+
)
23+
24+
// NodeInfoProcessor processes nodeInfos after they're created.
25+
type NodeInfoProcessor interface {
26+
// Process processes a map of nodeInfos for node groups.
27+
Process(ctx *context.AutoscalingContext, nodeInfosForNodeGroups map[string]*nodeinfo.NodeInfo) (map[string]*nodeinfo.NodeInfo, error)
28+
// CleanUp cleans up processor's internal structures.
29+
CleanUp()
30+
}
31+
32+
// NoOpNodeInfoProcessor doesn't change nodeInfos.
33+
type NoOpNodeInfoProcessor struct {
34+
}
35+
36+
// Process returns unchanged nodeInfos.
37+
func (p *NoOpNodeInfoProcessor) Process(ctx *context.AutoscalingContext, nodeInfosForNodeGroups map[string]*nodeinfo.NodeInfo) (map[string]*nodeinfo.NodeInfo, error) {
38+
return nodeInfosForNodeGroups, nil
39+
}
40+
41+
// CleanUp cleans up processor's internal structures.
42+
func (p *NoOpNodeInfoProcessor) CleanUp() {
43+
}
44+
45+
// NewDefaultNodeInfoProcessor returns a default instance of NodeInfoProcessor.
46+
func NewDefaultNodeInfoProcessor() NodeInfoProcessor {
47+
return &NoOpNodeInfoProcessor{}
48+
}

cluster-autoscaler/processors/processors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package processors
1919
import (
2020
"k8s.io/autoscaler/cluster-autoscaler/processors/nodegroups"
2121
"k8s.io/autoscaler/cluster-autoscaler/processors/nodegroupset"
22+
"k8s.io/autoscaler/cluster-autoscaler/processors/nodeinfos"
2223
"k8s.io/autoscaler/cluster-autoscaler/processors/nodes"
2324
"k8s.io/autoscaler/cluster-autoscaler/processors/pods"
2425
"k8s.io/autoscaler/cluster-autoscaler/processors/status"
@@ -43,6 +44,8 @@ type AutoscalingProcessors struct {
4344
AutoscalingStatusProcessor status.AutoscalingStatusProcessor
4445
// NodeGroupManager is responsible for creating/deleting node groups.
4546
NodeGroupManager nodegroups.NodeGroupManager
47+
// NodeInfoProcessor is used to process nodeInfos after they're created.
48+
NodeInfoProcessor nodeinfos.NodeInfoProcessor
4649
}
4750

4851
// DefaultProcessors returns default set of processors.
@@ -56,6 +59,7 @@ func DefaultProcessors() *AutoscalingProcessors {
5659
ScaleDownStatusProcessor: status.NewDefaultScaleDownStatusProcessor(),
5760
AutoscalingStatusProcessor: status.NewDefaultAutoscalingStatusProcessor(),
5861
NodeGroupManager: nodegroups.NewDefaultNodeGroupManager(),
62+
NodeInfoProcessor: nodeinfos.NewDefaultNodeInfoProcessor(),
5963
}
6064
}
6165

@@ -69,4 +73,5 @@ func (ap *AutoscalingProcessors) CleanUp() {
6973
ap.AutoscalingStatusProcessor.CleanUp()
7074
ap.NodeGroupManager.CleanUp()
7175
ap.ScaleDownNodeProcessor.CleanUp()
76+
ap.NodeInfoProcessor.CleanUp()
7277
}

0 commit comments

Comments
 (0)