tailcfg: add Node.Tags

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali 2021-10-20 14:26:31 -07:00 committed by Maisem Ali
parent 85fa1b0d61
commit 10745c099a
3 changed files with 34 additions and 2 deletions

View File

@ -164,6 +164,15 @@ type Node struct {
Hostinfo Hostinfo Hostinfo Hostinfo
Created time.Time Created time.Time
// Tags are the list of ACL tags applied to this node.
// Tags take the form of `tag:<value>` where value starts
// with a letter and only contains alphanumerics and dashes `-`.
// Some valid tag examples:
// `tag:prod`
// `tag:database`
// `tag:lab-1`
Tags []string `json:",omitempty"`
// PrimaryRoutes are the routes from AllowedIPs that this node // PrimaryRoutes are the routes from AllowedIPs that this node
// is currently the primary subnet router for, as determined // is currently the primary subnet router for, as determined
// by the control plane. It does not include the self address // by the control plane. It does not include the self address
@ -1172,7 +1181,8 @@ func (n *Node) Equal(n2 *Node) bool {
eqStrings(n.Capabilities, n2.Capabilities) && eqStrings(n.Capabilities, n2.Capabilities) &&
n.ComputedName == n2.ComputedName && n.ComputedName == n2.ComputedName &&
n.computedHostIfDifferent == n2.computedHostIfDifferent && n.computedHostIfDifferent == n2.computedHostIfDifferent &&
n.ComputedNameWithHost == n2.ComputedNameWithHost n.ComputedNameWithHost == n2.ComputedNameWithHost &&
eqStrings(n.Tags, n2.Tags)
} }
func eqBoolPtr(a, b *bool) bool { func eqBoolPtr(a, b *bool) bool {

View File

@ -51,6 +51,7 @@ func (src *Node) Clone() *Node {
dst.AllowedIPs = append(src.AllowedIPs[:0:0], src.AllowedIPs...) dst.AllowedIPs = append(src.AllowedIPs[:0:0], src.AllowedIPs...)
dst.Endpoints = append(src.Endpoints[:0:0], src.Endpoints...) dst.Endpoints = append(src.Endpoints[:0:0], src.Endpoints...)
dst.Hostinfo = *src.Hostinfo.Clone() dst.Hostinfo = *src.Hostinfo.Clone()
dst.Tags = append(src.Tags[:0:0], src.Tags...)
dst.PrimaryRoutes = append(src.PrimaryRoutes[:0:0], src.PrimaryRoutes...) dst.PrimaryRoutes = append(src.PrimaryRoutes[:0:0], src.PrimaryRoutes...)
if dst.LastSeen != nil { if dst.LastSeen != nil {
dst.LastSeen = new(time.Time) dst.LastSeen = new(time.Time)
@ -81,6 +82,7 @@ var _NodeCloneNeedsRegeneration = Node(struct {
DERP string DERP string
Hostinfo Hostinfo Hostinfo Hostinfo
Created time.Time Created time.Time
Tags []string
PrimaryRoutes []netaddr.IPPrefix PrimaryRoutes []netaddr.IPPrefix
LastSeen *time.Time LastSeen *time.Time
Online *bool Online *bool

View File

@ -195,7 +195,7 @@ func TestNodeEqual(t *testing.T) {
"ID", "StableID", "Name", "User", "Sharer", "ID", "StableID", "Name", "User", "Sharer",
"Key", "KeyExpiry", "Machine", "DiscoKey", "Key", "KeyExpiry", "Machine", "DiscoKey",
"Addresses", "AllowedIPs", "Endpoints", "DERP", "Hostinfo", "Addresses", "AllowedIPs", "Endpoints", "DERP", "Hostinfo",
"Created", "PrimaryRoutes", "Created", "Tags", "PrimaryRoutes",
"LastSeen", "Online", "KeepAlive", "MachineAuthorized", "LastSeen", "Online", "KeepAlive", "MachineAuthorized",
"Capabilities", "Capabilities",
"ComputedName", "computedHostIfDifferent", "ComputedNameWithHost", "ComputedName", "computedHostIfDifferent", "ComputedNameWithHost",
@ -366,6 +366,26 @@ func TestNodeEqual(t *testing.T) {
&Node{DERP: "bar"}, &Node{DERP: "bar"},
false, false,
}, },
{
&Node{Tags: []string{"tag:foo"}},
&Node{Tags: []string{"tag:foo"}},
true,
},
{
&Node{Tags: []string{"tag:foo", "tag:bar"}},
&Node{Tags: []string{"tag:bar"}},
false,
},
{
&Node{Tags: []string{"tag:foo"}},
&Node{Tags: []string{"tag:bar"}},
false,
},
{
&Node{Tags: []string{"tag:foo"}},
&Node{},
false,
},
} }
for i, tt := range tests { for i, tt := range tests {
got := tt.a.Equal(tt.b) got := tt.a.Equal(tt.b)