Skip to content

Commit

Permalink
Filter out cluster tags from nodepool tags while showing diff
Browse files Browse the repository at this point in the history
Signed-off-by: Nootan Singh <snootan@vmware.com>
  • Loading branch information
snootan committed Jan 29, 2024
1 parent 212b9fc commit d31a14c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions internal/resources/ekscluster/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -197,12 +192,17 @@ 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)

for k, v := range npTags {
if val, ok := clusterTags[k]; !ok {
npWithoutClusterTags[k] = v
} else if v != val {
npWithoutClusterTags[k] = v
}
}

return ret
return npWithoutClusterTags
}

0 comments on commit d31a14c

Please sign in to comment.