Skip to content

Commit

Permalink
Prevent from removing last node pool with mode System
Browse files Browse the repository at this point in the history
  • Loading branch information
mjura committed Oct 21, 2024
1 parent c082e0a commit 4dcb7bb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion controller/aks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (h *Handler) validateConfig(config *aksv1.AKSClusterConfig) error {
if np.Mode == "" {
return fmt.Errorf(cannotBeNilError, "NodePool.Mode", config.Spec.ClusterName, config.Name)
}
if np.Mode == "System" {
if np.Mode == string(armcontainerservice.AgentPoolModeSystem) {
systemMode = true
}
if np.OsType == "" {
Expand Down Expand Up @@ -964,6 +964,18 @@ func (h *Handler) updateUpstreamClusterState(ctx context.Context, config *aksv1.
// check for removed NodePools
for npName := range upstreamNodePools {
if _, ok := downstreamNodePools[npName]; !ok {
if upstreamNodePools[npName].Mode == string(armcontainerservice.AgentPoolModeSystem) {
// at least one NodePool with mode System is required in the cluster
systemNodePoolExists := false
for _, tmpNodePool := range downstreamNodePools {
if tmpNodePool.Mode == string(armcontainerservice.AgentPoolModeSystem) {
systemNodePoolExists = true
}
}
if !systemNodePoolExists {
return config, fmt.Errorf("cannot remove node pool [%s] with mode System from cluster [%s (id: %s)]", npName, config.Spec.ClusterName, config.Name)
}
}
logrus.Infof("Removing node pool [%s] from cluster [%s (id: %s)]", npName, config.Spec.ClusterName, config.Name)
err = aks.RemoveAgentPool(ctx, h.azureClients.agentPoolsClient, &config.Spec, upstreamNodePools[npName])
if err != nil {
Expand Down

0 comments on commit 4dcb7bb

Please sign in to comment.