Skip to content
Draft
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
31 changes: 31 additions & 0 deletions cmd/lk/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ var (
Hidden: true,
}

agentsURLFlag = &cli.StringFlag{
Name: "agents-url",
Usage: "Override cloud-agents URL (bypasses automatic URL resolution)",
Hidden: true,
Sources: cli.EnvVars("LK_AGENTS_URL"),
}

AgentCommands = []*cli.Command{
{
Name: "agent",
Expand Down Expand Up @@ -167,6 +174,7 @@ var (
silentFlag,
regionFlag,
skipSDKCheckFlag,
agentsURLFlag,
},
// NOTE: since secrets may contain commas, or indeed any special character we might want to treat as a flag separator,
// we disable it entirely here and require multiple --secrets flags to be used.
Expand All @@ -186,6 +194,7 @@ var (
Required: false,
Value: false,
},
agentsURLFlag,
},
ArgsUsage: "[working-dir]",
},
Expand All @@ -196,6 +205,7 @@ var (
Action: createAgentConfig,
Flags: []cli.Flag{
idFlag(false),
agentsURLFlag,
},
ArgsUsage: "[working-dir]",
},
Expand All @@ -211,6 +221,7 @@ var (
silentFlag,
ignoreEmptySecretsFlag,
skipSDKCheckFlag,
agentsURLFlag,
},
// NOTE: since secrets may contain commas, or indeed any special character we might want to treat as a flag separator,
// we disable it entirely here and require multiple --secrets flags to be used.
Expand All @@ -224,6 +235,7 @@ var (
Action: getAgentStatus,
Flags: []cli.Flag{
idFlag(false),
agentsURLFlag,
},
ArgsUsage: "[working-dir]",
},
Expand All @@ -237,6 +249,7 @@ var (
secretsFileFlag,
secretsMountFlag,
ignoreEmptySecretsFlag,
agentsURLFlag,
},
// NOTE: since secrets may contain commas, or indeed any special character we might want to treat as a flag separator,
// we disable it entirely here and require multiple --secrets flags to be used.
Expand All @@ -250,6 +263,7 @@ var (
Action: restartAgent,
Flags: []cli.Flag{
idFlag(false),
agentsURLFlag,
},
ArgsUsage: "[working-dir]",
},
Expand All @@ -266,6 +280,7 @@ var (
Required: true,
},
idFlag(false),
agentsURLFlag,
},
ArgsUsage: "[working-dir]",
},
Expand All @@ -278,6 +293,7 @@ var (
Flags: []cli.Flag{
idFlag(false),
logTypeFlag,
agentsURLFlag,
},
ArgsUsage: "[working-dir]",
},
Expand All @@ -290,6 +306,7 @@ var (
Flags: []cli.Flag{
silentFlag,
idFlag(false),
agentsURLFlag,
},
ArgsUsage: "[working-dir]",
},
Expand All @@ -300,6 +317,7 @@ var (
Action: listAgentVersions,
Flags: []cli.Flag{
idFlag(false),
agentsURLFlag,
},
ArgsUsage: "[working-dir]",
},
Expand All @@ -310,6 +328,7 @@ var (
Before: createAgentClient,
Flags: []cli.Flag{
idSliceFlag,
agentsURLFlag,
},
},
{
Expand All @@ -319,6 +338,7 @@ var (
Action: listAgentSecrets,
Flags: []cli.Flag{
idFlag(false),
agentsURLFlag,
},
ArgsUsage: "[working-dir]",
},
Expand All @@ -339,6 +359,7 @@ var (
Required: false,
Value: false,
},
agentsURLFlag,
},
// NOTE: since secrets may contain commas, or indeed any special character we might want to treat as a flag separator,
// we disable it entirely here and require multiple --secrets flags to be used.
Expand Down Expand Up @@ -389,6 +410,16 @@ func createAgentClientWithOpts(ctx context.Context, cmd *cli.Command, opts ...lo
}
}

// Priority for agents URL:
// 1. --agents-url flag (explicit override)
// 2. agents_url from livekit.toml (configured for managed deployments)
// 3. Default URL derived from project (handled by SDK)
if agentsURL := cmd.String("agents-url"); agentsURL != "" {
os.Setenv("LK_AGENTS_URL", agentsURL)
} else if configExists && lkConfig.Agent != nil && lkConfig.Agent.AgentsURL != "" {
os.Setenv("LK_AGENTS_URL", lkConfig.Agent.AgentsURL)
}

agentsClient, err = cloudagents.New(cloudagents.WithProject(project.URL, project.APIKey, project.APISecret))
if err != nil {
return ctx, err
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/livekit.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ type LiveKitTOMLProjectConfig struct {
}

type LiveKitTOMLAgentConfig struct {
ID string `toml:"id"`
ID string `toml:"id"`
AgentsURL string `toml:"agents_url,omitempty"`
}

func NewLiveKitTOML(forSubdomain string) *LiveKitTOML {
Expand Down
Loading