Skip to content

Commit 488c3f7

Browse files
committed
fix the re-tag bug
1 parent 09d3fe8 commit 488c3f7

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

pkg/tagit/tagit.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,25 @@ func (t *TagIt) getService() (*api.AgentService, error) {
197197
// 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.
198198
// but we never override the original tags from the consul service registration
199199
func (t *TagIt) needsTag(current []string, update []string) (updatedTags []string, shouldTag bool) {
200-
diff := t.diffTags(current, update)
200+
// Extract only the prefixed tags from current for comparison
201+
currentPrefixed := make([]string, 0)
202+
currentNonPrefixed := make([]string, 0)
203+
for _, tag := range current {
204+
if strings.HasPrefix(tag, t.TagPrefix+"-") {
205+
currentPrefixed = append(currentPrefixed, tag)
206+
} else {
207+
currentNonPrefixed = append(currentNonPrefixed, tag)
208+
}
209+
}
210+
211+
// Compare only the prefixed tags with the update
212+
diff := t.diffTags(currentPrefixed, update)
201213
if len(diff) == 0 {
202214
return nil, false
203215
}
204-
currentFiltered, _ := t.excludeTagged(current)
205-
updatedTags = append(currentFiltered, update...)
216+
217+
// Combine non-prefixed tags with the new update tags
218+
updatedTags = append(currentNonPrefixed, update...)
206219
slices.Sort(updatedTags)
207220
updatedTags = slices.Compact(updatedTags)
208221
return updatedTags, true

pkg/tagit/tagit_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ func TestNeedsTag(t *testing.T) {
195195
expectedTags: []string{"tag2", "tag3", "tag4", "tag5"},
196196
expectedShould: true,
197197
},
198+
{
199+
name: "No Update When Prefixed Tags Unchanged",
200+
current: []string{"tag-tag1", "tag-tag2", "other-tag", "another-tag"},
201+
update: []string{"tag-tag1", "tag-tag2"},
202+
expectedTags: nil,
203+
expectedShould: false,
204+
},
198205
}
199206

200207
for _, tt := range tests {

0 commit comments

Comments
 (0)