Add startup taint flag, prefix & add status taint prefix

This commit is contained in:
Mahmoud Atwa 2023-09-22 20:51:34 +00:00
parent fbe25e1708
commit d2fe118db9
3 changed files with 62 additions and 10 deletions

View File

@ -198,6 +198,7 @@ var (
newPodScaleUpDelay = flag.Duration("new-pod-scale-up-delay", 0*time.Second, "Pods less than this old will not be considered for scale-up. Can be increased for individual pods through annotation 'cluster-autoscaler.kubernetes.io/pod-scale-up-delay'.") newPodScaleUpDelay = flag.Duration("new-pod-scale-up-delay", 0*time.Second, "Pods less than this old will not be considered for scale-up. Can be increased for individual pods through annotation 'cluster-autoscaler.kubernetes.io/pod-scale-up-delay'.")
ignoreTaintsFlag = multiStringFlag("ignore-taint", "Specifies a taint to ignore in node templates when considering to scale a node group") ignoreTaintsFlag = multiStringFlag("ignore-taint", "Specifies a taint to ignore in node templates when considering to scale a node group")
startupTaintFlag = multiStringFlag("startup-taint", "Specifies a taint to ignore in node templates when considering to scale a node group (Equivalent to ignore-taint)")
balancingIgnoreLabelsFlag = multiStringFlag("balancing-ignore-label", "Specifies a label to ignore in addition to the basic and cloud-provider set of labels when comparing if two node groups are similar") balancingIgnoreLabelsFlag = multiStringFlag("balancing-ignore-label", "Specifies a label to ignore in addition to the basic and cloud-provider set of labels when comparing if two node groups are similar")
balancingLabelsFlag = multiStringFlag("balancing-label", "Specifies a label to use for comparing if two node groups are similar, rather than the built in heuristics. Setting this flag disables all other comparison logic, and cannot be combined with --balancing-ignore-label.") balancingLabelsFlag = multiStringFlag("balancing-label", "Specifies a label to use for comparing if two node groups are similar, rather than the built in heuristics. Setting this flag disables all other comparison logic, and cannot be combined with --balancing-ignore-label.")
awsUseStaticInstanceList = flag.Bool("aws-use-static-instance-list", false, "Should CA fetch instance types in runtime or use a static list. AWS only") awsUseStaticInstanceList = flag.Bool("aws-use-static-instance-list", false, "Should CA fetch instance types in runtime or use a static list. AWS only")
@ -346,7 +347,7 @@ func createAutoscalingOptions() config.AutoscalingOptions {
ExpendablePodsPriorityCutoff: *expendablePodsPriorityCutoff, ExpendablePodsPriorityCutoff: *expendablePodsPriorityCutoff,
Regional: *regional, Regional: *regional,
NewPodScaleUpDelay: *newPodScaleUpDelay, NewPodScaleUpDelay: *newPodScaleUpDelay,
IgnoredTaints: *ignoreTaintsFlag, IgnoredTaints: append(*ignoreTaintsFlag, *startupTaintFlag...),
BalancingExtraIgnoredLabels: *balancingIgnoreLabelsFlag, BalancingExtraIgnoredLabels: *balancingIgnoreLabelsFlag,
BalancingLabels: *balancingLabelsFlag, BalancingLabels: *balancingLabelsFlag,
KubeConfigPath: *kubeConfigFile, KubeConfigPath: *kubeConfigFile,

View File

@ -44,6 +44,12 @@ const (
// IgnoreTaintPrefix any taint starting with it will be filtered out from autoscaler template node. // IgnoreTaintPrefix any taint starting with it will be filtered out from autoscaler template node.
IgnoreTaintPrefix = "ignore-taint.cluster-autoscaler.kubernetes.io/" IgnoreTaintPrefix = "ignore-taint.cluster-autoscaler.kubernetes.io/"
// StartupTaintPrefix (Same as IgnoreTaintPrefix) any taint starting with it will be filtered out from autoscaler template node.
StartupTaintPrefix = "startup-taint.cluster-autoscaler.kubernetes.io/"
// StartupTaintPrefix (Same as IgnoreTaintPrefix) any taint starting with it will be filtered out from autoscaler template node.
DefaultStatusTaintPrefix = "status-taint.cluster-autoscaler.kubernetes.io/"
gkeNodeTerminationHandlerTaint = "cloud.google.com/impending-node-termination" gkeNodeTerminationHandlerTaint = "cloud.google.com/impending-node-termination"
// AWS: Indicates that a node has volumes stuck in attaching state and hence it is not fit for scheduling more pods // AWS: Indicates that a node has volumes stuck in attaching state and hence it is not fit for scheduling more pods
@ -57,6 +63,7 @@ type TaintKeySet map[string]bool
type TaintConfig struct { type TaintConfig struct {
IgnoredTaints TaintKeySet IgnoredTaints TaintKeySet
StatusTaints TaintKeySet StatusTaints TaintKeySet
StatusTaintPrefix string
} }
// NewTaintConfig returns the taint config extracted from options // NewTaintConfig returns the taint config extracted from options
@ -76,6 +83,7 @@ func NewTaintConfig(opts config.AutoscalingOptions) TaintConfig {
return TaintConfig{ return TaintConfig{
IgnoredTaints: ignoredTaints, IgnoredTaints: ignoredTaints,
StatusTaints: statusTaints, StatusTaints: statusTaints,
StatusTaintPrefix: DefaultStatusTaintPrefix,
} }
} }
@ -352,6 +360,15 @@ func SanitizeTaints(taints []apiv1.Taint, taintConfig TaintConfig) []apiv1.Taint
continue continue
} }
if strings.HasPrefix(taint.Key, StartupTaintPrefix) {
klog.V(4).Infof("Removing taint %s based on prefix, when creation template from node", taint.Key)
continue
}
if strings.HasPrefix(taint.Key, DefaultStatusTaintPrefix) {
klog.V(4).Infof("Removing status taint %s, when creating template from node", taint.Key)
continue
}
if _, exists := taintConfig.StatusTaints[taint.Key]; exists { if _, exists := taintConfig.StatusTaints[taint.Key]; exists {
klog.V(4).Infof("Removing status taint %s, when creating template from node", taint.Key) klog.V(4).Infof("Removing status taint %s, when creating template from node", taint.Key)
continue continue
@ -376,10 +393,10 @@ func FilterOutNodesWithIgnoredTaints(ignoredTaints TaintKeySet, allNodes, readyN
ready := true ready := true
for _, t := range node.Spec.Taints { for _, t := range node.Spec.Taints {
_, hasIgnoredTaint := ignoredTaints[t.Key] _, hasIgnoredTaint := ignoredTaints[t.Key]
if hasIgnoredTaint || strings.HasPrefix(t.Key, IgnoreTaintPrefix) { if hasIgnoredTaint || strings.HasPrefix(t.Key, IgnoreTaintPrefix) || strings.HasPrefix(t.Key, StartupTaintPrefix) {
ready = false ready = false
nodesWithIgnoredTaints[node.Name] = kubernetes.GetUnreadyNodeCopy(node, kubernetes.IgnoreTaint) nodesWithIgnoredTaints[node.Name] = kubernetes.GetUnreadyNodeCopy(node, kubernetes.IgnoreTaint)
klog.V(3).Infof("Overriding status of node %v, which seems to have ignored taint %q", node.Name, t.Key) klog.V(3).Infof("Overriding status of node %v, which seems to have ignored or startup taint %q", node.Name, t.Key)
break break
} }
} }

View File

@ -388,7 +388,7 @@ func TestFilterOutNodesWithIgnoredTaints(t *testing.T) {
}, },
}, },
}, },
"no ignored taint, one unready prefixed tainted node": { "no ignored taint, one node unready prefixed with ignore taint": {
readyNodes: 0, readyNodes: 0,
allNodes: 1, allNodes: 1,
ignoredTaints: map[string]bool{}, ignoredTaints: map[string]bool{},
@ -411,6 +411,29 @@ func TestFilterOutNodesWithIgnoredTaints(t *testing.T) {
}, },
}, },
}, },
"no ignored taint, one node unready prefixed with startup taint": {
readyNodes: 0,
allNodes: 1,
ignoredTaints: map[string]bool{},
node: &apiv1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "notReadyTainted",
CreationTimestamp: metav1.NewTime(time.Now()),
},
Spec: apiv1.NodeSpec{
Taints: []apiv1.Taint{
{
Key: StartupTaintPrefix + "another-taint",
Value: "myValue",
Effect: apiv1.TaintEffectNoSchedule,
},
},
},
Status: apiv1.NodeStatus{
Conditions: []apiv1.NodeCondition{readyCondition},
},
},
},
"no ignored taint, two taints": { "no ignored taint, two taints": {
readyNodes: 1, readyNodes: 1,
allNodes: 1, allNodes: 1,
@ -485,6 +508,16 @@ func TestSanitizeTaints(t *testing.T) {
Value: "myValue", Value: "myValue",
Effect: apiv1.TaintEffectNoSchedule, Effect: apiv1.TaintEffectNoSchedule,
}, },
{
Key: DefaultStatusTaintPrefix + "some-taint",
Value: "myValue",
Effect: apiv1.TaintEffectNoSchedule,
},
{
Key: StartupTaintPrefix + "some-taint",
Value: "myValue",
Effect: apiv1.TaintEffectNoSchedule,
},
{ {
Key: "test-taint", Key: "test-taint",
Value: "test2", Value: "test2",
@ -524,6 +557,7 @@ func TestSanitizeTaints(t *testing.T) {
taintConfig := TaintConfig{ taintConfig := TaintConfig{
IgnoredTaints: map[string]bool{"ignore-me": true}, IgnoredTaints: map[string]bool{"ignore-me": true},
StatusTaints: map[string]bool{"status-me": true}, StatusTaints: map[string]bool{"status-me": true},
StatusTaintPrefix: DefaultStatusTaintPrefix,
} }
newTaints := SanitizeTaints(node.Spec.Taints, taintConfig) newTaints := SanitizeTaints(node.Spec.Taints, taintConfig)