Skip to content

Commit

Permalink
feat: add single source of truth for k3d cloud flag (#738)
Browse files Browse the repository at this point in the history
Signed-off-by: João Vanzuita <joao@kubeshop.io>

Signed-off-by: João Vanzuita <joao@kubeshop.io>
  • Loading branch information
João Paulo Vanzuita authored Nov 16, 2022
1 parent 6f31259 commit 6a4f3c8
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 24 deletions.
3 changes: 2 additions & 1 deletion cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/kubefirst/kubefirst/pkg"
"log"
"time"

Expand All @@ -19,7 +20,7 @@ var destroyCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {

//Destroy is implemented based on the flavor selected.
if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
err := destroyLocalGithubCmd.RunE(cmd, args)
if err != nil {
log.Println("Erroring destroying local+github:", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ validated and configured.`,
}
log.Println("dependency installation complete")
progressPrinter.IncrementTracker("step-download", 1)
if installerFlags.Cloud == flagset.CloudLocal {
if installerFlags.Cloud == pkg.CloudK3d {
err = downloadManager.DownloadLocalTools(config)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/postInstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var postInstallCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
// todo: temporary
//flagset.DefineGlobalFlags(cmd)
if viper.GetString("cloud") == flagset.CloudLocal {
if viper.GetString("cloud") == pkg.CloudK3d {
cmd.Flags().Bool("enable-console", true, "If hand-off screen will be presented on a browser UI")
}
//globalFlags, err := flagset.ProcessGlobalFlags(cmd)
Expand Down
5 changes: 2 additions & 3 deletions internal/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/flagset"
"github.com/kubefirst/kubefirst/pkg"
"github.com/spf13/viper"
)
Expand All @@ -25,7 +24,7 @@ func TestArgoCDLivenessIntegration(t *testing.T) {
}

var argoURL string
if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
argoURL = "http://localhost:8080"
} else {
argoURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename"))
Expand Down Expand Up @@ -60,7 +59,7 @@ func TestArgoWorkflowLivenessIntegration(t *testing.T) {
}

var argoURL string
if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
argoURL = "http://localhost:2746"
} else {
argoURL = fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename"))
Expand Down
7 changes: 3 additions & 4 deletions internal/flagset/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flagset

import (
"errors"
"github.com/kubefirst/kubefirst/pkg"
"log"

"github.com/kubefirst/kubefirst/configs"
Expand All @@ -11,8 +12,6 @@ import (
)

const CloudAws = "aws"
const CloudLocal = "k3d"
const CloudK3d = "k3d"

// DefineInstallerGenericFlags - define installer flags for CLI
type InstallerGenericFlags struct {
Expand Down Expand Up @@ -162,7 +161,7 @@ func ProcessInstallerGenericFlags(cmd *cobra.Command) (InstallerGenericFlags, er
//Adds mandatory addon for non-local install
addon.AddAddon("cloud")
}
if flags.Cloud == CloudK3d {
if flags.Cloud == pkg.CloudK3d {
//Adds mandatory addon for local install
addon.AddAddon("k3d")
}
Expand Down Expand Up @@ -221,7 +220,7 @@ func validateInstallationFlags() error {
// return errors.New(message)
// }
if len(viper.GetString("cloud")) < 1 {
message := "missing flag --cloud, supported values: " + CloudAws + ", " + CloudK3d
message := "missing flag --cloud, supported values: " + CloudAws + ", " + pkg.CloudK3d
log.Println(message)
return errors.New(message)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/repo/kubefirstTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
gitConfig "github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/flagset"
"github.com/kubefirst/kubefirst/internal/gitClient"
"github.com/kubefirst/kubefirst/pkg"
cp "github.com/otiai10/copy"
Expand Down Expand Up @@ -41,10 +40,10 @@ func PrepareKubefirstTemplateRepo(dryRun bool, config *configs.Config, githubOrg
viper.WriteConfig()

log.Printf("cloned %s-template repository to directory %s/%s", repoName, config.K1FolderPath, repoName)
if viper.GetString("cloud") == flagset.CloudK3d && !viper.GetBool("github.gitops.hydrated") {
if viper.GetString("cloud") == pkg.CloudK3d && !viper.GetBool("github.gitops.hydrated") {
UpdateForLocalMode(directory)
}
if viper.GetString("cloud") == flagset.CloudK3d && strings.Contains(repoName, "metaphor") {
if viper.GetString("cloud") == pkg.CloudK3d && strings.Contains(repoName, "metaphor") {
os.RemoveAll(fmt.Sprintf("%s/.argo", directory))
os.RemoveAll(fmt.Sprintf("%s/.github", directory))
opt := cp.Options{
Expand Down
17 changes: 8 additions & 9 deletions internal/reports/section.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log"
"strings"

"github.com/kubefirst/kubefirst/internal/flagset"
"github.com/spf13/viper"
)

Expand Down Expand Up @@ -63,7 +62,7 @@ func PrintSectionAws() []byte {
func PrintSectionVault() []byte {

var vaultURL string
if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
vaultURL = "http://localhost:8200"
} else {
vaultURL = fmt.Sprintf("https://vault.%s", viper.GetString("aws.hostedzonename"))
Expand All @@ -80,7 +79,7 @@ func PrintSectionVault() []byte {
func PrintSectionArgoCD() []byte {

var argoCdURL string
if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
argoCdURL = "http://localhost:8080"
} else {
argoCdURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename"))
Expand All @@ -99,7 +98,7 @@ func PrintSectionArgoCD() []byte {
func PrintSectionArgoWorkflows() []byte {

var argoWorkflowsURL string
if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
argoWorkflowsURL = "http://localhost:2746"
} else {
argoWorkflowsURL = fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename"))
Expand All @@ -110,7 +109,7 @@ func PrintSectionArgoWorkflows() []byte {
handOffData.WriteString(strings.Repeat("-", 51))
handOffData.WriteString(fmt.Sprintf("\n URL: %s", argoWorkflowsURL))

if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
return handOffData.Bytes()
} else {
handOffData.WriteString("\n sso credentials only ")
Expand All @@ -123,7 +122,7 @@ func PrintSectionArgoWorkflows() []byte {
func PrintSectionAtlantis() []byte {

var atlantisUrl string
if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
atlantisUrl = "http://localhost:4141"
} else {
atlantisUrl = fmt.Sprintf("https://atlantis.%s", viper.GetString("aws.hostedzonename"))
Expand All @@ -140,7 +139,7 @@ func PrintSectionAtlantis() []byte {
func PrintSectionMuseum() []byte {

var chartmuseumURL string
if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
chartmuseumURL = "http://localhost:8181"
} else {
chartmuseumURL = fmt.Sprintf("https://chartmuseum.%s", viper.GetString("aws.hostedzonename"))
Expand All @@ -151,7 +150,7 @@ func PrintSectionMuseum() []byte {
handOffData.WriteString(strings.Repeat("-", 54))
handOffData.WriteString(fmt.Sprintf("\n URL: %s", chartmuseumURL))

if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
return handOffData.Bytes()
} else {
handOffData.WriteString("\n see vault for credentials ")
Expand Down Expand Up @@ -188,7 +187,7 @@ func PrintSectionMetaphorGo() []byte {

func PrintSectionMetaphorFrontend() []byte {
var handOffData bytes.Buffer
if viper.GetString("cloud") == flagset.CloudK3d {
if viper.GetString("cloud") == pkg.CloudK3d {
handOffData.WriteString("\n--- Metaphor ")
handOffData.WriteString(strings.Repeat("-", 57))
handOffData.WriteString("\n To access the metaphor applications you'll need to \n`kubectl port-forward` to the kubernetes service")
Expand Down
3 changes: 1 addition & 2 deletions internal/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/aws"
"github.com/kubefirst/kubefirst/internal/flagset"
"github.com/kubefirst/kubefirst/pkg"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -41,7 +40,7 @@ func terraformConfig(terraformEntryPoint string) map[string]string {
return envs
case "vault":

if viper.GetString("cloud") == flagset.CloudLocal {
if viper.GetString("cloud") == pkg.CloudK3d {
envs["TF_VAR_email_address"] = viper.GetString("adminemail")
envs["TF_VAR_github_token"] = os.Getenv("KUBEFIRST_GITHUB_AUTH_TOKEN")
envs["TF_VAR_vault_addr"] = viper.GetString("vault.local.service")
Expand Down

0 comments on commit 6a4f3c8

Please sign in to comment.