@@ -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
199199func (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
0 commit comments