Skip to content

Commit

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

newTags := types.StringList{}
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 a31fdf2

Please sign in to comment.