diff --git a/cmd/k3d/create.go b/cmd/k3d/create.go index cdf3f1e36..544f12e64 100644 --- a/cmd/k3d/create.go +++ b/cmd/k3d/create.go @@ -25,6 +25,8 @@ import ( githttps "github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/kubefirst/kubefirst-api/pkg/handlers" "github.com/kubefirst/kubefirst-api/pkg/reports" + "github.com/kubefirst/kubefirst-api/pkg/types" + utils "github.com/kubefirst/kubefirst-api/pkg/utils" "github.com/kubefirst/kubefirst-api/pkg/wrappers" "github.com/kubefirst/kubefirst/internal/catalog" "github.com/kubefirst/kubefirst/internal/gitShim" @@ -42,6 +44,7 @@ import ( "github.com/kubefirst/runtime/pkg/k8s" "github.com/kubefirst/runtime/pkg/progressPrinter" "github.com/kubefirst/runtime/pkg/services" + internalssh "github.com/kubefirst/runtime/pkg/ssh" "github.com/kubefirst/runtime/pkg/terraform" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" @@ -115,11 +118,11 @@ func runK3d(cmd *cobra.Command, args []string) error { return err } - // If cluster setup is complete, return - clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete") - if clusterSetupComplete { - return fmt.Errorf("this cluster install process has already completed successfully") - } + // // If cluster setup is complete, return + // clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete") + // if clusterSetupComplete { + // return fmt.Errorf("this cluster install process has already completed successfully") + // } utilities.CreateK1ClusterDirectory(clusterNameFlag) helpers.DisplayLogHints() @@ -129,22 +132,22 @@ func runK3d(cmd *cobra.Command, args []string) error { return err } - // switch gitProviderFlag { - // case "github": - // key, err := internalssh.GetHostKey("github.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "github.com", key.Type()) - // } - // case "gitlab": - // key, err := internalssh.GetHostKey("gitlab.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) - // } - // } + switch gitProviderFlag { + case "github": + key, err := internalssh.GetHostKey("github.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "github.com", key.Type()) + } + case "gitlab": + key, err := internalssh.GetHostKey("gitlab.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) + } + } // Either user or org can be specified for github, not both if githubOrgFlag != "" && githubUserFlag != "" { @@ -449,11 +452,11 @@ func runK3d(cmd *cobra.Command, args []string) error { telemetry.SendEvent(segClient, telemetry.KbotSetupStarted, "") log.Info().Msg("creating an ssh key pair for your new cloud infrastructure") - // sshPrivateKey, sshPublicKey, err = internalssh.CreateSshKeyPair() - // if err != nil { - // telemetry.SendEvent(segClient, telemetry.KbotSetupFailed, err.Error()) - // return err - // } + sshPrivateKey, sshPublicKey, err = utils.CreateSshKeyPair() + if err != nil { + telemetry.SendEvent(segClient, telemetry.KbotSetupFailed, err.Error()) + return err + } log.Info().Msg("ssh key pair creation complete") viper.Set("kbot.private-key", sshPrivateKey) @@ -701,14 +704,14 @@ func runK3d(cmd *cobra.Command, args []string) error { log.Info().Msgf("error opening repo at: %s", config.MetaphorDir) } - // err = internalssh.EvalSSHKey(&internalssh.EvalSSHKeyRequest{ - // GitProvider: gitProviderFlag, - // GitlabGroupFlag: gitlabGroupFlag, - // GitToken: cGitToken, - // }) - // if err != nil { - // return err - // } + err = utils.EvalSSHKey(&types.EvalSSHKeyRequest{ + GitProvider: gitProviderFlag, + GitlabGroupFlag: gitlabGroupFlag, + GitToken: cGitToken, + }) + if err != nil { + return err + } //Push to remotes and use https // Push gitops repo to remote @@ -1014,7 +1017,7 @@ func runK3d(cmd *cobra.Command, args []string) error { log.Error().Err(err).Msg("") } - if os.Getenv("SKIP_ARGOCD_LAUNCH") != "true" { + if os.Getenv("SKIP_ARGOCD_LAUNCH") != "true" || !ciFlag { err = pkg.OpenBrowser(pkg.ArgoCDLocalURLTLS) if err != nil { log.Error().Err(err).Msg("") @@ -1401,8 +1404,10 @@ func runK3d(cmd *cobra.Command, args []string) error { log.Info().Msg("welcome to your new kubefirst platform running in K3d") time.Sleep(time.Second * 1) // allows progress bars to finish - if !ciFlag { - reports.LocalHandoffScreenV2(viper.GetString("components.argocd.password"), clusterNameFlag, gitDestDescriptor, cGitOwner, config, false) + reports.LocalHandoffScreenV2(viper.GetString("components.argocd.password"), clusterNameFlag, gitDestDescriptor, cGitOwner, config, ciFlag) + + if ciFlag { + os.Exit(0) } } diff --git a/go.mod b/go.mod index 9750acff5..7010e9852 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/hashicorp/vault/api v1.9.0 github.com/kubefirst/kubefirst-api v0.1.21 github.com/kubefirst/metrics-client v0.3.0 - github.com/kubefirst/runtime v0.4.3 + github.com/kubefirst/runtime v0.4.4 github.com/nxadm/tail v1.4.8 github.com/rs/zerolog v1.29.1 github.com/sirupsen/logrus v1.9.0 @@ -76,6 +76,7 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bombsimon/logrusr/v2 v2.0.1 // indirect github.com/bradleyfalzon/ghinstallation/v2 v2.1.0 // indirect + github.com/caarlos0/env/v10 v10.0.0 // indirect github.com/caarlos0/env/v6 v6.10.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chai2010/gettext-go v0.1.0 // indirect @@ -117,6 +118,7 @@ require ( github.com/gorilla/css v1.0.0 // indirect github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect github.com/jedib0t/go-pretty/v6 v6.4.6 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/jonboulle/clockwork v0.2.2 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect @@ -129,6 +131,7 @@ require ( github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/microcosm-cc/bluemonday v1.0.21 // indirect github.com/miekg/dns v1.1.40 // indirect + github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a // indirect github.com/minio/md5-simd v1.1.2 // indirect github.com/minio/sha256-simd v1.0.0 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect @@ -156,6 +159,7 @@ require ( github.com/segmentio/analytics-go v3.1.0+incompatible // indirect github.com/segmentio/backo-go v1.0.1 // indirect github.com/skeema/knownhosts v1.1.0 // indirect + github.com/thanhpk/randstr v1.0.6 // indirect github.com/vmihailenco/go-tinylfu v0.2.1 // indirect github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect @@ -260,7 +264,7 @@ require ( github.com/spf13/afero v1.9.3 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/spf13/pflag v1.0.5 + github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/net v0.21.0 // indirect diff --git a/go.sum b/go.sum index b10b6aaa3..a2bfb7304 100644 --- a/go.sum +++ b/go.sum @@ -223,6 +223,8 @@ github.com/bradleyfalzon/ghinstallation/v2 v2.1.0 h1:5+NghM1Zred9Z078QEZtm28G/kf github.com/bradleyfalzon/ghinstallation/v2 v2.1.0/go.mod h1:Xg3xPRN5Mcq6GDqeUVhFbjEWMb4JHCyWEeeBGEYQoTU= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/caarlos0/env/v10 v10.0.0 h1:yIHUBZGsyqCnpTkbjk8asUlx6RFhhEs+h7TOBdgdzXA= +github.com/caarlos0/env/v10 v10.0.0/go.mod h1:ZfulV76NvVPw3tm591U4SwL3Xx9ldzBP9aGxzeN7G18= github.com/caarlos0/env/v6 v6.10.1 h1:t1mPSxNpei6M5yAeu1qtRdPAK29Nbcf/n3G7x+b3/II= github.com/caarlos0/env/v6 v6.10.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= @@ -669,6 +671,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= @@ -724,8 +728,8 @@ github.com/kubefirst/kubefirst-api v0.1.21 h1:sWS/DXNb5EGVg7apwHQl5ANWn905Hv5VBA github.com/kubefirst/kubefirst-api v0.1.21/go.mod h1:yk7WiGew7SOAWI9LVhx02l9XEAYTzof/kkxHgkgZBpM= github.com/kubefirst/metrics-client v0.3.0 h1:zCug82pEzeWhHhpeYQvdhytRNDxrLxX18dPQ5PSxY3s= github.com/kubefirst/metrics-client v0.3.0/go.mod h1:GR7wsMcyYhd+EU67PeuMCBYFE6OJ7P/j5OI5BLOoRMc= -github.com/kubefirst/runtime v0.4.3 h1:36oupCott94GF3qB6xSAq9R6NSRJb93zpQCKNMVB5Eg= -github.com/kubefirst/runtime v0.4.3/go.mod h1:GWsDhvffBMeJaHFgcCCyQrHIldclwVHwKD/j07UDYk4= +github.com/kubefirst/runtime v0.4.4 h1:HI2h49o8YF5bjMgbSSMLPULF6ygBZMTYwe5hfWkE39s= +github.com/kubefirst/runtime v0.4.4/go.mod h1:GWsDhvffBMeJaHFgcCCyQrHIldclwVHwKD/j07UDYk4= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/libopenstorage/openstorage v1.0.0/go.mod h1:Sp1sIObHjat1BeXhfMqLZ14wnOzEhNx2YQedreMcUyc= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0= @@ -782,6 +786,8 @@ github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXm github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.40 h1:pyyPFfGMnciYUk/mXpKkVmeMQjfXqt3FAJ2hy7tPiLA= github.com/miekg/dns v1.1.40/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= +github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a h1:eU8j/ClY2Ty3qdHnn0TyW3ivFoPC/0F1gQZz8yTxbbE= +github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a/go.mod h1:v8eSC2SMp9/7FTKUncp7fH9IwPfw+ysMObcEz5FWheQ= github.com/mindprince/gonvml v0.0.0-20190828220739-9ebdce4bb989/go.mod h1:2eu9pRWp8mo84xCg6KswZ+USQHjwgRhNp06sozOdsTY= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= @@ -1105,6 +1111,8 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69 github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= +github.com/thanhpk/randstr v1.0.6 h1:psAOktJFD4vV9NEVb3qkhRSMvYh4ORRaj1+w/hn4B+o= +github.com/thanhpk/randstr v1.0.6/go.mod h1:M/H2P1eNLZzlDwAzpkkkUvoyNNMbzRGhESZuEQk3r0U= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=