Skip to content

Commit e1e1c32

Browse files
authored
Merge pull request #7890 from YahiaBadr/migrate-flags-off-main
Migrating flags off main.go to a separate package
2 parents 173a4bd + 241ad7a commit e1e1c32

File tree

11 files changed

+651
-636
lines changed

11 files changed

+651
-636
lines changed

cluster-autoscaler/config/autoscaling_options.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ type AutoscalingOptions struct {
104104
// NodeGroupDefaults are default values for per NodeGroup options.
105105
// They will be used any time a specific value is not provided for a given NodeGroup.
106106
NodeGroupDefaults NodeGroupAutoscalingOptions
107-
// MaxEmptyBulkDelete is a number of empty nodes that can be removed at the same time.
108-
MaxEmptyBulkDelete int
109107
// MaxNodesTotal sets the maximum number of nodes in the whole cluster
110108
MaxNodesTotal int
111109
// MaxCoresTotal sets the maximum number of cores in the whole cluster
@@ -198,10 +196,6 @@ type AutoscalingOptions struct {
198196
ConfigNamespace string
199197
// ClusterName if available
200198
ClusterName string
201-
// NodeAutoprovisioningEnabled tells whether the node auto-provisioning is enabled for this cluster.
202-
NodeAutoprovisioningEnabled bool
203-
// MaxAutoprovisionedNodeGroupCount is the maximum number of autoprovisioned groups in the cluster.
204-
MaxAutoprovisionedNodeGroupCount int
205199
// UnremovableNodeRecheckTimeout is the timeout before we check again a node that couldn't be removed before
206200
UnremovableNodeRecheckTimeout time.Duration
207201
// Pods with priority below cutoff are expendable. They can be killed without any consideration during scale down and they don't cause scale-up.
@@ -318,6 +312,30 @@ type AutoscalingOptions struct {
318312
// It only refers to check capacity ProvisioningRequests, but if not empty, best-effort atomic ProvisioningRequests processing is disabled in this instance.
319313
// Not recommended: Until CA 1.35, ProvisioningRequests with this name as prefix in their class will be also processed.
320314
CheckCapacityProcessorInstance string
315+
// MaxInactivityTime is the maximum duration without recorded autoscaler activity before it is considered unhealthy.
316+
MaxInactivityTime time.Duration
317+
// MaxFailingTime is the maximum duration without a successful autoscaler run before it is considered unhealthy.
318+
MaxFailingTime time.Duration
319+
// DebuggingSnapshotEnabled is used to enable/disable debugging snapshot creation.
320+
DebuggingSnapshotEnabled bool
321+
// EnableProfiling is debug/pprof endpoint enabled.
322+
EnableProfiling bool
323+
// Address is the address of an auxiliary endpoint exposing process information like metrics, health checks and profiling data.
324+
Address string
325+
// EmitPerNodeGroupMetrics is used to enable/disable emitting per node group metrics.
326+
EmitPerNodeGroupMetrics bool
327+
// FrequentLoopsEnabled is used to enable/disable frequent loops.
328+
FrequentLoopsEnabled bool
329+
// ScanInterval is how often cluster is reevaluated for scale up or down
330+
ScanInterval time.Duration
331+
// ForceDaemonSets is used to block scale-up of node groups too small for all suitable Daemon Sets pods.
332+
ForceDaemonSets bool
333+
// NodeInfoCacheExpireTime is the time after which the node info cache expires for each item, Default value is 10 years.
334+
NodeInfoCacheExpireTime time.Duration
335+
// ProactiveScaleupEnabled is used to enable/disable proactive scale up.
336+
ProactiveScaleupEnabled bool
337+
// PodInjectionLimit limits total number of pods while injecting fake pods.
338+
PodInjectionLimit int
321339
}
322340

323341
// KubeClientOptions specify options for kube client

cluster-autoscaler/config/flags/flags.go

Lines changed: 532 additions & 0 deletions
Large diffs are not rendered by default.

cluster-autoscaler/main_test.go renamed to cluster-autoscaler/config/flags/flags_test.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package main
17+
package flags
1818

1919
import (
2020
"testing"
2121

2222
"k8s.io/autoscaler/cluster-autoscaler/config"
23+
kubelet_config "k8s.io/kubernetes/pkg/kubelet/apis/config"
2324

2425
"github.com/stretchr/testify/assert"
2526
)
@@ -91,3 +92,57 @@ func TestParseSingleGpuLimit(t *testing.T) {
9192
}
9293
}
9394
}
95+
96+
func TestParseShutdownGracePeriodsAndPriorities(t *testing.T) {
97+
testCases := []struct {
98+
name string
99+
input string
100+
want []kubelet_config.ShutdownGracePeriodByPodPriority
101+
}{
102+
{
103+
name: "empty input",
104+
input: "",
105+
want: nil,
106+
},
107+
{
108+
name: "Incorrect string - incorrect priority grace period pairs",
109+
input: "1:2,34",
110+
want: nil,
111+
},
112+
{
113+
name: "Incorrect string - trailing ,",
114+
input: "1:2, 3:4,",
115+
want: nil,
116+
},
117+
{
118+
name: "Incorrect string - trailing space",
119+
input: "1:2,3:4 ",
120+
want: nil,
121+
},
122+
{
123+
name: "Non integers - 1",
124+
input: "1:2,3:a",
125+
want: nil,
126+
},
127+
{
128+
name: "Non integers - 2",
129+
input: "1:2,3:23.2",
130+
want: nil,
131+
},
132+
{
133+
name: "parsable input",
134+
input: "1:2,3:4",
135+
want: []kubelet_config.ShutdownGracePeriodByPodPriority{
136+
{1, 2},
137+
{3, 4},
138+
},
139+
},
140+
}
141+
142+
for _, tc := range testCases {
143+
t.Run(tc.name, func(t *testing.T) {
144+
shutdownGracePeriodByPodPriority := parseShutdownGracePeriodsAndPriorities(tc.input)
145+
assert.Equal(t, tc.want, shutdownGracePeriodByPodPriority)
146+
})
147+
}
148+
}

cluster-autoscaler/core/scaledown/actuation/priority.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ package actuation
1919
import (
2020
"math"
2121
"sort"
22-
"strconv"
23-
"strings"
2422

2523
apiv1 "k8s.io/api/core/v1"
26-
"k8s.io/klog/v2"
2724
kubelet_config "k8s.io/kubernetes/pkg/kubelet/apis/config"
2825
)
2926

@@ -73,39 +70,6 @@ func groupIndex(pod *apiv1.Pod, groups []podEvictionGroup) int {
7370
return index
7471
}
7572

76-
// ParseShutdownGracePeriodsAndPriorities parse priorityGracePeriodStr and returns an array of ShutdownGracePeriodByPodPriority if succeeded.
77-
// Otherwise, returns an empty list
78-
func ParseShutdownGracePeriodsAndPriorities(priorityGracePeriodStr string) []kubelet_config.ShutdownGracePeriodByPodPriority {
79-
var priorityGracePeriodMap, emptyMap []kubelet_config.ShutdownGracePeriodByPodPriority
80-
81-
if priorityGracePeriodStr == "" {
82-
return emptyMap
83-
}
84-
priorityGracePeriodStrArr := strings.Split(priorityGracePeriodStr, ",")
85-
for _, item := range priorityGracePeriodStrArr {
86-
priorityAndPeriod := strings.Split(item, ":")
87-
if len(priorityAndPeriod) != 2 {
88-
klog.Errorf("Parsing shutdown grace periods failed because '%s' is not a priority and grace period couple separated by ':'", item)
89-
return emptyMap
90-
}
91-
priority, err := strconv.Atoi(priorityAndPeriod[0])
92-
if err != nil {
93-
klog.Errorf("Parsing shutdown grace periods and priorities failed: %v", err)
94-
return emptyMap
95-
}
96-
shutDownGracePeriod, err := strconv.Atoi(priorityAndPeriod[1])
97-
if err != nil {
98-
klog.Errorf("Parsing shutdown grace periods and priorities failed: %v", err)
99-
return emptyMap
100-
}
101-
priorityGracePeriodMap = append(priorityGracePeriodMap, kubelet_config.ShutdownGracePeriodByPodPriority{
102-
Priority: int32(priority),
103-
ShutdownGracePeriodSeconds: int64(shutDownGracePeriod),
104-
})
105-
}
106-
return priorityGracePeriodMap
107-
}
108-
10973
// SingleRuleDrainConfig returns an array of ShutdownGracePeriodByPodPriority with a single ShutdownGracePeriodByPodPriority
11074
func SingleRuleDrainConfig(shutdownGracePeriodSeconds int) []kubelet_config.ShutdownGracePeriodByPodPriority {
11175
return []kubelet_config.ShutdownGracePeriodByPodPriority{

cluster-autoscaler/core/scaledown/actuation/priority_test.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -183,57 +183,3 @@ func TestGroupByPriority(t *testing.T) {
183183
groups := groupByPriority(shutdownGracePeriodByPodPriority, []*apiv1.Pod{p1, p2, p3, p4, p5}, []*apiv1.Pod{p6, p7, p8, p9, p10})
184184
assert.Equal(t, wantGroups, groups)
185185
}
186-
187-
func TestParseShutdownGracePeriodsAndPriorities(t *testing.T) {
188-
testCases := []struct {
189-
name string
190-
input string
191-
want []kubelet_config.ShutdownGracePeriodByPodPriority
192-
}{
193-
{
194-
name: "empty input",
195-
input: "",
196-
want: nil,
197-
},
198-
{
199-
name: "Incorrect string - incorrect priority grace period pairs",
200-
input: "1:2,34",
201-
want: nil,
202-
},
203-
{
204-
name: "Incorrect string - trailing ,",
205-
input: "1:2, 3:4,",
206-
want: nil,
207-
},
208-
{
209-
name: "Incorrect string - trailing space",
210-
input: "1:2,3:4 ",
211-
want: nil,
212-
},
213-
{
214-
name: "Non integers - 1",
215-
input: "1:2,3:a",
216-
want: nil,
217-
},
218-
{
219-
name: "Non integers - 2",
220-
input: "1:2,3:23.2",
221-
want: nil,
222-
},
223-
{
224-
name: "parsable input",
225-
input: "1:2,3:4",
226-
want: []kubelet_config.ShutdownGracePeriodByPodPriority{
227-
{1, 2},
228-
{3, 4},
229-
},
230-
},
231-
}
232-
233-
for _, tc := range testCases {
234-
t.Run(tc.name, func(t *testing.T) {
235-
shutdownGracePeriodByPodPriority := ParseShutdownGracePeriodsAndPriorities(tc.input)
236-
assert.Equal(t, tc.want, shutdownGracePeriodByPodPriority)
237-
})
238-
}
239-
}

cluster-autoscaler/core/scaleup/orchestrator/async_initializer_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ func TestNodePoolAsyncInitialization(t *testing.T) {
6767
return nil
6868
}, nil)
6969
options := config.AutoscalingOptions{
70-
NodeAutoprovisioningEnabled: true,
71-
AsyncNodeGroupsEnabled: true,
70+
AsyncNodeGroupsEnabled: true,
7271
}
7372
listers := kube_util.NewListerRegistry(nil, nil, nil, nil, nil, nil, nil, nil, nil)
7473
context, err := NewScaleTestAutoscalingContext(options, &fake.Clientset{}, listers, provider, nil, nil)

cluster-autoscaler/core/scaleup/orchestrator/orchestrator_test.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,6 @@ func TestNoCreateNodeGroupMaxCoresLimitHit(t *testing.T) {
826826
options := defaultOptions
827827
options.MaxCoresTotal = 7
828828
options.MaxMemoryTotal = 100000
829-
options.NodeAutoprovisioningEnabled = true
830829

831830
largeNode := BuildTestNode("n", 8000, 8000)
832831
SetNodeReadyState(largeNode, true, time.Time{})
@@ -1555,11 +1554,9 @@ func TestScaleUpAutoprovisionedNodeGroup(t *testing.T) {
15551554
}, nil, []string{"T1"}, map[string]*framework.NodeInfo{"T1": ti1})
15561555

15571556
options := config.AutoscalingOptions{
1558-
EstimatorName: estimator.BinpackingEstimatorName,
1559-
MaxCoresTotal: 5000 * 64,
1560-
MaxMemoryTotal: 5000 * 64 * 20,
1561-
NodeAutoprovisioningEnabled: true,
1562-
MaxAutoprovisionedNodeGroupCount: 10,
1557+
EstimatorName: estimator.BinpackingEstimatorName,
1558+
MaxCoresTotal: 5000 * 64,
1559+
MaxMemoryTotal: 5000 * 64 * 20,
15631560
}
15641561
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
15651562
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
@@ -1608,12 +1605,10 @@ func TestScaleUpBalanceAutoprovisionedNodeGroups(t *testing.T) {
16081605
}, nil, []string{"T1"}, map[string]*framework.NodeInfo{"T1": ti1})
16091606

16101607
options := config.AutoscalingOptions{
1611-
BalanceSimilarNodeGroups: true,
1612-
EstimatorName: estimator.BinpackingEstimatorName,
1613-
MaxCoresTotal: 5000 * 64,
1614-
MaxMemoryTotal: 5000 * 64 * 20,
1615-
NodeAutoprovisioningEnabled: true,
1616-
MaxAutoprovisionedNodeGroupCount: 10,
1608+
BalanceSimilarNodeGroups: true,
1609+
EstimatorName: estimator.BinpackingEstimatorName,
1610+
MaxCoresTotal: 5000 * 64,
1611+
MaxMemoryTotal: 5000 * 64 * 20,
16171612
}
16181613
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
16191614
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)
@@ -1762,8 +1757,7 @@ func TestScaleupAsyncNodeGroupsEnabled(t *testing.T) {
17621757
}
17631758

17641759
options := config.AutoscalingOptions{
1765-
NodeAutoprovisioningEnabled: true,
1766-
AsyncNodeGroupsEnabled: true,
1760+
AsyncNodeGroupsEnabled: true,
17671761
}
17681762
podLister := kube_util.NewTestPodLister([]*apiv1.Pod{})
17691763
listers := kube_util.NewListerRegistry(nil, nil, podLister, nil, nil, nil, nil, nil, nil)

cluster-autoscaler/core/static_autoscaler_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -807,13 +807,11 @@ func TestStaticAutoscalerRunOnceWithAutoprovisionedEnabled(t *testing.T) {
807807
ScaleDownUtilizationThreshold: 0.5,
808808
MaxNodeProvisionTime: 10 * time.Second,
809809
},
810-
EstimatorName: estimator.BinpackingEstimatorName,
811-
ScaleDownEnabled: true,
812-
MaxNodesTotal: 100,
813-
MaxCoresTotal: 100,
814-
MaxMemoryTotal: 100000,
815-
NodeAutoprovisioningEnabled: true,
816-
MaxAutoprovisionedNodeGroupCount: 10,
810+
EstimatorName: estimator.BinpackingEstimatorName,
811+
ScaleDownEnabled: true,
812+
MaxNodesTotal: 100,
813+
MaxCoresTotal: 100,
814+
MaxMemoryTotal: 100000,
817815
}
818816
processorCallbacks := newStaticAutoscalerProcessorCallbacks()
819817

cluster-autoscaler/core/test/common.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@ func (p *MockAutoprovisioningNodeGroupManager) createNodeGroup(context *context.
248248

249249
// RemoveUnneededNodeGroups removes uneeded node groups
250250
func (p *MockAutoprovisioningNodeGroupManager) RemoveUnneededNodeGroups(context *context.AutoscalingContext) (removedNodeGroups []cloudprovider.NodeGroup, err error) {
251-
if !context.AutoscalingOptions.NodeAutoprovisioningEnabled {
252-
return nil, nil
253-
}
254251
removedNodeGroups = make([]cloudprovider.NodeGroup, 0)
255252
nodeGroups := context.CloudProvider.NodeGroups()
256253
for _, nodeGroup := range nodeGroups {

0 commit comments

Comments
 (0)