diff --git a/cmd/akamai/command.go b/cmd/akamai/command.go index c4e304d6..7fbbe8a4 100644 --- a/cmd/akamai/command.go +++ b/cmd/akamai/command.go @@ -110,6 +110,10 @@ func Create() *cobra.Command { createCmd.Flags().StringVar(&adminTeamName, "admin-team-name", "admins", "admin team name for this repo") createCmd.Flags().StringVar(&developerTeamName, "developer-team-name", "developers", "developer team name for this repo") createCmd.Flags().BoolVar(&installKubefirstProFlag, "install-kubefirst-pro", true, "whether or not to install kubefirst pro") + createCmd.Flags().StringVar(&gitopsRepoName, "gitops-repo-name", "gitops", "the custom gitops name") + createCmd.Flags().StringVar(&metaphorRepoName, "metaphor-repo-name", "metaphor", "the custom metaphor name") + createCmd.Flags().StringVar(&adminTeamName, "admin-team-name", "admins", "admin team name for this repo") + createCmd.Flags().StringVar(&developerTeamName, "developer-team-name", "developers", "developer team name for this repo") return createCmd } diff --git a/cmd/k3d/create.go b/cmd/k3d/create.go index f0567b6b..4ca54ef1 100644 --- a/cmd/k3d/create.go +++ b/cmd/k3d/create.go @@ -342,8 +342,7 @@ func runK3d(cmd *cobra.Command, args []string) error { //} // Instantiate K3d config - config := k3d.GetConfig(clusterNameFlag, gitProviderFlag, cGitOwner, gitProtocolFlag, gitopsRepoName, metaphorRepoName, adminTeamName, developerTeamName) - config := k3d.GetConfig(clusterNameFlag, gitProviderFlag, cGitOwner, gitProtocolFlag, gitopsRepoName, metaphorRepoName, adminTeamName, developerTeamName) + config := k3d.GetConfig(clusterNameFlag, gitProviderFlag, cGitOwner, gitProtocolFlag) switch gitProviderFlag { case "github": config.GithubToken = cGitToken @@ -395,8 +394,7 @@ func runK3d(cmd *cobra.Command, args []string) error { log.Info().Msgf("kubefirst version configs.K1Version: %s ", configs.K1Version) log.Info().Msgf("cloning gitops-template repo url: %s ", gitopsTemplateURLFlag) log.Info().Msgf("cloning gitops-template repo branch: %s ", gitopsTemplateBranchFlag) - log.Info().Msgf("branch %s\b", gitopsTemplateBranchFlag) - log.Info().Msgf("branch %s ", gitopsTemplateBranchFlag) + atlantisWebhookSecret := viper.GetString("secrets.atlantis-webhook") if atlantisWebhookSecret == "" { atlantisWebhookSecret = utils.Random(20) @@ -556,8 +554,7 @@ func runK3d(cmd *cobra.Command, args []string) error { if !viper.GetBool("kubefirst-checks.tools-downloaded") { log.Info().Msg("installing kubefirst dependencies") - err := k3d.DownloadTools(clusterNameFlag, config.GitProvider, cGitOwner, config.ToolsDir, config.GitProtocol, config.GitopsRepoName, config.MetaphorRepoName, config.AdminTeamName, config.DeveloperTeamName) - err := k3d.DownloadTools(clusterNameFlag, config.GitProvider, cGitOwner, config.ToolsDir, config.GitProtocol, config.GitopsRepoName, config.MetaphorRepoName, config.AdminTeamName, config.DeveloperTeamName) + err := k3d.DownloadTools(clusterNameFlag, config.GitProvider, cGitOwner, config.ToolsDir, config.GitProtocol) if err != nil { return err } @@ -573,8 +570,7 @@ func runK3d(cmd *cobra.Command, args []string) error { metaphorTemplateTokens := k3d.MetaphorTokenValues{ ClusterName: clusterNameFlag, CloudRegion: cloudRegionFlag, - ContainerRegistryURL: fmt.Sprintf("%s/%s/%s", containerRegistryHost, cGitOwner, config.MetaphorRepoName), - ContainerRegistryURL: fmt.Sprintf("%s/%s/%s", containerRegistryHost, cGitOwner, config.MetaphorRepoName), + ContainerRegistryURL: fmt.Sprintf("%s/%s/metaphor", containerRegistryHost, cGitOwner), DomainName: k3d.DomainName, MetaphorDevelopmentIngressURL: fmt.Sprintf("metaphor-development.%s", k3d.DomainName), MetaphorStagingIngressURL: fmt.Sprintf("metaphor-staging.%s", k3d.DomainName), @@ -616,10 +612,6 @@ func runK3d(cmd *cobra.Command, args []string) error { if err != nil { return err } - viper.Set("adminTeamName", config.AdminTeamName) - viper.Set("developerTeamName", config.DeveloperTeamName) - viper.Set("adminTeamName", config.AdminTeamName) - viper.Set("developerTeamName", config.DeveloperTeamName) // todo emit init telemetry end viper.Set("kubefirst-checks.gitops-ready-to-push", true) @@ -1072,53 +1064,7 @@ func runK3d(cmd *cobra.Command, args []string) error { log.Info().Msg("applying the registry application to argocd") registryApplicationObject := argocd.GetArgoCDApplicationObject(gitopsRepoURL, fmt.Sprintf("registry/%s", clusterNameFlag)) - err = k3d.RestartDeployment(context.Background(), kcfg.Clientset, "argocd", "argocd-applicationset-controller") - err = k3d.RestartDeployment(context.Background(), kcfg.Clientset, "argocd", "argocd-applicationset-controller") - if err != nil { - log.Info().Msgf("Error executing kubectl command: %v\n", err) - return err - } - - - retryAttempts := 2 - for attempt := 1; attempt <= retryAttempts; attempt++ { - log.Info().Msgf("Attempt #%d to create Argo CD application...\n", attempt) - - app, err := argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{}) - return fmt.Errorf("error in restarting argocd controller %w", err) - } - - err = wait.PollImmediate(5*time.Second, 20*time.Second, func() (bool, error) { - _, err := argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{}) - if err != nil { - if errors.Is(err, syscall.ECONNREFUSED) { - return false, nil // retry if we can't connect to it - } - - if apierrors.IsAlreadyExists(err) { - return true, nil // application already exists - } - - return false, fmt.Errorf("error creating argocd application : %w", err) - } - return true, nil - }) - if err != nil { - return fmt.Errorf("error creating argocd application : %w", err) - } - - log.Info().Msg("Argo CD application created successfully") - return false, nil - } - return true, nil - }) - - if err != nil { - return fmt.Errorf("error creating argocd application : %w", err) - } - - log.Info().Msg("Argo CD application created successfully\n") - + _, _ = argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{}) viper.Set("kubefirst-checks.argocd-create-registry", true) viper.WriteConfig() telemetry.SendEvent(segClient, telemetry.CreateRegistryCompleted, "") @@ -1225,8 +1171,7 @@ func runK3d(cmd *cobra.Command, args []string) error { // define upload object objectName := fmt.Sprintf("terraform/%s/terraform.tfstate", config.GitProvider) - filePath := config.K1Dir + fmt.Sprintf("/%s/%s", objectName, config.GitopsRepoName) - filePath := config.K1Dir + fmt.Sprintf("/%s/%s", objectName, config.GitopsRepoName) + filePath := config.K1Dir + fmt.Sprintf("/gitops/%s", objectName) contentType := "xl.meta" bucketName := "kubefirst-state-store" log.Info().Msgf("BucketName: %s", bucketName) @@ -1496,4 +1441,3 @@ func runK3d(cmd *cobra.Command, args []string) error { return nil } - diff --git a/cmd/k3d/destroy.go b/cmd/k3d/destroy.go index f0e750f2..e321d531 100644 --- a/cmd/k3d/destroy.go +++ b/cmd/k3d/destroy.go @@ -42,9 +42,13 @@ func destroyK3d(cmd *cobra.Command, args []string) error { // Check for existing port forwards before continuing - gitopsRepoName, metaphorRepoName := common.Getgitmeta(clusterName) + gitopsRepoName, metaphorRepoName, err := common.GetGitmeta(clusterName) - err := k8s.CheckForExistingPortForwards(9000) + if err != nil { + return fmt.Errorf("error in getting repo info: %w", err) + } + + err = k8s.CheckForExistingPortForwards(9000) if err != nil { log.Error().Msgf("%s - this port is required to tear down your kubefirst environment - please close any existing port forwards before continuing", err.Error()) return fmt.Errorf("%s (maybe the handoff screen is still open in another terminal) - this port is required to tear down your kubefirst environment - please close any existing port forwards before continuing", err.Error()) diff --git a/cmd/k3d/vault.go b/cmd/k3d/vault.go index 3aeb4a47..283eede9 100644 --- a/cmd/k3d/vault.go +++ b/cmd/k3d/vault.go @@ -40,7 +40,12 @@ func unsealVault(cmd *cobra.Command, args []string) error { if !flags.SetupComplete { return fmt.Errorf("there doesn't appear to be an active k3d cluster") } - gitopsRepoName, metaphorRepoName := common.Getgitmeta(viper.GetString("flags.cluster-name")) + gitopsRepoName, metaphorRepoName, err := common.GetGitmeta(viper.GetString("flags.cluster-name")) + + if err != nil { + return fmt.Errorf("error in getting repo info: %w", err) + } + config := k3d.GetConfig( viper.GetString("flags.cluster-name"), flags.GitProvider, diff --git a/internal/common/common.go b/internal/common/common.go index 735d51ad..870495bd 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -114,85 +114,6 @@ func GetRootCredentials(cmd *cobra.Command, args []string) error { return nil } -func GetGitmeta(clusterName string) (string, string, error) { - - var gitopsFound, metaphorFound bool - homePath, err := os.UserHomeDir() - dirs, err := ioutil.ReadDir(fmt.Sprintf("%s/.k1/%s", homePath, clusterName)) - var gitopsRepoName, metaphorRepoName string - - homePath, err := os.UserHomeDir() - if err != nil { - log.Info().Msg("Error reading directory") - return "cantfindgit", "cantfindmeta" - } - - for _, direc := range dirs { - if direc.IsDir() { - parentdir, err := ioutil.ReadDir(fmt.Sprintf("%s/.k1/%s/%s", homePath, clusterName, direc.Name())) - return "", "", fmt.Errorf("unable to get user's home directory: %w", err) - } - - basePath := filepath.Join(homePath, ".k1", clusterName) - - err = filepath.WalkDir(basePath, func(path string, info fs.DirEntry, err error) error { - if err != nil { - return err - } - - if info.IsDir() { - relPath, err := filepath.Rel(basePath, path) - - if err != nil { - return fmt.Errorf("error while finding repository : %w", err) - } - - if relPath == "." || strings.Count(relPath, string(os.PathSeparator)) == 1 { - if info.Name() == "registry" { - if !gitopsFound { - gitopsRepoName = filepath.Dir(relPath) - gitopsFound = true - } else if dir.Name() == ".github" { - metaphorRepoName = direc.Name() - } - } - if info.Name() == ".github" { - if !metaphorFound { - metaphorRepoName = filepath.Dir(relPath) - metaphorFound = true - } - } - } - - } - } - } - if metaphorFound && gitopsFound { - return fs.SkipDir - } - - return nil - }) - - if err != nil { - log.Info().Msg("Error reading directory") - return "", "", fmt.Errorf("Error Reading %w", err) - } - - if !gitopsFound { - log.Info().Msg("Gitops Repo not found") - return "cantfindgit", "cantfindmeta" - return "", "", fmt.Errorf("Gitopsrepo Not Found") - } - - if !metaphorFound { - log.Info().Msg("Metaphor Repo not found") - return "", "", fmt.Errorf("MetaphorRepo Not Found") - } - - return gitopsRepoName, metaphorRepoName, nil -} - func Destroy(cmd *cobra.Command, args []string) error { // Determine if there are active instal ls gitProvider := viper.GetString("flags.git-provider") @@ -204,12 +125,6 @@ func Destroy(cmd *cobra.Command, args []string) error { clusterName := viper.GetString("flags.cluster-name") domainName := viper.GetString("flags.domain-name") - gitopsRepoName, metaphorRepoName := Getgitmeta(clusterName) - gitopsRepoName, metaphorRepoName, err := GetGitmeta(clusterName) - - if err != nil { - return err - } // Switch based on git provider, set params cGitOwner := "" switch gitProvider { @@ -230,10 +145,6 @@ func Destroy(cmd *cobra.Command, args []string) error { gitProtocol, os.Getenv("CF_API_TOKEN"), os.Getenv("CF_ORIGIN_CA_ISSUER_API_TOKEN"), - gitopsRepoName, - metaphorRepoName, - gitopsRepoName, - metaphorRepoName, ) progress.AddStep("Destroying k3d")