Skip to content

Commit

Permalink
Deflake discovery tests (gravitational#30474)
Browse files Browse the repository at this point in the history
This change deflakes some discovery server tests.
  • Loading branch information
atburke authored Aug 17, 2023
1 parent 96f2e48 commit 2e36d23
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 202 deletions.
44 changes: 34 additions & 10 deletions lib/srv/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ func (m Matchers) IsEmpty() bool {
return len(m.GCP) == 0 && len(m.AWS) == 0 && len(m.Azure) == 0 && len(m.Kubernetes) == 0
}

// ssmInstaller handles running SSM commands that install Teleport on EC2 instances.
type ssmInstaller interface {
Run(ctx context.Context, req server.SSMRunRequest) error
}

// azureInstaller handles running commands that install Teleport on Azure
// virtual machines.
type azureInstaller interface {
Run(ctx context.Context, req server.AzureRunRequest) error
}

// gcpInstaller handles running commands that install Teleport on GCP
// virtual machines.
type gcpInstaller interface {
Run(ctx context.Context, req server.GCPRunRequest) error
}

// Config provides configuration for the discovery server.
type Config struct {
// CloudClients is an interface for retrieving cloud clients.
Expand Down Expand Up @@ -166,17 +183,17 @@ type Server struct {
// ec2Watcher periodically retrieves EC2 instances.
ec2Watcher *server.Watcher
// ec2Installer is used to start the installation process on discovered EC2 nodes
ec2Installer *server.SSMInstaller
ec2Installer ssmInstaller
// azureWatcher periodically retrieves Azure virtual machines.
azureWatcher *server.Watcher
// azureInstaller is used to start the installation process on discovered Azure
// virtual machines.
azureInstaller *server.AzureInstaller
azureInstaller azureInstaller
// gcpWatcher periodically retrieves GCP virtual machines.
gcpWatcher *server.Watcher
// gcpInstaller is used to start the installation process on discovered GCP
// virtual machines
gcpInstaller *server.GCPInstaller
gcpInstaller gcpInstaller
// kubeFetchers holds all kubernetes fetchers for Azure and other clouds.
kubeFetchers []common.Fetcher
// kubeAppsFetchers holds all kubernetes fetchers for apps.
Expand Down Expand Up @@ -249,9 +266,12 @@ func (s *Server) initAWSWatchers(matchers []types.AWSMatcher) error {
return trace.Wrap(err)
}

s.ec2Installer = server.NewSSMInstaller(server.SSMInstallerConfig{
Emitter: s.Emitter,
})
if s.ec2Installer == nil {
s.ec2Installer = server.NewSSMInstaller(server.SSMInstallerConfig{
Emitter: s.Emitter,
})
}

lr, err := newLabelReconciler(&labelReconcilerConfig{
log: s.Log,
accessPoint: s.AccessPoint,
Expand Down Expand Up @@ -358,8 +378,10 @@ func (s *Server) initAzureWatchers(ctx context.Context, matchers []types.AzureMa
if err != nil {
return trace.Wrap(err)
}
s.azureInstaller = &server.AzureInstaller{
Emitter: s.Emitter,
if s.azureInstaller == nil {
s.azureInstaller = &server.AzureInstaller{
Emitter: s.Emitter,
}
}
}

Expand Down Expand Up @@ -424,8 +446,10 @@ func (s *Server) initGCPWatchers(ctx context.Context, matchers []types.GCPMatche
if err != nil {
return trace.Wrap(err)
}
s.gcpInstaller = &server.GCPInstaller{
Emitter: s.Emitter,
if s.gcpInstaller == nil {
s.gcpInstaller = &server.GCPInstaller{
Emitter: s.Emitter,
}
}
}

Expand Down
Loading

0 comments on commit 2e36d23

Please sign in to comment.