Skip to content
Merged
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
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249
github.com/oklog/run v1.1.0
github.com/panta/machineid v1.0.2
github.com/signadot/go-sdk v0.3.8-0.20260402222445-b8b5bc1f40c0
github.com/signadot/go-sdk v0.3.8-0.20260409131400-73b58199c972
github.com/signadot/libconnect v0.1.1-0.20260224205539-f894c2d0a57e
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.11.0
Expand Down Expand Up @@ -146,13 +146,13 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
go.opentelemetry.io/otel v1.42.0 // indirect
go.opentelemetry.io/otel/metric v1.42.0 // indirect
go.opentelemetry.io/otel/trace v1.42.0 // indirect
go.opentelemetry.io/otel v1.43.0 // indirect
go.opentelemetry.io/otel/metric v1.43.0 // indirect
go.opentelemetry.io/otel/trace v1.43.0 // indirect
golang.org/x/crypto v0.49.0 // indirect
golang.org/x/oauth2 v0.32.0 // indirect
golang.org/x/sys v0.42.0 // indirect
golang.org/x/text v0.35.0 // indirect
golang.org/x/text v0.36.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/signadot/go-sdk v0.3.8-0.20260402222445-b8b5bc1f40c0 h1:CpkTVrKonGpInT2p5p1cWihob4Nh1rYM52CrTqQS+sI=
github.com/signadot/go-sdk v0.3.8-0.20260402222445-b8b5bc1f40c0/go.mod h1:2+pvoCGoDDO+iPUmUuU2BjYHByHp3IDQ9k3o0liibb4=
github.com/signadot/go-sdk v0.3.8-0.20260409131400-73b58199c972 h1:wnTmmIpMSPw8QDCuAKPRivdUka/I5J7efoApozXpmog=
github.com/signadot/go-sdk v0.3.8-0.20260409131400-73b58199c972/go.mod h1:hb509KxoXFyiH5CZzNMJdX3x0CO1pg8bKGu25Nw47/k=
github.com/signadot/libconnect v0.1.1-0.20260224205539-f894c2d0a57e h1:NiYn5S3cMIhsGh3RzBgRg9NzLDG5qEP7uhSJKtwW7oc=
github.com/signadot/libconnect v0.1.1-0.20260224205539-f894c2d0a57e/go.mod h1:cAsgAummH9Q9DrLQ7+S3mqrBv/+ZYKVSEXjR/WfoUJM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
Expand Down Expand Up @@ -484,16 +484,16 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.42.0 h1:lSQGzTgVR3+sgJDAU/7/ZMjN9Z+vUip7leaqBKy4sho=
go.opentelemetry.io/otel v1.42.0/go.mod h1:lJNsdRMxCUIWuMlVJWzecSMuNjE7dOYyWlqOXWkdqCc=
go.opentelemetry.io/otel/metric v1.42.0 h1:2jXG+3oZLNXEPfNmnpxKDeZsFI5o4J+nz6xUlaFdF/4=
go.opentelemetry.io/otel/metric v1.42.0/go.mod h1:RlUN/7vTU7Ao/diDkEpQpnz3/92J9ko05BIwxYa2SSI=
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
go.opentelemetry.io/otel/sdk v1.41.0 h1:YPIEXKmiAwkGl3Gu1huk1aYWwtpRLeskpV+wPisxBp8=
go.opentelemetry.io/otel/sdk v1.41.0/go.mod h1:ahFdU0G5y8IxglBf0QBJXgSe7agzjE4GiTJ6HT9ud90=
go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM=
go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA=
go.opentelemetry.io/otel/trace v1.42.0 h1:OUCgIPt+mzOnaUTpOQcBiM/PLQ/Op7oq6g4LenLmOYY=
go.opentelemetry.io/otel/trace v1.42.0/go.mod h1:f3K9S+IFqnumBkKhRJMeaZeNk9epyhnCmQh/EysQCdc=
go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
Expand Down Expand Up @@ -666,8 +666,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -722,8 +722,8 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s=
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
95 changes: 81 additions & 14 deletions internal/command/plan/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
sdkclient "github.com/signadot/go-sdk/client"
planlogs "github.com/signadot/go-sdk/client/plan_execution_logs"
planexecs "github.com/signadot/go-sdk/client/plan_executions"
sdkplans "github.com/signadot/go-sdk/client/plans"
plantags "github.com/signadot/go-sdk/client/plan_tags"
"github.com/signadot/go-sdk/models"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -59,19 +60,30 @@ func runPlan(cfg *config.PlanRun, out, log io.Writer, args []string) error {
return err
}

// Resolve plan ID.
planID, err := resolvePlanID(cfg, args)
// Resolve and fetch plan.
plan, err := resolvePlan(ctx, cfg, args)
if err != nil {
return err
}
planID := plan.ID
planSpec := plan.Spec

// Build params.
params := buildParams(cfg.Params)
if params == nil && (cfg.Sandbox != "" || cfg.RouteGroup != "") {
params = make(map[string]any)
}

// Apply --sandbox / --route-group to params.
if err := applyRoutingFlags(cfg, planSpec, params); err != nil {
return err
}

// Create execution.
spec := &models.PlanExecutionSpec{
PlanID: planID,
Params: params,
PlanID: planID,
Cluster: cfg.Cluster,
Params: params,
}
createParams := planexecs.NewCreatePlanExecutionParams().
WithContext(ctx).
Expand Down Expand Up @@ -149,27 +161,38 @@ func runPlan(cfg *config.PlanRun, out, log io.Writer, args []string) error {
return nil
}

func resolvePlanID(cfg *config.PlanRun, args []string) (string, error) {
func resolvePlan(ctx context.Context, cfg *config.PlanRun, args []string) (*models.RunnablePlan, error) {
if cfg.Tag != "" && len(args) > 0 {
return "", fmt.Errorf("specify either a plan ID argument or --tag, not both")
return nil, fmt.Errorf("specify either a plan ID argument or --tag, not both")
}
if cfg.Tag == "" && len(args) == 0 {
return "", fmt.Errorf("specify a plan ID argument or --tag")
return nil, fmt.Errorf("specify a plan ID argument or --tag")
}

if cfg.Tag != "" {
params := plantags.NewGetPlanTagParams().
tagParams := plantags.NewGetPlanTagParams().
WithContext(ctx).
WithOrgName(cfg.Org).
WithPlanTagName(cfg.Tag)
resp, err := cfg.Client.PlanTags.GetPlanTag(params, nil)
resp, err := cfg.Client.PlanTags.GetPlanTag(tagParams, nil)
if err != nil {
return "", fmt.Errorf("resolving tag %q: %w", cfg.Tag, err)
return nil, fmt.Errorf("resolving tag %q: %w", cfg.Tag, err)
}
if resp.Payload.Spec == nil || resp.Payload.Spec.PlanID == "" {
return "", fmt.Errorf("tag %q has no plan ID", cfg.Tag)
if resp.Payload.Plan == nil {
return nil, fmt.Errorf("tag %q has no plan", cfg.Tag)
}
return resp.Payload.Spec.PlanID, nil
return resp.Payload.Plan, nil
}
return args[0], nil

getParams := sdkplans.NewGetPlanParams().
WithContext(ctx).
WithOrgName(cfg.Org).
WithPlanID(args[0])
resp, err := cfg.Client.Plans.GetPlan(getParams, nil)
if err != nil {
return nil, fmt.Errorf("fetching plan: %w", err)
}
return resp.Payload, nil
}

func buildParams(tplVals config.TemplateVals) map[string]any {
Expand Down Expand Up @@ -212,6 +235,50 @@ func looksLikeJSON(s string) bool {
return false
}

func applyRoutingFlags(cfg *config.PlanRun, planSpec *models.PlanSpec, params map[string]any) error {
if cfg.Sandbox == "" && cfg.RouteGroup == "" {
return nil
}

aff := planSpec.Cluster
if aff == nil {
if cfg.Sandbox != "" {
return fmt.Errorf("plan does not accept a sandbox parameter")
}
return fmt.Errorf("plan does not accept a route group parameter")
}

if cfg.Sandbox != "" {
if aff.FromAnyTarget != "" {
raw, err := json.Marshal(models.RoutingTarget{Sandbox: cfg.Sandbox})
if err != nil {
return fmt.Errorf("marshalling routing target: %w", err)
}
params[aff.FromAnyTarget] = json.RawMessage(raw)
} else if aff.FromSandbox != "" {
params[aff.FromSandbox] = cfg.Sandbox
} else {
return fmt.Errorf("plan does not accept a sandbox parameter")
}
}

if cfg.RouteGroup != "" {
if aff.FromAnyTarget != "" {
raw, err := json.Marshal(models.RoutingTarget{RouteGroup: cfg.RouteGroup})
if err != nil {
return fmt.Errorf("marshalling routing target: %w", err)
}
params[aff.FromAnyTarget] = json.RawMessage(raw)
} else if aff.FromRouteGroup != "" {
params[aff.FromRouteGroup] = cfg.RouteGroup
} else {
return fmt.Errorf("plan does not accept a route group parameter")
}
}

return nil
}

func isTerminal(phase models.PlansExecutionPhase) bool {
switch phase {
case models.PlansExecutionPhaseCompleted,
Expand Down
13 changes: 10 additions & 3 deletions internal/config/planrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ type PlanRun struct {
*Plan

// Flags
Tag string
Params TemplateVals
Wait bool
Tag string
Cluster string
Sandbox string
RouteGroup string
Params TemplateVals
Wait bool
Attach bool
Timeout time.Duration
OutputDir string
}

func (c *PlanRun) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&c.Tag, "tag", "", "run the plan referenced by this tag (alternative to plan ID argument)")
cmd.Flags().StringVar(&c.Cluster, "cluster", "", "target cluster for the execution")
cmd.Flags().StringVar(&c.Sandbox, "sandbox", "", "run in the context of a sandbox")
cmd.Flags().StringVar(&c.RouteGroup, "route-group", "", "run in the context of a route group")
cmd.MarkFlagsMutuallyExclusive("sandbox", "route-group")
cmd.Flags().Var(&c.Params, "param", "parameter in key=value form (can be repeated)")
cmd.Flags().BoolVar(&c.Wait, "wait", true, "wait for execution to complete")
cmd.Flags().BoolVar(&c.Attach, "attach", false, "stream structured events (logs, outputs, result) to stdout")
Expand Down