Skip to content

Commit

Permalink
Merge pull request #302 from mjura/v2.8-import-update
Browse files Browse the repository at this point in the history
[2.8] Fix for updating imported clusters
  • Loading branch information
mjura committed Nov 1, 2023
2 parents 4e57121 + f0d1c23 commit 1df3660
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions controller/aks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,16 @@ func (h *Handler) updateUpstreamClusterState(ctx context.Context, config *aksv1.
}
}

// build ClusterSpec for imported clusters from upstream config,
// otherwise ConfigSpec will be null
importedClusterSpec := upstreamSpec.DeepCopy()
updateAksCluster := false
// check Kubernetes version for update
if config.Spec.KubernetesVersion != nil {
if to.String(config.Spec.KubernetesVersion) != to.String(upstreamSpec.KubernetesVersion) {
logrus.Infof("Updating kubernetes version for cluster [%s]", config.Spec.ClusterName)
updateAksCluster = true
importedClusterSpec.KubernetesVersion = config.Spec.KubernetesVersion
}
}

Expand All @@ -768,6 +772,7 @@ func (h *Handler) updateUpstreamClusterState(ctx context.Context, config *aksv1.
if !reflect.DeepEqual(config.Spec.AuthorizedIPRanges, upstreamSpec.AuthorizedIPRanges) {
logrus.Infof("Updating authorized IP ranges for cluster [%s]", config.Spec.ClusterName)
updateAksCluster = true
importedClusterSpec.AuthorizedIPRanges = config.Spec.AuthorizedIPRanges
}
}

Expand All @@ -776,6 +781,7 @@ func (h *Handler) updateUpstreamClusterState(ctx context.Context, config *aksv1.
if to.Bool(config.Spec.HTTPApplicationRouting) != to.Bool(upstreamSpec.HTTPApplicationRouting) {
logrus.Infof("Updating HTTP application routing for cluster [%s]", config.Spec.ClusterName)
updateAksCluster = true
importedClusterSpec.HTTPApplicationRouting = config.Spec.HTTPApplicationRouting
}
}

Expand All @@ -784,6 +790,9 @@ func (h *Handler) updateUpstreamClusterState(ctx context.Context, config *aksv1.
if to.Bool(config.Spec.Monitoring) != to.Bool(upstreamSpec.Monitoring) {
logrus.Infof("Updating monitoring addon for cluster [%s]", config.Spec.ClusterName)
updateAksCluster = true
importedClusterSpec.Monitoring = config.Spec.Monitoring
importedClusterSpec.LogAnalyticsWorkspaceGroup = config.Spec.LogAnalyticsWorkspaceGroup
importedClusterSpec.LogAnalyticsWorkspaceName = config.Spec.LogAnalyticsWorkspaceName
}
}

Expand All @@ -803,6 +812,12 @@ func (h *Handler) updateUpstreamClusterState(ctx context.Context, config *aksv1.

upstreamNodePools, _ := utils.BuildNodePoolMap(upstreamSpec.NodePools, config.Spec.ClusterName)
clusterSpecCopy := config.Spec.DeepCopy()
if config.Spec.Imported {
clusterSpecCopy = importedClusterSpec
clusterSpecCopy.ResourceGroup = config.Spec.ResourceGroup
clusterSpecCopy.ResourceLocation = config.Spec.ResourceLocation
clusterSpecCopy.ClusterName = config.Spec.ClusterName
}
clusterSpecCopy.NodePools = make([]aksv1.AKSNodePool, 0, len(config.Spec.NodePools))
for _, n := range config.Spec.NodePools {
if _, ok := upstreamNodePools[*n.Name]; ok {
Expand Down

0 comments on commit 1df3660

Please sign in to comment.