mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-22 05:39:30 -04:00
deubgd: add instance metadata to collected logs
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
568f288f0d
commit
e5e5d8eaae
6 changed files with 99 additions and 23 deletions
|
@ -22,6 +22,8 @@ type providerMetadata interface {
|
|||
Self(ctx context.Context) (metadata.InstanceMetadata, error)
|
||||
// GetLoadBalancerEndpoint returns the endpoint of the load balancer.
|
||||
GetLoadBalancerEndpoint(ctx context.Context) (string, error)
|
||||
// UID returns the UID of the current instance.
|
||||
UID(ctx context.Context) (string, error)
|
||||
}
|
||||
|
||||
// Fetcher checks the metadata service to search for instances that were set up for debugging.
|
||||
|
@ -46,6 +48,20 @@ func (f *Fetcher) Role(ctx context.Context) (role.Role, error) {
|
|||
return self.Role, nil
|
||||
}
|
||||
|
||||
// UID returns node UID via meta data API.
|
||||
func (f *Fetcher) UID(ctx context.Context) (string, error) {
|
||||
uid, err := f.metaAPI.UID(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("retrieving UID from cloud provider metadata: %w", err)
|
||||
}
|
||||
return uid, nil
|
||||
}
|
||||
|
||||
// Self returns the current instance via meta data API.
|
||||
func (f *Fetcher) Self(ctx context.Context) (metadata.InstanceMetadata, error) {
|
||||
return f.metaAPI.Self(ctx)
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
|
|
@ -172,6 +172,8 @@ type stubMetadata struct {
|
|||
selfErr error
|
||||
getLBEndpointRes string
|
||||
getLBEndpointErr error
|
||||
uid string
|
||||
uidErr error
|
||||
}
|
||||
|
||||
func (m *stubMetadata) List(ctx context.Context) ([]metadata.InstanceMetadata, error) {
|
||||
|
@ -185,3 +187,7 @@ func (m *stubMetadata) Self(ctx context.Context) (metadata.InstanceMetadata, err
|
|||
func (m *stubMetadata) GetLoadBalancerEndpoint(ctx context.Context) (string, error) {
|
||||
return m.getLBEndpointRes, m.getLBEndpointErr
|
||||
}
|
||||
|
||||
func (m *stubMetadata) UID(context.Context) (string, error) {
|
||||
return m.uid, m.uidErr
|
||||
}
|
||||
|
|
|
@ -9,23 +9,33 @@ package fallback
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/role"
|
||||
"github.com/edgelesssys/constellation/v2/debugd/internal/debugd/metadata/cloudprovider"
|
||||
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
|
||||
)
|
||||
|
||||
// Fetcher implements metadata.Fetcher interface but does not actually fetch cloud provider metadata.
|
||||
type Fetcher struct{}
|
||||
|
||||
// Role for fallback fetcher does not try to fetch role.
|
||||
func (f Fetcher) Role(_ context.Context) (role.Role, error) {
|
||||
return role.Unknown, nil
|
||||
// NewFallbackFetcher returns a cloudprovider.Fetcher with a fake metadata backend.
|
||||
func NewFallbackFetcher() *cloudprovider.Fetcher {
|
||||
return cloudprovider.New(&fallbackMetadata{})
|
||||
}
|
||||
|
||||
// DiscoverDebugdIPs for fallback fetcher does not try to discover debugd IPs.
|
||||
func (f Fetcher) DiscoverDebugdIPs(ctx context.Context) ([]string, error) {
|
||||
type fallbackMetadata struct{}
|
||||
|
||||
// List retrieves all instances belonging to the current constellation.
|
||||
func (fallbackMetadata) List(context.Context) ([]metadata.InstanceMetadata, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// DiscoverLoadbalancerIP for fallback fetcher does not try to discover loadbalancer IP.
|
||||
func (f Fetcher) DiscoverLoadbalancerIP(ctx context.Context) (string, error) {
|
||||
// Self retrieves the current instance.
|
||||
func (fallbackMetadata) Self(context.Context) (metadata.InstanceMetadata, error) {
|
||||
return metadata.InstanceMetadata{}, nil
|
||||
}
|
||||
|
||||
// GetLoadBalancerEndpoint returns the endpoint of the load balancer.
|
||||
func (fallbackMetadata) GetLoadBalancerEndpoint(context.Context) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// UID returns the UID of the current instance.
|
||||
func (fallbackMetadata) UID(context.Context) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/role"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
@ -21,9 +22,20 @@ func TestMain(m *testing.M) {
|
|||
func TestDiscoverDebugdIPs(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
fetcher := Fetcher{}
|
||||
fetcher := NewFallbackFetcher()
|
||||
ips, err := fetcher.DiscoverDebugdIPs(context.Background())
|
||||
|
||||
assert.NoError(err)
|
||||
assert.Empty(ips)
|
||||
|
||||
rol, err := fetcher.Role(context.Background())
|
||||
assert.NoError(err)
|
||||
assert.Equal(rol, role.Unknown)
|
||||
|
||||
uid, err := fetcher.UID(context.Background())
|
||||
assert.NoError(err)
|
||||
assert.Empty(uid)
|
||||
|
||||
self, err := fetcher.Self(context.Background())
|
||||
assert.NoError(err)
|
||||
assert.Empty(self)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue