Skip to content

Commit

Permalink
add missing discovery config labels for GCP and Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoandredinis committed Nov 18, 2024
1 parent 7c60d86 commit f176d32
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/srv/db/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (s *Server) startCloudWatcher(ctx context.Context) error {
if err != nil {
return trace.Wrap(err)
}
azureFetchers, err := dbfetchers.MakeAzureFetchers(s.cfg.CloudClients, s.cfg.AzureMatchers)
azureFetchers, err := dbfetchers.MakeAzureFetchers(s.cfg.CloudClients, s.cfg.AzureMatchers, "" /* discovery config */)
if err != nil {
return trace.Wrap(err)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func (s *Server) databaseFetchersFromMatchers(matchers Matchers, discoveryConfig
// Azure
azureDatabaseMatchers, _ := splitMatchers(matchers.Azure, db.IsAzureMatcherType)
if len(azureDatabaseMatchers) > 0 {
databaseFetchers, err := db.MakeAzureFetchers(s.CloudClients, azureDatabaseMatchers)
databaseFetchers, err := db.MakeAzureFetchers(s.CloudClients, azureDatabaseMatchers, discoveryConfig)
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down
3 changes: 2 additions & 1 deletion lib/srv/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,7 @@ func TestDiscoveryDatabase(t *testing.T) {
_, awsRedshiftDBWithDiscoveryConfig := makeRedshiftCluster(t, "aws-redshift", "us-east-1", rewriteDiscoveryLabelsParams{discoveryGroup: mainDiscoveryGroup, discoveryConfig: discoveryConfigName})
awsRDSInstance, awsRDSDB := makeRDSInstance(t, "aws-rds", "us-west-1", rewriteDiscoveryLabelsParams{discoveryGroup: mainDiscoveryGroup})
azRedisResource, azRedisDB := makeAzureRedisServer(t, "az-redis", "sub1", "group1", "East US", rewriteDiscoveryLabelsParams{discoveryGroup: mainDiscoveryGroup})
_, azRedisDBWithDiscoveryConfig := makeAzureRedisServer(t, "az-redis", "sub1", "group1", "East US", rewriteDiscoveryLabelsParams{discoveryGroup: mainDiscoveryGroup, discoveryConfig: discoveryConfigName})

role := types.AssumeRole{RoleARN: "arn:aws:iam::123456789012:role/test-role", ExternalID: "test123"}
awsRDSDBWithRole := awsRDSDB.Copy()
Expand Down Expand Up @@ -2038,7 +2039,7 @@ func TestDiscoveryDatabase(t *testing.T) {
},
{
name: "discover Azure database using dynamic matchers",
expectDatabases: []types.Database{azRedisDB},
expectDatabases: []types.Database{azRedisDBWithDiscoveryConfig},
discoveryConfigs: func(t *testing.T) []*discoveryconfig.DiscoveryConfig {
dc1 := matcherForDiscoveryConfigFn(t, mainDiscoveryGroup, Matchers{
Azure: []types.AzureMatcher{{
Expand Down
6 changes: 4 additions & 2 deletions lib/srv/discovery/fetchers/db/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type azureFetcherConfig struct {
Regions []string
// regionSet is a set of regions, used for efficient region match lookup.
regionSet map[string]struct{}
// DiscoveryConfig is the name of the discovery config which originated the resource.
DiscoveryConfig string
}

// regionMatches returns whether a given region matches the configured Regions selector
Expand Down Expand Up @@ -151,8 +153,8 @@ func (f *azureFetcher[DBType, ListClient]) FetcherType() string {
}

// IntegrationName returns the integration name.
// There are no integrations supporting Azure Discovery fetchers, so this returns an empty string.
func (f *azureFetcher[DBType, ListClient]) IntegrationName() string {
// There is currently no integration that supports Auto Discover for Azure resources.
return ""
}

Expand All @@ -161,7 +163,7 @@ func (f *azureFetcher[DBType, ListClient]) IntegrationName() string {
// Might be empty when the fetcher is using static matchers:
// ie teleport.yaml/discovery_service.<cloud>.<matcher>
func (f *azureFetcher[DBType, ListClient]) DiscoveryConfigName() string {
return ""
return f.cfg.DiscoveryConfig
}

// Get returns Azure DB servers matching the watcher's selectors.
Expand Down
15 changes: 8 additions & 7 deletions lib/srv/discovery/fetchers/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func MakeAWSFetchers(ctx context.Context, clients cloud.AWSClients, matchers []t
}

// MakeAzureFetchers creates new Azure database fetchers.
func MakeAzureFetchers(clients cloud.AzureClients, matchers []types.AzureMatcher) (result []common.Fetcher, err error) {
func MakeAzureFetchers(clients cloud.AzureClients, matchers []types.AzureMatcher, discoveryConfig string) (result []common.Fetcher, err error) {
for _, matcher := range services.SimplifyAzureMatchers(matchers) {
for _, matcherType := range matcher.Types {
makeFetchers, found := makeAzureFetcherFuncs[matcherType]
Expand All @@ -112,12 +112,13 @@ func MakeAzureFetchers(clients cloud.AzureClients, matchers []types.AzureMatcher
for _, sub := range matcher.Subscriptions {
for _, group := range matcher.ResourceGroups {
fetcher, err := makeFetcher(azureFetcherConfig{
AzureClients: clients,
Type: matcherType,
Subscription: sub,
ResourceGroup: group,
Labels: matcher.ResourceTags,
Regions: matcher.Regions,
AzureClients: clients,
Type: matcherType,
Subscription: sub,
ResourceGroup: group,
Labels: matcher.ResourceTags,
Regions: matcher.Regions,
DiscoveryConfig: discoveryConfig,
})
if err != nil {
return nil, trace.Wrap(err)
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/discovery/fetchers/db/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func mustMakeAWSFetchers(t *testing.T, clients cloud.AWSClients, matchers []type
func mustMakeAzureFetchers(t *testing.T, clients cloud.AzureClients, matchers []types.AzureMatcher) []common.Fetcher {
t.Helper()

fetchers, err := MakeAzureFetchers(clients, matchers)
fetchers, err := MakeAzureFetchers(clients, matchers, "" /* discovery config */)
require.NoError(t, err)
require.NotEmpty(t, fetchers)

Expand Down
5 changes: 4 additions & 1 deletion lib/srv/discovery/fetchers/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type GKEFetcherConfig struct {
FilterLabels types.Labels
// Log is the logger.
Log logrus.FieldLogger
// DiscoveryConfig is the name of the discovery config which originated the resource.
DiscoveryConfig string
}

// CheckAndSetDefaults validates and sets the defaults values.
Expand Down Expand Up @@ -149,10 +151,11 @@ func (a *gkeFetcher) Cloud() string {
}

func (a *gkeFetcher) IntegrationName() string {
// There is currently no integration that supports Auto Discover for GCP resources.
return ""
}
func (a *gkeFetcher) DiscoveryConfigName() string {
return ""
return a.DiscoveryConfig
}

func (a *gkeFetcher) String() string {
Expand Down
5 changes: 4 additions & 1 deletion lib/srv/discovery/fetchers/kube_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type KubeAppsFetcherConfig struct {
Log logrus.FieldLogger
// ProtocolChecker inspects port to find your whether they are HTTP/HTTPS or not.
ProtocolChecker ProtocolChecker
// DiscoveryConfig is the name of the discovery config which originated the resource.
DiscoveryConfig string
}

// CheckAndSetDefaults validates and sets the defaults values.
Expand Down Expand Up @@ -234,11 +236,12 @@ func (f *KubeAppFetcher) Cloud() string {
}

func (f *KubeAppFetcher) IntegrationName() string {
// KubeAppFetcher does not have an integration.
return ""
}

func (f *KubeAppFetcher) DiscoveryConfigName() string {
return ""
return f.DiscoveryConfig
}

func (f *KubeAppFetcher) FetcherType() string {
Expand Down

0 comments on commit f176d32

Please sign in to comment.