From 4f3ce7077962f2a96d4d3f2ccfca280b372ff3c5 Mon Sep 17 00:00:00 2001 From: Britt Gresham Date: Fri, 9 Sep 2022 18:13:23 +0000 Subject: [PATCH] core/cli: Update profile set to use defaults on init only This commit modifies `runner profile set` to use profile defaults only when setting up an initial profile instead of resetting the profile to defaults when updating an existing profile. --- internal/cli/runner_profile_set.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/internal/cli/runner_profile_set.go b/internal/cli/runner_profile_set.go index dd13c945afc..268162b1f17 100644 --- a/internal/cli/runner_profile_set.go +++ b/internal/cli/runner_profile_set.go @@ -123,7 +123,7 @@ func (c *RunnerProfileSetCommand) Run(args []string) int { }, }, } - } else { + } else if od.TargetRunner == nil || c.flagTargetRunnerId == "*" { od.TargetRunner = &pb.Ref_Runner{Target: &pb.Ref_Runner_Any{}} } @@ -188,8 +188,9 @@ func (c *RunnerProfileSetCommand) Run(args []string) int { } } - od.OciUrl = c.flagOCIUrl - od.EnvironmentVariables = map[string]string{} + if od.OciUrl == "" || c.flagOCIUrl != installutil.DefaultRunnerImage { + od.OciUrl = c.flagOCIUrl + } if c.flagDefault != nil { od.Default = *c.flagDefault } @@ -206,11 +207,20 @@ func (c *RunnerProfileSetCommand) Run(args []string) int { od.EnvironmentVariables[kv[:idx]] = kv[idx+1:] } } - } else { - od.EnvironmentVariables = c.flagEnvVar + } + if c.flagEnvVar != nil { + fmt.Printf("envvar: %#v", c.flagEnvVar) + for k, v := range c.flagEnvVar { + if v == "" { + delete(od.EnvironmentVariables, k) + } else { + od.EnvironmentVariables[k] = v + } + } + //od.EnvironmentVariables = c.flagEnvVar } - if c.flagPluginType == "" { + if od.PluginType == "" && c.flagPluginType == "" { c.ui.Output( "Flag '-plugin-type' must be set to a valid plugin type like 'docker' or 'kubernetes'.\n\n%s", c.Help(), @@ -218,8 +228,10 @@ func (c *RunnerProfileSetCommand) Run(args []string) int { ) return 1 } + if c.flagPluginType != "" { + od.PluginType = c.flagPluginType + } - od.PluginType = c.flagPluginType // Upsert _, err := c.project.Client().UpsertOnDemandRunnerConfig(ctx, &pb.UpsertOnDemandRunnerConfigRequest{