Skip to content
Merged
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
37 changes: 31 additions & 6 deletions cmd/lk/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ var (
Required: false,
}

regionFlag = &cli.StringSliceFlag{
Name: "regions",
Usage: "Region(s) to deploy the agent to. If unset, will deploy to the nearest region.",
regionFlag = &cli.StringFlag{
Name: "region",
Usage: "Region to deploy the agent to. If unset, will deploy to the nearest region.",
Required: false,
Hidden: true,
}

skipSDKCheckFlag = &cli.BoolFlag{
Expand Down Expand Up @@ -141,7 +140,9 @@ var (
},
}},
}},
Flags: []cli.Flag{},
Flags: []cli.Flag{
regionFlag,
},
ArgsUsage: "[AGENT-NAME]",
DisableSliceFlagSeparator: true,
},
Expand Down Expand Up @@ -554,7 +555,31 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
}
}

regions := cmd.StringSlice("regions")
region := cmd.String("region")
if region == "" {
availableRegionsStr, ok := settingsMap["available_regions"]
if ok && availableRegionsStr != "" {
regionOptions := strings.Split(availableRegionsStr, ",")
for i, r := range regionOptions {
regionOptions[i] = strings.TrimSpace(r)
}

if err := huh.NewSelect[string]().
Title("Select region for agent deployment").
Options(huh.NewOptions(regionOptions...)...).
Value(&region).
WithTheme(util.Theme).
Run(); err != nil {
return err
}
} else {
// we shouldn't ever get here, but if we do, just default to us-east
logger.Debugw("no available regions found, defaulting to us-east. please contact LiveKit support if this is unexpected.")
region = "us-east"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't default region be empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm i wasn't sure here. if it's empty then whichever region picks it up based on dns of the api call would deploy it. not sure if that is better or to use us-east

}
}

regions := []string{region}
excludeFiles := []string{fmt.Sprintf("**/%s", config.LiveKitTOMLFile)}
resp, err := agentsClient.CreateAgent(ctx, os.DirFS(workingDir), secrets, regions, excludeFiles)
if err != nil {
Expand Down
Loading