Skip to content

Commit 772d51a

Browse files
committed
Rename --mode to --runner, and update the README
Tool: gitpod/catfood.gitpod.cloud
1 parent d54e72f commit 772d51a

File tree

4 files changed

+116
-99
lines changed

4 files changed

+116
-99
lines changed

gitpod-network-check/README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ A CLI to check if your network setup is suitable for the installation of Gitpod.
5555

5656
2. Run the network diagnosis
5757

58-
The tool supports different modes for running the checks, specified by the `--mode` flag (`ec2`, `lambda`, `local`).
58+
The tool supports different runners for executing the checks, specified by the `--runner` flag (`ec2`, `lambda`, `local`).
5959

60-
**Using EC2 Mode (Default):**
60+
**Using EC2 Runner (Default):**
6161

6262
This mode launches temporary EC2 instances in your specified subnets to perform the network checks. This most closely simulates the environment where Gitpod components will run.
6363

64-
To start the diagnosis using EC2 mode: `./gitpod-network-check diagnose --mode ec2` (or simply `./gitpod-network-check diagnose` as EC2 is the default).
64+
To start the diagnosis using the EC2 runner: `./gitpod-network-check diagnose --runner ec2` (or simply `./gitpod-network-check diagnose` as EC2 is the default).
6565

6666
```console
67-
# Example output for EC2 mode
68-
./gitpod-network-check diagnose --mode ec2
67+
# Example output for EC2 runner
68+
./gitpod-network-check diagnose --runner ec2
6969
INFO[0000] ℹ️ Running with region `eu-central-1`, main subnet `[subnet-0ed211f14362b224f subnet-041703e62a05d2024]`, pod subnet `[subnet-075c44edead3b062f subnet-06eb311c6b92e0f29]`, hosts `[accounts.google.com https://github.com]`, ami ``, and API endpoint ``
7070
INFO[0000] ✅ Main Subnets are valid
7171
INFO[0000] ✅ Pod Subnets are valid
@@ -127,47 +127,47 @@ A CLI to check if your network setup is suitable for the installation of Gitpod.
127127
INFO[0306] ✅ Security group 'sg-00d4a66a7840ebd67' deleted
128128
```
129129

130-
**Using Lambda Mode:**
130+
**Using Lambda Runner:**
131131

132132
This mode uses AWS Lambda functions deployed into your specified subnets to perform the network checks. It avoids the need to launch full EC2 instances but has its own prerequisites.
133133

134134
* **Prerequisites for Lambda Mode:**
135135
* **IAM Permissions:** The AWS credentials used to run `gitpod-network-check` need permissions to manage Lambda functions, IAM roles, security groups, and CloudWatch Logs. Specifically, it needs to perform actions like: `lambda:CreateFunction`, `lambda:GetFunction`, `lambda:DeleteFunction`, `lambda:InvokeFunction`, `iam:CreateRole`, `iam:GetRole`, `iam:DeleteRole`, `iam:AttachRolePolicy`, `iam:DetachRolePolicy`, `ec2:CreateSecurityGroup`, `ec2:DescribeSecurityGroups`, `ec2:DeleteSecurityGroup`, `ec2:AuthorizeSecurityGroupEgress`, `ec2:DescribeSubnets`, `logs:DeleteLogGroup`.
136136
* **Network Connectivity:** Lambda functions running within a VPC need a route to the internet or required AWS service endpoints. This typically requires a **NAT Gateway** in your VPC or **VPC Endpoints** for all necessary services (e.g., STS, CloudWatch Logs, ECR, S3, DynamoDB, and any target HTTPS hosts). Without proper outbound connectivity, the Lambda checks will fail.
137137

138-
* **Running Lambda Mode:**
139-
To start the diagnosis using Lambda mode:
138+
* **Running Lambda Runner:**
139+
To start the diagnosis using the Lambda runner:
140140
```bash
141-
./gitpod-network-check diagnose --mode lambda
141+
./gitpod-network-check diagnose --runner lambda
142142
```
143143

144-
* **Using Existing Resources (Lambda Mode):**
144+
* **Using Existing Resources (Lambda Runner):**
145145
If you have pre-existing IAM roles or Security Groups you want the Lambda functions to use, you can specify them using flags. This will prevent the tool from creating or deleting these specific resources.
146146
```bash
147-
./gitpod-network-check diagnose --mode lambda \
147+
./gitpod-network-check diagnose --runner lambda \
148148
--lambda-role-arn arn:aws:iam::123456789012:role/MyExistingLambdaRole \
149149
--lambda-sg-id sg-0123456789abcdef0
150150
```
151151

152-
* **Example Output (Lambda Mode):**
153-
The output will be similar to EC2 mode but will show Lambda function creation/invocation instead of EC2 instance management.
152+
* **Example Output (Lambda Runner):**
153+
The output will be similar to EC2 runner but will show Lambda function creation/invocation instead of EC2 instance management.
154154

155-
**Using Local Mode:**
155+
**Using Local Runner:**
156156

157157
This mode runs the checks directly from the machine where you execute the CLI. It's useful for basic outbound connectivity tests but **does not** accurately reflect the network environment within your AWS subnets.
158158
159-
To start the diagnosis using local mode: `./gitpod-network-check diagnose --mode local`
159+
To start the diagnosis using the local runner: `./gitpod-network-check diagnose --runner local`
160160
161161
3. Clean up after network diagnosis
162162
163-
The `diagnose` command is designed to clean up the AWS resources it creates (EC2 instances, Lambda functions, IAM roles, Security Groups, CloudWatch Log groups) before it finishes. However, if the process terminates unexpectedly, you can manually trigger cleanup using the `clean` command. This command respects the `--mode` flag to clean up resources specific to that mode.
163+
The `diagnose` command is designed to clean up the AWS resources it creates (EC2 instances, Lambda functions, IAM roles, Security Groups, CloudWatch Log groups) before it finishes. However, if the process terminates unexpectedly, you can manually trigger cleanup using the `clean` command. This command respects the `--runner` flag to clean up resources specific to that runner.
164164
165165
```bash
166-
# Clean up resources potentially left by EC2 mode
167-
./gitpod-network-check clean --mode ec2
166+
# Clean up resources potentially left by the EC2 runner
167+
./gitpod-network-check clean --runner ec2
168168
169-
# Clean up resources potentially left by Lambda mode
170-
./gitpod-network-check clean --mode lambda
169+
# Clean up resources potentially left by the Lambda runner
170+
./gitpod-network-check clean --runner lambda
171171
```
172172
173173
**Note:** The `clean` command will *not* delete IAM roles or Security Groups if they were provided using the `--lambda-role-arn` or `--lambda-sg-id` flags during the `diagnose` run.

gitpod-network-check/cmd/root.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ var Flags = struct {
2424
// Variable to store the testsets flag value
2525
SelectedTestsets []string
2626

27-
// Variable to store the mode flag value
28-
ModeVar string
27+
// Variable to store the runner flag value
28+
RunnerTypeStr string
2929

30-
Mode runner.Mode
30+
RunnerType runner.RunnerType
3131
}{}
3232

3333
// NetworkCheckCmd is the root command for the application
@@ -52,20 +52,20 @@ func preRunE(cmd *cobra.Command, args []string) error {
5252
log.Infof("ℹ️ Running with region `%s`, main subnet `%v`, pod subnet `%v`, hosts `%v`, ami `%v`, and API endpoint `%v`", NetworkConfig.AwsRegion, NetworkConfig.MainSubnets, NetworkConfig.PodSubnets, NetworkConfig.HttpsHosts, NetworkConfig.InstanceAMI, NetworkConfig.ApiEndpoint)
5353

5454
// validate the config
55-
err = validateSubnets(cmd, args)
55+
err = validateSubnetsConfig(cmd, args)
5656
if err != nil {
5757
return fmt.Errorf("❌ incorrect subnets: %v", err)
5858
}
5959

60-
err = validateMode(cmd, args)
60+
err = validateRunnerFlag(cmd, args)
6161
if err != nil {
62-
return fmt.Errorf("❌ incorrect mode: %v", err)
62+
return fmt.Errorf("❌ incorrect runner: %v", err) // Update error message context
6363
}
6464

6565
return nil
6666
}
6767

68-
func validateSubnets(cmd *cobra.Command, args []string) error {
68+
func validateSubnetsConfig(cmd *cobra.Command, args []string) error {
6969
if len(NetworkConfig.MainSubnets) < 1 {
7070
return fmt.Errorf("At least one Main subnet needs to be specified: %v", NetworkConfig.MainSubnets)
7171
}
@@ -78,13 +78,13 @@ func validateSubnets(cmd *cobra.Command, args []string) error {
7878
return nil
7979
}
8080

81-
func validateMode(cmd *cobra.Command, args []string) error {
82-
// Validate mode
83-
mode, err := runner.VaildateMode(Flags.ModeVar)
81+
func validateRunnerFlag(cmd *cobra.Command, args []string) error {
82+
// Validate runnerType
83+
runnerType, err := runner.ValidateRunnerType(Flags.RunnerTypeStr)
8484
if err != nil {
8585
return err
8686
}
87-
Flags.Mode = mode
87+
Flags.RunnerType = runnerType
8888

8989
return nil
9090
}
@@ -132,15 +132,15 @@ func init() {
132132
NetworkCheckCmd.PersistentFlags().StringVar(&NetworkConfig.InstanceAMI, "instance-ami", "", "Custom ec2 instance AMI id, if not set will use latest ubuntu")
133133
NetworkCheckCmd.PersistentFlags().StringVar(&NetworkConfig.ApiEndpoint, "api-endpoint", "", "The Gitpod Enterprise control plane's regional API endpoint subdomain")
134134
NetworkCheckCmd.PersistentFlags().StringSliceVar(&Flags.SelectedTestsets, "testsets", []string{"aws-services-pod-subnet", "aws-services-main-subnet", "https-hosts-main-subnet"}, "List of testsets to run (options: aws-services-pod-subnet, aws-services-main-subnet, https-hosts-main-subnet)")
135-
NetworkCheckCmd.PersistentFlags().StringVar(&Flags.ModeVar, "mode", string(runner.ModeEC2), fmt.Sprintf("How to run the tests (default: %s, options: %s, %s, %s)", runner.ModeEC2, runner.ModeEC2, runner.ModeLambda, runner.ModeLocal))
135+
// Rename flag, variable, and update help text
136+
NetworkCheckCmd.PersistentFlags().StringVar(&Flags.RunnerTypeStr, "runner", string(runner.RunnerTypeEC2), fmt.Sprintf("Specify the runner for executing tests (default: %s, options: %s, %s, %s)", runner.RunnerTypeEC2, runner.RunnerTypeEC2, runner.RunnerTypeLambda, runner.RunnerTypeLocal))
136137
// Lambda-specific flags
137138
NetworkCheckCmd.PersistentFlags().StringVar(&NetworkConfig.LambdaRoleArn, "lambda-role-arn", "", "ARN of an existing IAM role to use for Lambda execution (overrides automatic creation/deletion)")
138139
NetworkCheckCmd.PersistentFlags().StringVar(&NetworkConfig.LambdaSecurityGroupID, "lambda-sg-id", "", "ID of an existing Security Group to use for Lambda execution (overrides automatic creation/deletion)")
139140

140141
bindFlags(NetworkCheckCmd, v)
141142
}
142143

143-
144144
func readConfigFile() *viper.Viper {
145145
v := viper.New()
146146
if NetworkConfig.CfgFile != "" {

gitpod-network-check/pkg/runner/common.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ import (
1414
"github.com/gitpod-io/enterprise-deployment-toolkit/gitpod-network-check/pkg/checks"
1515
)
1616

17-
type Mode string
17+
type RunnerType string
1818

1919
const (
20-
ModeEC2 Mode = "ec2"
21-
ModeLambda Mode = "lambda"
22-
ModeLocal Mode = "local"
20+
RunnerTypeEC2 RunnerType = "ec2"
21+
RunnerTypeLambda RunnerType = "lambda"
22+
RunnerTypeLocal RunnerType = "local"
2323
)
2424

25-
var validModes = map[string]bool{
26-
string(ModeLambda): true,
27-
string(ModeEC2): true,
28-
string(ModeLocal): true,
25+
var validRunnerType = map[string]bool{
26+
string(RunnerTypeLambda): true,
27+
string(RunnerTypeEC2): true,
28+
string(RunnerTypeLocal): true,
2929
}
3030

31-
func VaildateMode(modeStr string) (Mode, error) {
32-
if _, ok := validModes[modeStr]; ok {
33-
return Mode(modeStr), nil
31+
func ValidateRunnerType(runnerStr string) (RunnerType, error) {
32+
if _, ok := validRunnerType[runnerStr]; ok {
33+
return RunnerType(runnerStr), nil
3434
}
35-
return "", fmt.Errorf("invalid mode: %s, must be one of: %v", modeStr, slices.Collect(maps.Keys(validModes)))
35+
return "", fmt.Errorf("invalid runner: %s, must be one of: %v", runnerStr, slices.Collect(maps.Keys(validRunnerType)))
3636
}
3737

3838
type TestRunner interface {
@@ -41,32 +41,34 @@ type TestRunner interface {
4141
Cleanup(ctx context.Context) error
4242
}
4343

44-
func NewRunner(ctx context.Context, mode Mode, config *checks.NetworkConfig) (TestRunner, error) {
44+
func NewRunner(ctx context.Context, mode RunnerType, config *checks.NetworkConfig) (TestRunner, error) {
4545
switch mode {
46-
case ModeEC2:
46+
case RunnerTypeEC2:
4747
return NewEC2TestRunner(context.Background(), config)
48-
case ModeLocal:
48+
case RunnerTypeLocal:
4949
return NewLocalTestRunner(), nil
50-
case ModeLambda:
50+
case RunnerTypeLambda:
5151
return NewLambdaTestRunner(ctx, config)
5252
default:
53-
return nil, fmt.Errorf("invalid mode: %s, must be one of: %v", mode, slices.Collect(maps.Keys(validModes)))
53+
// Update error message
54+
return nil, fmt.Errorf("invalid runner: %s, must be one of: %v", mode, slices.Collect(maps.Keys(validRunnerType)))
5455
}
5556
}
5657

5758
// Creates a new TestRunner instance, loading existing resources from the AWS account by known name/tags.
5859
// This is useful for cleaning up left-over resources from previous runs.
59-
func LoadRunnerFromTags(ctx context.Context, mode Mode, networkConfig *checks.NetworkConfig) (TestRunner, error) {
60+
func LoadRunnerFromTags(ctx context.Context, mode RunnerType, networkConfig *checks.NetworkConfig) (TestRunner, error) {
6061
switch mode {
61-
case ModeEC2:
62+
case RunnerTypeEC2:
6263
return LoadEC2RunnerFromTags(ctx, networkConfig)
63-
case ModeLambda:
64+
case RunnerTypeLambda:
6465
return LoadLambdaRunnerFromTags(ctx, networkConfig) // Call the new function
65-
case ModeLocal:
66+
case RunnerTypeLocal:
6667
// Local mode does not require any AWS resources, so we can just return a new instance.
6768
return NewLocalTestRunner(), nil
6869
default:
69-
return nil, fmt.Errorf("invalid mode: %s, must be one of: %v", mode, slices.Collect(maps.Keys(validModes)))
70+
// Update error message
71+
return nil, fmt.Errorf("invalid runner: %s, must be one of: %v", mode, slices.Collect(maps.Keys(validRunnerType)))
7072
}
7173
}
7274

0 commit comments

Comments
 (0)