Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/proto/teleport/legacy/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,9 @@ message InstanceFilter {

// NewerThanVersion is an optional exclusive lower version bound.
string NewerThanVersion = 7;

// UpdateGroup matches instance update group if specified.
string UpdateGroup = 8;
}

// ServerV2 represents a Node, App, Database, Proxy or Auth Service instance in a Teleport cluster.
Expand Down
14 changes: 14 additions & 0 deletions api/types/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ func (f InstanceFilter) Match(i Instance) bool {
return false
}

// Empty update group matches all.
if f.UpdateGroup != "" {
if updateInfo := i.GetUpdaterInfo(); updateInfo == nil || updateInfo.UpdateGroup != f.UpdateGroup {
return false
}
}

return true
}

Expand Down Expand Up @@ -183,6 +190,9 @@ type Instance interface {
// another instance.
GetLastMeasurement() *SystemClockMeasurement

// GetUpdaterInfo returns information about the instance updater.
GetUpdaterInfo() *UpdaterV2Info

// Clone performs a deep copy on this instance.
Clone() Instance
}
Expand Down Expand Up @@ -286,6 +296,10 @@ func (i *InstanceV1) GetExternalUpgraderVersion() string {
return i.Spec.ExternalUpgraderVersion
}

func (i *InstanceV1) GetUpdaterInfo() *UpdaterV2Info {
return i.Spec.UpdaterInfo
}

func (i *InstanceV1) GetControlLog() []InstanceControlLogEntry {
return i.Spec.ControlLog
}
Expand Down
64 changes: 44 additions & 20 deletions api/types/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,30 @@ import (

func TestInstanceFilter(t *testing.T) {
iis := []struct {
id string
version string
services []SystemRole
upgrader string
id string
version string
services []SystemRole
upgrader string
updateGroup string
}{
{
id: "a1",
version: "v1.2.3",
services: []SystemRole{RoleAuth},
id: "a1",
version: "v1.2.3",
services: []SystemRole{RoleAuth},
updateGroup: "default",
},
{
id: "a2",
version: "v2.3.4",
services: []SystemRole{RoleAuth, RoleNode},
upgrader: "kube",
id: "a2",
version: "v2.3.4",
services: []SystemRole{RoleAuth, RoleNode},
upgrader: "kube",
updateGroup: "default",
},
{
id: "p1",
version: "v1.2.1",
services: []SystemRole{RoleProxy},
id: "p1",
version: "v1.2.1",
services: []SystemRole{RoleProxy},
updateGroup: "foobar",
},
{
id: "p2",
Expand All @@ -58,10 +62,18 @@ func TestInstanceFilter(t *testing.T) {
// set up group of test instances
var instances []Instance
for _, ii := range iis {
var UpdaterInfo *UpdaterV2Info
if ii.updateGroup != "" {
UpdaterInfo = &UpdaterV2Info{
UpdateGroup: ii.updateGroup,
}
}

ins, err := NewInstance(ii.id, InstanceSpecV1{
Version: ii.version,
Services: ii.services,
ExternalUpgrader: ii.upgrader,
UpdaterInfo: UpdaterInfo,
})

require.NoError(t, err, "id=%s", ii.id)
Expand Down Expand Up @@ -146,17 +158,29 @@ func TestInstanceFilter(t *testing.T) {
"p1",
},
},
{
desc: "match-update-group",
filter: InstanceFilter{
UpdateGroup: "default",
},
matches: []string{
"a1",
"a2",
},
},
}

for _, tt := range tts {
var matches []string
for _, ins := range instances {
if tt.filter.Match(ins) {
matches = append(matches, ins.GetName())
t.Run(tt.desc, func(t *testing.T) {
var matches []string
for _, ins := range instances {
if tt.filter.Match(ins) {
matches = append(matches, ins.GetName())
}
}
}

require.Equal(t, tt.matches, matches)
require.Equal(t, tt.matches, matches)
})
}
}

Expand Down
Loading
Loading