| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- package cmd
- import (
- "os"
- "github.com/porter-dev/porter/cli/cmd/api"
- "github.com/porter-dev/porter/cli/cmd/connect"
- "github.com/spf13/cobra"
- )
- var (
- kubeconfigPath string
- print *bool
- contexts *[]string
- )
- var connectCmd = &cobra.Command{
- Use: "connect",
- Short: "Commands that connect to external clusters and providers",
- }
- var connectKubeconfigCmd = &cobra.Command{
- Use: "kubeconfig",
- Short: "Uses the local kubeconfig to add a cluster",
- Run: func(cmd *cobra.Command, args []string) {
- err := checkLoginAndRun(args, runConnectKubeconfig)
- if err != nil {
- os.Exit(1)
- }
- },
- }
- var connectECRCmd = &cobra.Command{
- Use: "ecr",
- Short: "Adds an ECR instance to a project",
- Run: func(cmd *cobra.Command, args []string) {
- err := checkLoginAndRun(args, runConnectECR)
- if err != nil {
- os.Exit(1)
- }
- },
- }
- var connectGCRCmd = &cobra.Command{
- Use: "gcr",
- Short: "Adds a GCR instance to a project",
- Run: func(cmd *cobra.Command, args []string) {
- err := checkLoginAndRun(args, runConnectGCR)
- if err != nil {
- os.Exit(1)
- }
- },
- }
- var connectHRCmd = &cobra.Command{
- Use: "helmrepo",
- Aliases: []string{"helm", "helmrepos"},
- Short: "Adds a Helm repository to a project",
- Run: func(cmd *cobra.Command, args []string) {
- err := checkLoginAndRun(args, runConnectHelmRepoBasic)
- if err != nil {
- os.Exit(1)
- }
- },
- }
- func init() {
- rootCmd.AddCommand(connectCmd)
- connectCmd.AddCommand(connectKubeconfigCmd)
- connectCmd.PersistentFlags().StringVar(
- &host,
- "host",
- getHost(),
- "host url of Porter instance",
- )
- projectID = *connectCmd.PersistentFlags().UintP(
- "project-id",
- "p",
- getProjectID(),
- "project id to use",
- )
- connectKubeconfigCmd.PersistentFlags().StringVarP(
- &kubeconfigPath,
- "kubeconfig",
- "k",
- "",
- "path to kubeconfig",
- )
- contexts = connectKubeconfigCmd.PersistentFlags().StringArray(
- "context",
- nil,
- "the context to connect (defaults to the current context)",
- )
- connectCmd.AddCommand(connectECRCmd)
- connectCmd.AddCommand(connectGCRCmd)
- connectCmd.AddCommand(connectHRCmd)
- }
- func runConnectKubeconfig(_ *api.AuthCheckResponse, client *api.Client, _ []string) error {
- isLocal := false
- if getDriver() == "local" {
- isLocal = true
- }
- id, err := connect.Kubeconfig(
- client,
- kubeconfigPath,
- *contexts,
- getProjectID(),
- isLocal,
- )
- if err != nil {
- return err
- }
- return setCluster(id)
- }
- func runConnectECR(_ *api.AuthCheckResponse, client *api.Client, _ []string) error {
- regID, err := connect.ECR(
- client,
- getProjectID(),
- )
- if err != nil {
- return err
- }
- return setRegistry(regID)
- }
- func runConnectGCR(_ *api.AuthCheckResponse, client *api.Client, _ []string) error {
- regID, err := connect.GCR(
- client,
- getProjectID(),
- )
- if err != nil {
- return err
- }
- return setRegistry(regID)
- }
- func runConnectHelmRepoBasic(_ *api.AuthCheckResponse, client *api.Client, _ []string) error {
- hrID, err := connect.Helm(
- client,
- getProjectID(),
- )
- if err != nil {
- return err
- }
- return setHelmRepo(hrID)
- }
|