From cb93df5eb5769137b534eea12a20fd40f2b62c5d Mon Sep 17 00:00:00 2001 From: Stefan McShane Date: Wed, 20 Sep 2023 01:00:37 -0400 Subject: [PATCH 1/4] squashing --- .gitignore | 1 + cli/cmd/commands/app.go | 6 +++--- cli/cmd/commands/apply.go | 2 +- cli/cmd/commands/auth.go | 2 +- cli/cmd/commands/cluster.go | 6 +++--- cli/cmd/commands/config.go | 6 +++--- cli/cmd/commands/connect.go | 16 +++++++-------- cli/cmd/commands/create.go | 2 +- cli/cmd/commands/delete.go | 10 +++++----- cli/cmd/commands/deploy_bluegreen.go | 2 +- cli/cmd/commands/docker.go | 2 +- cli/cmd/commands/errors.go | 4 ++-- cli/cmd/commands/get.go | 4 ++-- cli/cmd/commands/helm.go | 10 +++++----- cli/cmd/commands/job.go | 8 ++++---- cli/cmd/commands/kubectl.go | 30 ++++++++++++++++++++++------ cli/cmd/commands/list.go | 8 ++++---- cli/cmd/commands/logs.go | 2 +- cli/cmd/commands/project.go | 6 +++--- cli/cmd/commands/registry.go | 8 ++++---- cli/cmd/commands/run.go | 4 ++-- cli/cmd/commands/stack.go | 4 ++-- cli/cmd/commands/update.go | 14 ++++++------- 23 files changed, 88 insertions(+), 69 deletions(-) diff --git a/.gitignore b/.gitignore index e6dea30dc3..293f4322e8 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ bin openapi.yaml .idea portercli +local vendor diff --git a/cli/cmd/commands/app.go b/cli/cmd/commands/app.go index f4fc9bd720..59a59b58af 100644 --- a/cli/cmd/commands/app.go +++ b/cli/cmd/commands/app.go @@ -152,7 +152,7 @@ func appRunFlags(appRunCmd *cobra.Command) { ) } -func appRun(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, args []string) error { +func appRun(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, args []string) error { execArgs := args[1:] color.New(color.FgGreen).Println("Attempting to run", strings.Join(execArgs, " "), "for application", args[0]) @@ -267,7 +267,7 @@ func appRun(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client a return appExecuteRunEphemeral(ctx, config, appNamespace, selectedPod.Name, selectedContainerName, execArgs) } -func appCleanup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func appCleanup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { config := &AppPorterRunSharedConfig{ Client: client, CLIConfig: cliConfig, @@ -1044,7 +1044,7 @@ func appCreateEphemeralPodFromExisting( ) } -func appUpdateTag(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, args []string) error { +func appUpdateTag(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, args []string) error { namespace := fmt.Sprintf("porter-stack-%s", args[0]) if appTag == "" { appTag = "latest" diff --git a/cli/cmd/commands/apply.go b/cli/cmd/commands/apply.go index 5c27a2ebba..3f36dc003a 100644 --- a/cli/cmd/commands/apply.go +++ b/cli/cmd/commands/apply.go @@ -108,7 +108,7 @@ applying a configuration: return applyCmd } -func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ []string) (err error) { +func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) (err error) { project, err := client.GetProject(ctx, cliConfig.Project) if err != nil { return fmt.Errorf("could not retrieve project from Porter API. Please contact support@porter.run") diff --git a/cli/cmd/commands/auth.go b/cli/cmd/commands/auth.go index 1749ad8528..85a0fe022d 100644 --- a/cli/cmd/commands/auth.go +++ b/cli/cmd/commands/auth.go @@ -281,7 +281,7 @@ func register(ctx context.Context, cliConf config.CLIConfig) error { return nil } -func logout(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func logout(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { err := client.Logout(ctx) if err != nil { if !strings.Contains(err.Error(), "You are not logged in.") { diff --git a/cli/cmd/commands/cluster.go b/cli/cmd/commands/cluster.go index 8fb78fe4af..382921a0d7 100644 --- a/cli/cmd/commands/cluster.go +++ b/cli/cmd/commands/cluster.go @@ -70,7 +70,7 @@ func registerCommand_Cluster(cliConf config.CLIConfig) *cobra.Command { return clusterCmd } -func listClusters(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listClusters(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { resp, err := client.ListProjectClusters(ctx, cliConf.Project) if err != nil { return err @@ -98,7 +98,7 @@ func listClusters(ctx context.Context, user *types.GetAuthenticatedUserResponse, return nil } -func deleteCluster(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func deleteCluster(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { userResp, err := utils.PromptPlaintext( fmt.Sprintf( `Are you sure you'd like to delete the cluster with id %s? %s `, @@ -128,7 +128,7 @@ func deleteCluster(ctx context.Context, user *types.GetAuthenticatedUserResponse return nil } -func listNamespaces(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listNamespaces(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { pID := cliConf.Project // get the service account based on the cluster id diff --git a/cli/cmd/commands/config.go b/cli/cmd/commands/config.go index 604cb67f67..a102f11302 100644 --- a/cli/cmd/commands/config.go +++ b/cli/cmd/commands/config.go @@ -186,7 +186,7 @@ func printConfig() error { return nil } -func listAndSetProject(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listAndSetProject(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) _ = s.Color("cyan") s.Suffix = " Loading list of projects" @@ -230,7 +230,7 @@ func listAndSetProject(ctx context.Context, _ *types.GetAuthenticatedUserRespons return nil } -func listAndSetCluster(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listAndSetCluster(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) _ = s.Color("cyan") s.Suffix = " Loading list of clusters" @@ -273,7 +273,7 @@ func listAndSetCluster(ctx context.Context, _ *types.GetAuthenticatedUserRespons return nil } -func listAndSetRegistry(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listAndSetRegistry(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) _ = s.Color("cyan") s.Suffix = " Loading list of registries" diff --git a/cli/cmd/commands/connect.go b/cli/cmd/commands/connect.go index 48dc3b2f6f..14f88d0f75 100644 --- a/cli/cmd/commands/connect.go +++ b/cli/cmd/commands/connect.go @@ -138,7 +138,7 @@ func registerCommand_Connect(cliConf config.CLIConfig) *cobra.Command { return connectCmd } -func runConnectKubeconfig(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func runConnectKubeconfig(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { isLocal := false if cliConf.Driver == "local" { @@ -160,7 +160,7 @@ func runConnectKubeconfig(ctx context.Context, _ *types.GetAuthenticatedUserResp return cliConf.SetCluster(id) } -func runConnectECR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func runConnectECR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { regID, err := connect.ECR( ctx, client, @@ -173,7 +173,7 @@ func runConnectECR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, c return cliConf.SetRegistry(regID) } -func runConnectGCR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func runConnectGCR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { regID, err := connect.GCR( ctx, client, @@ -186,7 +186,7 @@ func runConnectGCR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, c return cliConf.SetRegistry(regID) } -func runConnectGAR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func runConnectGAR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { regID, err := connect.GAR( ctx, client, @@ -199,7 +199,7 @@ func runConnectGAR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, c return cliConf.SetRegistry(regID) } -func runConnectDOCR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func runConnectDOCR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { regID, err := connect.DOCR( ctx, client, @@ -212,7 +212,7 @@ func runConnectDOCR(ctx context.Context, _ *types.GetAuthenticatedUserResponse, return cliConf.SetRegistry(regID) } -func runConnectDockerhub(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func runConnectDockerhub(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { regID, err := connect.Dockerhub( ctx, client, @@ -225,7 +225,7 @@ func runConnectDockerhub(ctx context.Context, _ *types.GetAuthenticatedUserRespo return cliConf.SetRegistry(regID) } -func runConnectRegistry(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func runConnectRegistry(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { regID, err := connect.Registry( ctx, client, @@ -238,7 +238,7 @@ func runConnectRegistry(ctx context.Context, _ *types.GetAuthenticatedUserRespon return cliConf.SetRegistry(regID) } -func runConnectHelmRepo(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func runConnectHelmRepo(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { hrID, err := connect.HelmRepo( ctx, client, diff --git a/cli/cmd/commands/create.go b/cli/cmd/commands/create.go index 197074df11..1f4ee5140d 100644 --- a/cli/cmd/commands/create.go +++ b/cli/cmd/commands/create.go @@ -180,7 +180,7 @@ To deploy an application from a Docker registry, use "--source registry" and pas var supportedKinds = map[string]string{"web": "", "job": "", "worker": ""} -func createFull(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func createFull(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.CreateFull(ctx) if err != nil { diff --git a/cli/cmd/commands/delete.go b/cli/cmd/commands/delete.go index ec9904ef38..ff0f202a08 100644 --- a/cli/cmd/commands/delete.go +++ b/cli/cmd/commands/delete.go @@ -113,7 +113,7 @@ deleting a configuration: return deleteCmd } -func deleteDeployment(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func deleteDeployment(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.DeleteDeployment(ctx) if err != nil { @@ -152,7 +152,7 @@ func deleteDeployment(ctx context.Context, _ *types.GetAuthenticatedUserResponse ) } -func deleteApp(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func deleteApp(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.DeleteApp(ctx) if err != nil { @@ -189,7 +189,7 @@ func deleteApp(ctx context.Context, _ *types.GetAuthenticatedUserResponse, clien return nil } -func deleteJob(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func deleteJob(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.DeleteJob(ctx) if err != nil { @@ -226,7 +226,7 @@ func deleteJob(ctx context.Context, _ *types.GetAuthenticatedUserResponse, clien return nil } -func deleteAddon(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func deleteAddon(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { name := args[0] resp, err := client.GetRelease( @@ -255,7 +255,7 @@ func deleteAddon(ctx context.Context, _ *types.GetAuthenticatedUserResponse, cli return nil } -func deleteHelm(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func deleteHelm(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { name := args[0] resp, err := client.ListHelmRepos(ctx, cliConf.Project) diff --git a/cli/cmd/commands/deploy_bluegreen.go b/cli/cmd/commands/deploy_bluegreen.go index 0563ce02fd..e3183fc2e1 100644 --- a/cli/cmd/commands/deploy_bluegreen.go +++ b/cli/cmd/commands/deploy_bluegreen.go @@ -61,7 +61,7 @@ func registerCommand_Deploy(cliConf config.CLIConfig) *cobra.Command { return deployCmd } -func bluegreenSwitch(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, args []string) error { +func bluegreenSwitch(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, args []string) error { project, err := client.GetProject(ctx, cliConfig.Project) if err != nil { return fmt.Errorf("could not retrieve project from Porter API. Please contact support@porter.run") diff --git a/cli/cmd/commands/docker.go b/cli/cmd/commands/docker.go index f71abf2887..a3496dc70a 100644 --- a/cli/cmd/commands/docker.go +++ b/cli/cmd/commands/docker.go @@ -31,6 +31,6 @@ func registerCommand_Docker(cliConf config.CLIConfig) *cobra.Command { return dockerCmd } -func dockerConfig(ctx context.Context, user *ptypes.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func dockerConfig(ctx context.Context, user *ptypes.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { return config.SetDockerConfig(ctx, client, cliConf.Project) } diff --git a/cli/cmd/commands/errors.go b/cli/cmd/commands/errors.go index 313fc601b8..75bd1f3dda 100644 --- a/cli/cmd/commands/errors.go +++ b/cli/cmd/commands/errors.go @@ -20,7 +20,7 @@ var ( ErrCannotConnect error = errors.New("Unable to connect to the Porter server.") ) -type authenticatedRunnerFunc func(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error +type authenticatedRunnerFunc func(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error func checkLoginAndRunWithConfig(cmd *cobra.Command, cliConf config.CLIConfig, args []string, runner authenticatedRunnerFunc) error { ctx := cmd.Context() @@ -65,7 +65,7 @@ func checkLoginAndRunWithConfig(cmd *cobra.Command, cliConf config.CLIConfig, ar ValidateApplyV2Enabled: project.ValidateApplyV2, } - err = runner(ctx, user, client, cliConf, flags, args) + err = runner(ctx, user, client, cliConf, flags, cmd, args) if err != nil { red := color.New(color.FgRed) diff --git a/cli/cmd/commands/get.go b/cli/cmd/commands/get.go index c6b9d89248..bc52f99b5b 100644 --- a/cli/cmd/commands/get.go +++ b/cli/cmd/commands/get.go @@ -71,7 +71,7 @@ type getReleaseInfo struct { RevisionID int `json:"revision_id" yaml:"revision_id"` } -func get(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func get(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.Get(ctx) if err != nil { @@ -118,7 +118,7 @@ func get(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api. return nil } -func getValues(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func getValues(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.GetValues(ctx) if err != nil { diff --git a/cli/cmd/commands/helm.go b/cli/cmd/commands/helm.go index 8d0155d7de..e54c942a12 100644 --- a/cli/cmd/commands/helm.go +++ b/cli/cmd/commands/helm.go @@ -27,7 +27,7 @@ func registerCommand_Helm(cliConf config.CLIConfig) *cobra.Command { return helmCmd } -func runHelm(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func runHelm(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { _, err := exec.LookPath("helm") if err != nil { return fmt.Errorf("error finding helm: %w", err) @@ -44,12 +44,12 @@ func runHelm(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client os.Setenv("KUBECONFIG", tmpFile) - cmd := exec.Command("helm", args...) + execCommand := exec.Command("helm", args...) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + execCommand.Stdout = os.Stdout + execCommand.Stderr = os.Stderr - err = cmd.Run() + err = execCommand.Run() if err != nil { return fmt.Errorf("error running helm: %w", err) diff --git a/cli/cmd/commands/job.go b/cli/cmd/commands/job.go index 78e6fb04c9..9384a51fb6 100644 --- a/cli/cmd/commands/job.go +++ b/cli/cmd/commands/job.go @@ -177,7 +177,7 @@ use the --namespace flag: return jobCmd } -func batchImageUpdate(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func batchImageUpdate(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.BatchImageUpdate(ctx) if err != nil { @@ -201,7 +201,7 @@ func batchImageUpdate(ctx context.Context, _ *types.GetAuthenticatedUserResponse } // waits for a job with a given name/namespace -func waitForJob(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func waitForJob(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.WaitForJob(ctx) if err != nil { @@ -218,7 +218,7 @@ func waitForJob(ctx context.Context, _ *types.GetAuthenticatedUserResponse, clie }) } -func runJob(ctx context.Context, authRes *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func runJob(ctx context.Context, authRes *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.RunJob(ctx) if err != nil { @@ -252,7 +252,7 @@ func runJob(ctx context.Context, authRes *types.GetAuthenticatedUserResponse, cl return fmt.Errorf("error running job: %w", err) } - err = waitForJob(ctx, authRes, client, cliConf, featureFlags, args) + err = waitForJob(ctx, authRes, client, cliConf, featureFlags, cmd, args) if err != nil { return fmt.Errorf("error waiting for job to complete: %w", err) } diff --git a/cli/cmd/commands/kubectl.go b/cli/cmd/commands/kubectl.go index 41f58eaa4a..f14a79d731 100644 --- a/cli/cmd/commands/kubectl.go +++ b/cli/cmd/commands/kubectl.go @@ -23,15 +23,22 @@ func registerCommand_Kubectl(cliConf config.CLIConfig) *cobra.Command { } }, } + var printKubeconfig bool + kubectlCmd.Flags().BoolVar(&printKubeconfig, "print-kubeconfig", false, "Print an authenticated kubeconfig to the console with a 15 minute expiry") return kubectlCmd } -func runKubectl(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func runKubectl(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { _, err := exec.LookPath("kubectl") if err != nil { return fmt.Errorf("error finding kubectl: %w", err) } + printKubeconfig, err := cmd.Flags().GetBool("print-kubeconfig") + if err != nil { + return fmt.Errorf("error when retrieving print-kubeconfig flag") + } + tmpFile, err := downloadTempKubeconfig(ctx, client, cliConf) if err != nil { return err @@ -41,15 +48,26 @@ func runKubectl(ctx context.Context, _ *types.GetAuthenticatedUserResponse, clie os.Remove(tmpFile) }() - os.Setenv("KUBECONFIG", tmpFile) + if printKubeconfig { + kc, err := os.ReadFile(tmpFile) //nolint:gosec + if err != nil { + return fmt.Errorf("erro reading downloaded kubeconfig for printing: %w", err) + } + fmt.Println(string(kc)) + return nil + } - cmd := exec.Command("kubectl", args...) + err = os.Setenv("KUBECONFIG", tmpFile) + if err != nil { + return fmt.Errorf("unable to set KUBECONFIG env var: %w", err) + } - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + execCommand := exec.Command("kubectl", args...) - err = cmd.Run() + execCommand.Stdout = os.Stdout + execCommand.Stderr = os.Stderr + err = execCommand.Run() if err != nil { return fmt.Errorf("error running helm: %w", err) } diff --git a/cli/cmd/commands/list.go b/cli/cmd/commands/list.go index 7a9a7768d4..88e190bf39 100644 --- a/cli/cmd/commands/list.go +++ b/cli/cmd/commands/list.go @@ -91,7 +91,7 @@ func registerCommand_List(cliConf config.CLIConfig) *cobra.Command { return listCmd } -func listAll(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listAll(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.ListAll(ctx) if err != nil { @@ -108,7 +108,7 @@ func listAll(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client return nil } -func listApps(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listApps(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.ListApps(ctx) if err != nil { @@ -125,7 +125,7 @@ func listApps(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client return nil } -func listJobs(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listJobs(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.ListJobs(ctx) if err != nil { @@ -142,7 +142,7 @@ func listJobs(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client return nil } -func listAddons(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listAddons(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { err := writeReleases(ctx, client, cliConf, "addon") if err != nil { return err diff --git a/cli/cmd/commands/logs.go b/cli/cmd/commands/logs.go index 4c558d2d9d..3c91552ba9 100644 --- a/cli/cmd/commands/logs.go +++ b/cli/cmd/commands/logs.go @@ -44,7 +44,7 @@ func registerCommand_Logs(cliConf config.CLIConfig) *cobra.Command { return logsCmd } -func logs(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, args []string) error { +func logs(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, args []string) error { podsSimple, err := getPods(ctx, client, cliConfig, namespace, args[0]) if err != nil { return fmt.Errorf("Could not retrieve list of pods: %s", err.Error()) diff --git a/cli/cmd/commands/project.go b/cli/cmd/commands/project.go index ad3efb4353..c592fd8a94 100644 --- a/cli/cmd/commands/project.go +++ b/cli/cmd/commands/project.go @@ -64,7 +64,7 @@ func registerCommand_Project(cliConf config.CLIConfig) *cobra.Command { return projectCmd } -func createProject(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func createProject(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { resp, err := client.CreateProject(ctx, &types.CreateProjectRequest{ Name: args[0], }) @@ -77,7 +77,7 @@ func createProject(ctx context.Context, _ *types.GetAuthenticatedUserResponse, c return cliConf.SetProject(ctx, client, resp.ID) } -func listProjects(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listProjects(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { resp, err := client.ListUserProjects(ctx) if err != nil { return err @@ -105,7 +105,7 @@ func listProjects(ctx context.Context, user *types.GetAuthenticatedUserResponse, return nil } -func deleteProject(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, args []string) error { +func deleteProject(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, args []string) error { userResp, err := utils.PromptPlaintext( fmt.Sprintf( `Are you sure you'd like to delete the project with id %s? %s `, diff --git a/cli/cmd/commands/registry.go b/cli/cmd/commands/registry.go index 4319b9ecef..59301809b4 100644 --- a/cli/cmd/commands/registry.go +++ b/cli/cmd/commands/registry.go @@ -95,7 +95,7 @@ func registerCommand_Registry(cliConf config.CLIConfig) *cobra.Command { return registryCmd } -func listRegistries(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listRegistries(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { pID := cliConf.Project // get the list of namespaces @@ -129,7 +129,7 @@ func listRegistries(ctx context.Context, user *types.GetAuthenticatedUserRespons return nil } -func deleteRegistry(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func deleteRegistry(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { userResp, err := utils.PromptPlaintext( fmt.Sprintf( `Are you sure you'd like to delete the registry with id %s? %s `, @@ -159,7 +159,7 @@ func deleteRegistry(ctx context.Context, user *types.GetAuthenticatedUserRespons return nil } -func listRepos(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listRepos(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { pID := cliConf.Project rID := cliConf.Registry @@ -189,7 +189,7 @@ func listRepos(ctx context.Context, user *types.GetAuthenticatedUserResponse, cl return nil } -func listImages(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func listImages(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { pID := cliConf.Project rID := cliConf.Registry repoName := args[0] diff --git a/cli/cmd/commands/run.go b/cli/cmd/commands/run.go index 141e0e1249..c478088ac9 100644 --- a/cli/cmd/commands/run.go +++ b/cli/cmd/commands/run.go @@ -126,7 +126,7 @@ func registerCommand_Run(cliConf config.CLIConfig) *cobra.Command { return runCmd } -func run(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func run(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { execArgs := args[1:] color.New(color.FgGreen).Println("Running", strings.Join(execArgs, " "), "for release", args[0]) @@ -242,7 +242,7 @@ func run(ctx context.Context, user *types.GetAuthenticatedUserResponse, client a return executeRunEphemeral(ctx, config, namespace, selectedPod.Name, selectedContainerName, execArgs) } -func cleanup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ []string) error { +func cleanup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) error { config := &PorterRunSharedConfig{ Client: client, CLIConfig: cliConfig, diff --git a/cli/cmd/commands/stack.go b/cli/cmd/commands/stack.go index 256629c74d..6ddc8f13ca 100644 --- a/cli/cmd/commands/stack.go +++ b/cli/cmd/commands/stack.go @@ -101,7 +101,7 @@ func registerCommand_Stack(cliConf config.CLIConfig) *cobra.Command { return stackCmd } -func stackAddEnvGroup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func stackAddEnvGroup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.StackAddEnvGroup(ctx) if err != nil { @@ -179,7 +179,7 @@ func stackAddEnvGroup(ctx context.Context, _ *types.GetAuthenticatedUserResponse return nil } -func stackRemoveEnvGroup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func stackRemoveEnvGroup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.StackRemoveEnvGroup(ctx) if err != nil { diff --git a/cli/cmd/commands/update.go b/cli/cmd/commands/update.go index d7eecbb17d..fe32d53b21 100644 --- a/cli/cmd/commands/update.go +++ b/cli/cmd/commands/update.go @@ -443,7 +443,7 @@ the image that the application uses if no --values file is specified: return updateCmd } -func updateFull(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func updateFull(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.UpdateFull(ctx, cliConf, client, app) if err != nil { @@ -503,7 +503,7 @@ func updateFull(ctx context.Context, _ *types.GetAuthenticatedUserResponse, clie return nil } -func updateGetEnv(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func updateGetEnv(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { updateAgent, err := updateGetAgent(ctx, client, cliConf) if err != nil { return err @@ -526,7 +526,7 @@ func updateGetEnv(ctx context.Context, _ *types.GetAuthenticatedUserResponse, cl return updateAgent.WriteBuildEnv(getEnvFileDest) } -func updateBuild(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func updateBuild(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.UpdateBuild(ctx) if err != nil { @@ -543,7 +543,7 @@ func updateBuild(ctx context.Context, _ *types.GetAuthenticatedUserResponse, cli return updateBuildWithAgent(ctx, updateAgent) } -func updatePush(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func updatePush(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if app == "" { if len(args) == 0 { return fmt.Errorf("please provide the docker image name") @@ -602,7 +602,7 @@ func updatePush(ctx context.Context, _ *types.GetAuthenticatedUserResponse, clie return updatePushWithAgent(ctx, updateAgent) } -func updateUpgrade(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func updateUpgrade(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if featureFlags.ValidateApplyV2Enabled { err := v2.UpdateUpgrade(ctx) if err != nil { @@ -635,7 +635,7 @@ func updateUpgrade(ctx context.Context, _ *types.GetAuthenticatedUserResponse, c return nil } -func updateSetEnvGroup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func updateSetEnvGroup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if len(normalEnvGroupVars) == 0 && len(secretEnvGroupVars) == 0 && len(args) == 0 { return fmt.Errorf("please provide one or more variables to update") } @@ -743,7 +743,7 @@ func validateVarValue(in string) (string, string, error) { return key, value, nil } -func updateUnsetEnvGroup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error { +func updateUnsetEnvGroup(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { if len(args) == 0 { return fmt.Errorf("required variable name") } From a61574bb17f1070723adfa62bbf0c2e9b1854bdd Mon Sep 17 00:00:00 2001 From: Stefan McShane Date: Tue, 26 Sep 2023 11:12:46 +0100 Subject: [PATCH 2/4] merging master --- cli/cmd/commands/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/cmd/commands/app.go b/cli/cmd/commands/app.go index 4718722702..2d7142d015 100644 --- a/cli/cmd/commands/app.go +++ b/cli/cmd/commands/app.go @@ -1145,7 +1145,7 @@ func appCreateEphemeralPodFromExisting( ) } -func appUpdateTag(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, args []string) error { +func appUpdateTag(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { project, err := client.GetProject(ctx, cliConfig.Project) if err != nil { return fmt.Errorf("could not retrieve project from Porter API. Please contact support@porter.run") From 18e44ecde8cbc8c140c1316ad0463db8b2e59e24 Mon Sep 17 00:00:00 2001 From: Stefan McShane Date: Tue, 26 Sep 2023 11:13:52 +0100 Subject: [PATCH 3/4] merging master --- cli/cmd/commands/app.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/cmd/commands/app.go b/cli/cmd/commands/app.go index 2d7142d015..255a8ce9c9 100644 --- a/cli/cmd/commands/app.go +++ b/cli/cmd/commands/app.go @@ -1146,13 +1146,13 @@ func appCreateEphemeralPodFromExisting( } func appUpdateTag(ctx context.Context, user *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, cmd *cobra.Command, args []string) error { - project, err := client.GetProject(ctx, cliConfig.Project) + project, err := client.GetProject(ctx, cliConf.Project) if err != nil { return fmt.Errorf("could not retrieve project from Porter API. Please contact support@porter.run") } if project.ValidateApplyV2 { - tag, err := v2.UpdateImage(ctx, appTag, client, cliConfig.Project, cliConfig.Cluster, args[0]) + tag, err := v2.UpdateImage(ctx, appTag, client, cliConf.Project, cliConf.Cluster, args[0]) if err != nil { return fmt.Errorf("error updating tag: %w", err) } @@ -1163,7 +1163,7 @@ func appUpdateTag(ctx context.Context, user *types.GetAuthenticatedUserResponse, if appTag == "" { appTag = "latest" } - release, err := client.GetRelease(ctx, cliConfig.Project, cliConfig.Cluster, namespace, args[0]) + release, err := client.GetRelease(ctx, cliConf.Project, cliConf.Cluster, namespace, args[0]) if err != nil { return fmt.Errorf("Unable to find application %s", args[0]) } @@ -1176,8 +1176,8 @@ func appUpdateTag(ctx context.Context, user *types.GetAuthenticatedUserResponse, Tag: appTag, } createUpdatePorterAppRequest := &types.CreatePorterAppRequest{ - ClusterID: cliConfig.Cluster, - ProjectID: cliConfig.Project, + ClusterID: cliConf.Cluster, + ProjectID: cliConf.Project, ImageInfo: imageInfo, OverrideRelease: false, } @@ -1186,8 +1186,8 @@ func appUpdateTag(ctx context.Context, user *types.GetAuthenticatedUserResponse, _, err = client.CreatePorterApp( ctx, - cliConfig.Project, - cliConfig.Cluster, + cliConf.Project, + cliConf.Cluster, args[0], createUpdatePorterAppRequest, ) From 813b4daa07f8b907e0612348e6d73c534c711d2b Mon Sep 17 00:00:00 2001 From: Stefan McShane Date: Tue, 26 Sep 2023 11:23:38 +0100 Subject: [PATCH 4/4] reducing cyclo complexity --- cli/cmd/commands/apply.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cli/cmd/commands/apply.go b/cli/cmd/commands/apply.go index c4b6ba8b3a..5f5692f6e1 100644 --- a/cli/cmd/commands/apply.go +++ b/cli/cmd/commands/apply.go @@ -112,18 +112,23 @@ applying a configuration: return applyCmd } +func appNameFromEnvironmentVariable() string { + if os.Getenv("PORTER_APP_NAME") != "" { + return os.Getenv("PORTER_APP_NAME") + } + if os.Getenv("PORTER_STACK_NAME") != "" { + return os.Getenv("PORTER_STACK_NAME") + } + return "" +} + func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConfig config.CLIConfig, _ config.FeatureFlags, _ *cobra.Command, _ []string) (err error) { project, err := client.GetProject(ctx, cliConfig.Project) if err != nil { return fmt.Errorf("could not retrieve project from Porter API. Please contact support@porter.run") } - var appName string - if os.Getenv("PORTER_APP_NAME") != "" { - appName = os.Getenv("PORTER_APP_NAME") - } else if os.Getenv("PORTER_STACK_NAME") != "" { - appName = os.Getenv("PORTER_STACK_NAME") - } + appName := appNameFromEnvironmentVariable() if project.ValidateApplyV2 { if previewApply && !project.PreviewEnvsEnabled {