Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 3rd party tools which require kubeconfig #3604

Merged
merged 5 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bin
openapi.yaml
.idea
portercli
local


vendor
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/commands/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]")
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/commands/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.") {
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/commands/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 `,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions cli/cmd/commands/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions cli/cmd/commands/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/commands/deploy_bluegreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]")
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/commands/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions cli/cmd/commands/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions cli/cmd/commands/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading
Loading