Bladeren bron

set the cluster when we change projects if there is only one cluster (#3037)

Feroze Mohideen 3 jaren geleden
bovenliggende
commit
5530e9faa4
2 gewijzigde bestanden met toevoegingen van 19 en 9 verwijderingen
  1. 7 9
      cli/cmd/app.go
  2. 12 0
      cli/cmd/config/config.go

+ 7 - 9
cli/cmd/app.go

@@ -80,7 +80,7 @@ var appUpdateTagCmd = &cobra.Command{
 	Args:  cobra.MinimumNArgs(1),
 	Short: "Updates the image tag for an application.",
 	Run: func(cmd *cobra.Command, args []string) {
-		err := checkLoginAndRun(args, appUpdateUpgrade)
+		err := checkLoginAndRun(args, appUpdateTag)
 		if err != nil {
 			os.Exit(1)
 		}
@@ -141,16 +141,14 @@ func appRun(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []st
 	appNamespace = fmt.Sprintf("porter-stack-%s", args[0])
 
 	if len(execArgs) > 0 {
-		release, err := client.GetRelease(
-			context.Background(), cliConf.Project, cliConf.Cluster, appNamespace, args[0],
-		)
+		res, err := client.GetPorterApp(context.Background(), cliConf.Project, cliConf.Cluster, args[0])
 		if err != nil {
-			return fmt.Errorf("error fetching release %s: %w", args[0], err)
+			return fmt.Errorf("Unable to run command - application not found: %w", err)
 		}
 
-		if release.BuildConfig != nil &&
-			(strings.Contains(release.BuildConfig.Builder, "heroku") ||
-				strings.Contains(release.BuildConfig.Builder, "paketo")) &&
+		if res.Builder != "" &&
+			(strings.Contains(res.Builder, "heroku") ||
+				strings.Contains(res.Builder, "paketo")) &&
 			execArgs[0] != "/cnb/lifecycle/launcher" &&
 			execArgs[0] != "launcher" {
 			// this is a buildpacks release using a heroku builder, prepend the launcher
@@ -984,7 +982,7 @@ func appCreateEphemeralPodFromExisting(
 	)
 }
 
-func appUpdateUpgrade(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
+func appUpdateTag(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
 	namespace := fmt.Sprintf("porter-stack-%s", args[0])
 	if appTag == "" {
 		appTag = "latest"

+ 12 - 0
cli/cmd/config/config.go

@@ -1,6 +1,7 @@
 package config
 
 import (
+	"context"
 	"errors"
 	"fmt"
 	"io/ioutil"
@@ -233,6 +234,17 @@ func (c *CLIConfig) SetProject(projectID uint) error {
 
 	config.Project = projectID
 
+	client := GetAPIClient()
+	if client != nil {
+		resp, err := client.ListProjectClusters(context.Background(), projectID)
+		if err == nil {
+			clusters := *resp
+			if len(clusters) == 1 {
+				c.SetCluster(clusters[0].ID)
+			}
+		}
+	}
+
 	return nil
 }