Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions pkg/tagit/tagit.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,25 @@ func (t *TagIt) getService() (*api.AgentService, error) {
// needsTag checks if the service needs to be tagged. Based on the diff of the current and updated tags, filtering out tags that are already tagged.
// but we never override the original tags from the consul service registration
func (t *TagIt) needsTag(current []string, update []string) (updatedTags []string, shouldTag bool) {
diff := t.diffTags(current, update)
// Extract only the prefixed tags from current for comparison
currentPrefixed := make([]string, 0)
currentNonPrefixed := make([]string, 0)
for _, tag := range current {
if strings.HasPrefix(tag, t.TagPrefix+"-") {
currentPrefixed = append(currentPrefixed, tag)
} else {
currentNonPrefixed = append(currentNonPrefixed, tag)
}
}

// Compare only the prefixed tags with the update
diff := t.diffTags(currentPrefixed, update)
if len(diff) == 0 {
return nil, false
}
currentFiltered, _ := t.excludeTagged(current)
updatedTags = append(currentFiltered, update...)

// Combine non-prefixed tags with the new update tags
updatedTags = append(currentNonPrefixed, update...)
slices.Sort(updatedTags)
updatedTags = slices.Compact(updatedTags)
return updatedTags, true
Expand Down
7 changes: 7 additions & 0 deletions pkg/tagit/tagit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ func TestNeedsTag(t *testing.T) {
expectedTags: []string{"tag2", "tag3", "tag4", "tag5"},
expectedShould: true,
},
{
name: "No Update When Prefixed Tags Unchanged",
current: []string{"tag-tag1", "tag-tag2", "other-tag", "another-tag"},
update: []string{"tag-tag1", "tag-tag2"},
expectedTags: nil,
expectedShould: false,
},
}

for _, tt := range tests {
Expand Down
Loading