Skip to content

Commit

Permalink
Allow to remove forced tags of a node
Browse files Browse the repository at this point in the history
Set as empty StringList
  • Loading branch information
juanfont committed Apr 18, 2024
1 parent 580f96c commit c906aaf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hscontrol/db/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ func SetTags(
tags []string,
) error {
if len(tags) == 0 {
// if no tags are provided, we remove all forced tags
if err := tx.Model(&types.Node{}).Where("id = ?", nodeID).Update("forced_tags", types.StringList{}).Error; err != nil {
return fmt.Errorf("failed to remove tags for node in the database: %w", err)
}

return nil
}

Expand Down
7 changes: 7 additions & 0 deletions hscontrol/db/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ func (s *Suite) TestSetTags(c *check.C) {
check.DeepEquals,
types.StringList([]string{"tag:bar", "tag:test", "tag:unknown"}),
)

// test removing tags
err = db.SetTags(node.ID, []string{})
c.Assert(err, check.IsNil)
node, err = db.getNode("test", "testnode")
c.Assert(err, check.IsNil)
c.Assert(node.ForcedTags, check.DeepEquals, types.StringList([]string{}))
}

func TestHeadscale_generateGivenName(t *testing.T) {
Expand Down

0 comments on commit c906aaf

Please sign in to comment.