in cmd/e2e-test/sweeper/sweeper.go [56:98]
func (s *SweeperCommand) Run(log *zap.Logger, opts *cli.GlobalOptions) error {
ctx := context.Background()
logger := e2e.NewLogger()
if s.clusterPrefix != "" && s.clusterName != "" {
return fmt.Errorf("cannot use --cluster-prefix and --cluster-name together")
}
if s.clusterPrefix != "" && s.all {
return fmt.Errorf("cannot use --cluster-prefix and --all together")
}
if s.clusterName != "" && s.all {
return fmt.Errorf("cannot use --cluster-name and --all together")
}
if s.clusterPrefix == "" && s.clusterName == "" && !s.all {
return fmt.Errorf("either --cluster-prefix, --cluster-name, or --all must be specified")
}
aws, err := e2e.NewAWSConfig(ctx,
// We use a custom AppId so the requests show that they were
// made by this command in the user-agent
config.WithAppID("nodeadm-e2e-test-sweeper-cmd"),
)
if err != nil {
return fmt.Errorf("reading AWS configuration: %w", err)
}
sweeper := cleanup.NewSweeper(aws, logger, s.eksEndpoint)
input := cleanup.SweeperInput{
AllClusters: s.all,
ClusterNamePrefix: s.clusterPrefix,
ClusterName: s.clusterName,
InstanceAgeThreshold: s.ageThreshold,
DryRun: s.dryRun,
}
logger.Info("Cleaning up E2E cluster resources...", "configuration", input)
if err = sweeper.Run(ctx, input); err != nil {
return fmt.Errorf("error cleaning up e2e resources: %w", err)
}
logger.Info("Cleanup completed successfully!")
return nil
}