From 6954683f18d6ed6c0f4217296ff981b6ffe904ec Mon Sep 17 00:00:00 2001 From: Malte Poll Date: Wed, 30 Mar 2022 13:26:17 +0200 Subject: [PATCH] debugd: filter own instance from list of discovered debugd instances --- debugd/debugd/metadata/cloudprovider/cloudprovider.go | 11 +++++++++++ .../metadata/cloudprovider/cloudprovider_test.go | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/debugd/debugd/metadata/cloudprovider/cloudprovider.go b/debugd/debugd/metadata/cloudprovider/cloudprovider.go index 537c89aff..5bee5a647 100644 --- a/debugd/debugd/metadata/cloudprovider/cloudprovider.go +++ b/debugd/debugd/metadata/cloudprovider/cloudprovider.go @@ -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...) diff --git a/debugd/debugd/metadata/cloudprovider/cloudprovider_test.go b/debugd/debugd/metadata/cloudprovider/cloudprovider_test.go index 182be7792..d3b6ee665 100644 --- a/debugd/debugd/metadata/cloudprovider/cloudprovider_test.go +++ b/debugd/debugd/metadata/cloudprovider/cloudprovider_test.go @@ -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": {