Skip to content

Commit

Permalink
Keep Namespace labels order in tags
Browse files Browse the repository at this point in the history
Signed-off-by: Yanjun Zhou <yanjun.zhou@broadcom.com>
  • Loading branch information
yanjunz97 committed Feb 25, 2025
1 parent f3b8b84 commit 70ae1f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 9 additions & 3 deletions pkg/nsx/services/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"sort"
"strings"
"sync"

Expand Down Expand Up @@ -366,9 +367,14 @@ func (service *SubnetService) GenerateSubnetNSTags(obj client.Object) []model.Ta
model.Tag{Scope: common.String(common.TagScopeVMNamespace), Tag: common.String(obj.GetNamespace())})
}
}
// Append Namespace labels as tags
for k, v := range namespace.Labels {
tags = append(tags, model.Tag{Scope: common.String(k), Tag: common.String(v)})
// Append Namespace labels in order as tags
labelKeys := make([]string, 0, len(namespace.Labels))
for k := range namespace.Labels {
labelKeys = append(labelKeys, k)
}
sort.Strings(labelKeys)
for _, k := range labelKeys {
tags = append(tags, model.Tag{Scope: common.String(k), Tag: common.String(namespace.Labels[k])})
}
return tags
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/nsx/services/subnetport/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"slices"
"sort"

"github.com/google/uuid"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -65,8 +66,14 @@ func (service *SubnetPortService) buildSubnetPort(obj interface{}, nsxSubnet *mo
namespace_uid := namespace.UID
tags := util.BuildBasicTags(getCluster(service), obj, namespace_uid)
if labelTags != nil {
for k, v := range *labelTags {
tags = append(tags, model.Tag{Scope: String(k), Tag: String(v)})
// Append Namespace labels in order as tags
labelKeys := make([]string, 0, len(*labelTags))
for k := range *labelTags {
labelKeys = append(labelKeys, k)
}
sort.Strings(labelKeys)
for _, k := range labelKeys {
tags = append(tags, model.Tag{Scope: common.String(k), Tag: common.String((*labelTags)[k])})
}
}
nsxSubnetPort := &model.VpcSubnetPort{
Expand Down

0 comments on commit 70ae1f8

Please sign in to comment.