debugd: filter own instance from list of discovered debugd instances

This commit is contained in:
Malte Poll 2022-03-30 13:26:17 +02:00 committed by Malte Poll
parent 7143b29caf
commit 6954683f18
2 changed files with 12 additions and 1 deletions

View File

@ -49,10 +49,21 @@ func NewAzure(ctx context.Context) (*Fetcher, error) {
// DiscoverDebugdIPs will query the metadata of all instances and return any ips of instances already set up for debugging.
func (f *Fetcher) DiscoverDebugdIPs(ctx context.Context) ([]string, error) {
self, err := f.metaAPI.Self(ctx)
if err != nil {
return nil, fmt.Errorf("retrieving own instance failed: %w", err)
}
instances, err := f.metaAPI.List(ctx)
if err != nil {
return nil, fmt.Errorf("retrieving instances failed: %w", err)
}
// filter own instance from instance list
for i, instance := range instances {
if instance.ProviderID == self.ProviderID {
instances = append(instances[:i], instances[i+1:]...)
break
}
}
var ips []string
for _, instance := range instances {
ips = append(ips, instance.IPs...)

View File

@ -34,7 +34,7 @@ func TestDiscoverDebugIPs(t *testing.T) {
},
},
expectedIPs: []string{
"192.0.2.0", "192.0.2.1", "192.0.2.2",
"192.0.2.1", "192.0.2.2",
},
},
"retrieve fails": {