From 2e67472ffa8e456a318791e264595d6b3086aa9d Mon Sep 17 00:00:00 2001 From: Nootan Singh Date: Mon, 29 Jan 2024 13:26:50 +0530 Subject: [PATCH] Filter out cluster tags from nodepool tags while showing diff Signed-off-by: Nootan Singh --- internal/resources/ekscluster/data_source.go | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/internal/resources/ekscluster/data_source.go b/internal/resources/ekscluster/data_source.go index f5c74f894..1a95d5aca 100644 --- a/internal/resources/ekscluster/data_source.go +++ b/internal/resources/ekscluster/data_source.go @@ -143,10 +143,6 @@ func setResourceData(d *schema.ResourceData, eksCluster *eksmodel.VmwareTanzuMan // see the explanation of this in the func doc of nodepoolPosMap npPosMap := nodepoolPosMap(tfNodepools) - - // get nodepool mapping of names with their details - npDataMap := nodepoolDetailsMap(tfNodepools) - nodepools := make([]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolDefinition, len(tfNodepools)) for _, np := range remoteNodepools { @@ -157,11 +153,10 @@ func setResourceData(d *schema.ResourceData, eksCluster *eksmodel.VmwareTanzuMan }, Spec: np.Spec, } + npDef.Spec.Tags = filterOutClusterTags(np.Spec.Tags, eksCluster.Spec.Config.Tags) if pos, ok := npPosMap[np.FullName.Name]; ok { nodepools[pos] = npDef - // Add tf file nodepool tags as part of nodepool tags so that it will not show difference - nodepools[pos].Spec.Tags = npDataMap[np.FullName.Name].Spec.Tags } else { nodepools = append(nodepools, npDef) } @@ -197,12 +192,16 @@ func nodepoolPosMap(nps []*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolD return ret } -// Returns mapping of nodepool names to their corresponding details in the array. -func nodepoolDetailsMap(nps []*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolDefinition) map[string]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolDefinition { - ret := map[string]*eksmodel.VmwareTanzuManageV1alpha1EksclusterNodepoolDefinition{} - for _, np := range nps { - ret[np.Info.Name] = np - } +// filterOutClusterTags is used to remove cluster tags from nodepool while checking diff. +func filterOutClusterTags(npTags, clusterTags map[string]string) map[string]string { + npWithoutClusterTags := make(map[string]string) - return ret + for k, v := range npTags { + if val, ok := clusterTags[k]; !ok { + npWithoutClusterTags[k] = v + } else if v != val { + npWithoutClusterTags[k] = v + } + } + return npWithoutClusterTags }