Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiscoveryConfig Status: update even when no resources are found #49588

Merged
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
4 changes: 2 additions & 2 deletions lib/srv/discovery/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ type Fetcher interface {
// IntegrationName identifies the integration name whose credentials were used to fetch the resources.
// Might be empty when the fetcher is using ambient credentials.
IntegrationName() string
// DiscoveryConfigName is the name of the discovery config which originated the resource.
// GetDiscoveryConfigName is the name of the discovery config which originated the resource.
// Might be empty when the fetcher is using static matchers:
// ie teleport.yaml/discovery_service.<cloud>.<matcher>
DiscoveryConfigName() string
GetDiscoveryConfigName() string
// Cloud returns the cloud the fetcher is operating.
Cloud() string
}
4 changes: 2 additions & 2 deletions lib/srv/discovery/common/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ func (w *Watcher) fetchAndSend() {
// Add the integration name to the static labels for each resource.
fetcherLabels[types.TeleportInternalDiscoveryIntegrationName] = lFetcher.IntegrationName()
}
if lFetcher.DiscoveryConfigName() != "" {
if lFetcher.GetDiscoveryConfigName() != "" {
// Add the discovery config name to the static labels of each resource.
fetcherLabels[types.TeleportInternalDiscoveryConfigName] = lFetcher.DiscoveryConfigName()
fetcherLabels[types.TeleportInternalDiscoveryConfigName] = lFetcher.GetDiscoveryConfigName()
}

if w.cfg.DiscoveryGroup != "" {
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/discovery/common/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (m *mockFetcher) IntegrationName() string {
return ""
}

func (m *mockFetcher) DiscoveryConfigName() string {
func (m *mockFetcher) GetDiscoveryConfigName() string {
return ""
}
func (m *mockFetcher) Cloud() string {
Expand Down
11 changes: 10 additions & 1 deletion lib/srv/discovery/database_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/gravitational/teleport/lib/services"
"github.com/gravitational/teleport/lib/srv/discovery/common"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/utils/slices"
)

const databaseEventPrefix = "db/"
Expand Down Expand Up @@ -74,6 +75,14 @@ func (s *Server) startDatabaseWatchers() error {
Origin: types.OriginCloud,
Clock: s.clock,
PreFetchHookFn: func() {
discoveryConfigs := slices.FilterMapUnique(
s.getAllDatabaseFetchers(),
func(f common.Fetcher) (s string, include bool) {
return f.GetDiscoveryConfigName(), f.GetDiscoveryConfigName() != ""
},
)
s.updateDiscoveryConfigStatus(discoveryConfigs...)

s.awsRDSResourcesStatus.reset()
},
},
Expand All @@ -99,7 +108,7 @@ func (s *Server) startDatabaseWatchers() error {

resourceGroup := awsResourceGroupFromLabels(db.GetStaticLabels())
resourcesFoundByGroup[resourceGroup] += 1
discoveryConfigsChanged[resourceGroup.discoveryConfig] = struct{}{}
discoveryConfigsChanged[resourceGroup.discoveryConfigName] = struct{}{}

dbs = append(dbs, db)
}
Expand Down
Loading
Loading