From 4dcb7bb244e4f5fa39d5c4dcbd7cd234b3c9c695 Mon Sep 17 00:00:00 2001 From: Michal Jura Date: Mon, 21 Oct 2024 11:28:58 +0200 Subject: [PATCH] Prevent from removing last node pool with mode System Issue: https://github.com/rancher/aks-operator/issues/619 --- controller/aks-cluster-config-handler.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/controller/aks-cluster-config-handler.go b/controller/aks-cluster-config-handler.go index b9693b8a..d755bd53 100644 --- a/controller/aks-cluster-config-handler.go +++ b/controller/aks-cluster-config-handler.go @@ -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 == "" { @@ -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 {