operator: allow increasing number of node upgrade budget

This commit is contained in:
Leonard Cohnen 2024-10-20 22:12:56 +02:00 committed by Markus Rudy
parent 37900d9d9c
commit 11c02980be
6 changed files with 24 additions and 9 deletions

View File

@ -54,6 +54,11 @@ spec:
description: KubernetesComponentsReference is a reference to the ConfigMap description: KubernetesComponentsReference is a reference to the ConfigMap
containing the Kubernetes components to use for all nodes. containing the Kubernetes components to use for all nodes.
type: string type: string
maxNodeBudget:
description: MaxNodeBudget is the maximum number of nodes that can
be created simultaneously.
format: int32
type: integer
type: object type: object
status: status:
description: NodeVersionStatus defines the observed state of NodeVersion. description: NodeVersionStatus defines the observed state of NodeVersion.

View File

@ -21,6 +21,8 @@ type NodeVersionSpec struct {
KubernetesComponentsReference string `json:"kubernetesComponentsReference,omitempty"` KubernetesComponentsReference string `json:"kubernetesComponentsReference,omitempty"`
// KubernetesClusterVersion is the advertised Kubernetes version of the cluster. // KubernetesClusterVersion is the advertised Kubernetes version of the cluster.
KubernetesClusterVersion string `json:"kubernetesClusterVersion,omitempty"` KubernetesClusterVersion string `json:"kubernetesClusterVersion,omitempty"`
// MaxNodeBudget is the maximum number of nodes that can be created simultaneously.
MaxNodeBudget uint32 `json:"maxNodeBudget,omitempty"`
} }
// NodeVersionStatus defines the observed state of NodeVersion. // NodeVersionStatus defines the observed state of NodeVersion.

View File

@ -54,6 +54,11 @@ spec:
description: KubernetesComponentsReference is a reference to the ConfigMap description: KubernetesComponentsReference is a reference to the ConfigMap
containing the Kubernetes components to use for all nodes. containing the Kubernetes components to use for all nodes.
type: string type: string
maxNodeBudget:
description: MaxNodeBudget is the maximum number of nodes that can
be created simultaneously.
format: int32
type: integer
type: object type: object
status: status:
description: NodeVersionStatus defines the observed state of NodeVersion. description: NodeVersionStatus defines the observed state of NodeVersion.

View File

@ -13,4 +13,4 @@ kind: Kustomization
images: images:
- name: controller - name: controller
newName: ghcr.io/edgelesssys/constellation/node-operator newName: ghcr.io/edgelesssys/constellation/node-operator
newTag: v0.0.0 newTag: v0.0.1

View File

@ -38,8 +38,6 @@ import (
) )
const ( const (
// nodeOverprovisionLimit is the maximum number of extra nodes created during the update procedure at any point in time.
nodeOverprovisionLimit = 1
// nodeJoinTimeout is the time limit pending nodes have to join the cluster before being terminated. // nodeJoinTimeout is the time limit pending nodes have to join the cluster before being terminated.
nodeJoinTimeout = time.Minute * 30 nodeJoinTimeout = time.Minute * 30
// nodeLeaveTimeout is the time limit pending nodes have to leave the cluster and being terminated. // nodeLeaveTimeout is the time limit pending nodes have to leave the cluster and being terminated.
@ -161,9 +159,14 @@ func (r *NodeVersionReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// - being created (joining) // - being created (joining)
// - being destroyed (leaving) // - being destroyed (leaving)
// - heirs to outdated nodes // - heirs to outdated nodes
extraNodes := len(groups.Heirs) + len(groups.AwaitingAnnotation) + len(pendingNodeList.Items) extraNodes := uint32(len(groups.Heirs) + len(groups.AwaitingAnnotation) + len(pendingNodeList.Items))
// newNodesBudget is the maximum number of new nodes that can be created in this Reconcile call. // newNodesBudget is the maximum number of new nodes that can be created in this Reconcile call.
var newNodesBudget int var newNodesBudget uint32
nodeOverprovisionLimit := uint32(1)
// Use user definable value if it makes sense
if desiredNodeVersion.Spec.MaxNodeBudget > 0 {
nodeOverprovisionLimit = desiredNodeVersion.Spec.MaxNodeBudget
}
if extraNodes < nodeOverprovisionLimit { if extraNodes < nodeOverprovisionLimit {
newNodesBudget = nodeOverprovisionLimit - extraNodes newNodesBudget = nodeOverprovisionLimit - extraNodes
} }
@ -743,7 +746,7 @@ func (r *NodeVersionReconciler) tryUpdateStatus(ctx context.Context, name types.
} }
// nodeVersionStatus generates the NodeVersion.Status field given node groups and the budget for new nodes. // nodeVersionStatus generates the NodeVersion.Status field given node groups and the budget for new nodes.
func nodeVersionStatus(scheme *runtime.Scheme, groups nodeGroups, pendingNodes []updatev1alpha1.PendingNode, invalidNodes []corev1.Node, newNodesBudget int) updatev1alpha1.NodeVersionStatus { func nodeVersionStatus(scheme *runtime.Scheme, groups nodeGroups, pendingNodes []updatev1alpha1.PendingNode, invalidNodes []corev1.Node, newNodesBudget uint32) updatev1alpha1.NodeVersionStatus {
var status updatev1alpha1.NodeVersionStatus var status updatev1alpha1.NodeVersionStatus
outdatedCondition := metav1.Condition{ outdatedCondition := metav1.Condition{
Type: updatev1alpha1.ConditionOutdated, Type: updatev1alpha1.ConditionOutdated,
@ -821,7 +824,7 @@ func nodeVersionStatus(scheme *runtime.Scheme, groups nodeGroups, pendingNodes [
} }
status.Pending = append(status.Pending, *pendingRef) status.Pending = append(status.Pending, *pendingRef)
} }
status.Budget = uint32(newNodesBudget) status.Budget = newNodesBudget
return status return status
} }
@ -941,5 +944,5 @@ type newNodeConfig struct {
outdatedNodes []corev1.Node outdatedNodes []corev1.Node
pendingNodes []updatev1alpha1.PendingNode pendingNodes []updatev1alpha1.PendingNode
scalingGroupByID map[string]updatev1alpha1.ScalingGroup scalingGroupByID map[string]updatev1alpha1.ScalingGroup
newNodesBudget int newNodesBudget uint32
} }

View File

@ -332,7 +332,7 @@ func TestCreateNewNodes(t *testing.T) {
outdatedNodes []corev1.Node outdatedNodes []corev1.Node
pendingNodes []updatev1alpha1.PendingNode pendingNodes []updatev1alpha1.PendingNode
scalingGroupByID map[string]updatev1alpha1.ScalingGroup scalingGroupByID map[string]updatev1alpha1.ScalingGroup
budget int budget uint32
wantCreateCalls []string wantCreateCalls []string
}{ }{
"no outdated nodes": { "no outdated nodes": {