Skip to content

Commit

Permalink
add akamai cloud support (#2104)
Browse files Browse the repository at this point in the history
* initial commit for akamai beta command with github

* unable to run cli, package issue

* need to add this back

* Update go.mod

* cleanup mod file

---------

Co-authored-by: Cristhian Fernández <[email protected]>
  • Loading branch information
jarededwards and CristhianF7 authored Mar 12, 2024
1 parent 1db2022 commit 204a548
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 141 deletions.
132 changes: 132 additions & 0 deletions cmd/akamai/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
Copyright (C) 2021-2023, Kubefirst
This program is licensed under MIT.
See the LICENSE file for more details.
*/
package akamai

import (
"fmt"

"github.com/kubefirst/kubefirst-api/pkg/constants"
"github.com/kubefirst/kubefirst/internal/common"
"github.com/kubefirst/kubefirst/internal/progress"
"github.com/spf13/cobra"
)

var (
// Create
alertsEmailFlag string
ciFlag bool
cloudRegionFlag string
clusterNameFlag string
clusterTypeFlag string
dnsProviderFlag string
subdomainNameFlag string
domainNameFlag string
githubOrgFlag string
gitlabGroupFlag string
gitProviderFlag string
gitProtocolFlag string
gitopsTemplateURLFlag string
gitopsTemplateBranchFlag string
useTelemetryFlag bool
nodeTypeFlag string
nodeCountFlag string
installCatalogApps string

// RootCredentials
copyArgoCDPasswordToClipboardFlag bool
copyKbotPasswordToClipboardFlag bool
copyVaultPasswordToClipboardFlag bool

// Supported providers
supportedDNSProviders = []string{"cloudflare"}
supportedGitProviders = []string{"github", "gitlab"}
// Supported git protocols
supportedGitProtocolOverride = []string{"https", "ssh"}
)

func NewCommand() *cobra.Command {
akamaiCmd := &cobra.Command{
Use: "akamai",
Short: "kubefirst akamai installation",
Long: "kubefirst akamai",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("To learn more about akamai in kubefirst, run:")
fmt.Println(" kubefirst akamai --help")

if progress.Progress != nil {
progress.Progress.Quit()
}
},
}

// wire up new commands
akamaiCmd.AddCommand(Create(), Destroy(), RootCredentials())

return akamaiCmd
}

func Create() *cobra.Command {
createCmd := &cobra.Command{
Use: "create",
Short: "create the kubefirst platform running on akamai kubernetes",
TraverseChildren: true,
RunE: createAkamai,
}

akamaiDefaults := constants.GetCloudDefaults().Akamai

// todo review defaults and update descriptions
createCmd.Flags().StringVar(&alertsEmailFlag, "alerts-email", "", "email address for let's encrypt certificate notifications (required)")
createCmd.MarkFlagRequired("alerts-email")
createCmd.Flags().BoolVar(&ciFlag, "ci", false, "if running kubefirst in ci, set this flag to disable interactive features")
createCmd.Flags().StringVar(&cloudRegionFlag, "cloud-region", "us-central", "the akamai region to provision infrastructure in")
createCmd.Flags().StringVar(&clusterNameFlag, "cluster-name", "kubefirst", "the name of the cluster to create")
createCmd.Flags().StringVar(&clusterTypeFlag, "cluster-type", "mgmt", "the type of cluster to create (i.e. mgmt|workload)")
createCmd.Flags().StringVar(&nodeCountFlag, "node-count", akamaiDefaults.NodeCount, "the node count for the cluster")
createCmd.Flags().StringVar(&nodeTypeFlag, "node-type", akamaiDefaults.InstanceSize, "the instance size of the cluster to create")
createCmd.Flags().StringVar(&dnsProviderFlag, "dns-provider", "cloudflare", fmt.Sprintf("the dns provider - one of: %s", supportedDNSProviders))
createCmd.Flags().StringVar(&subdomainNameFlag, "subdomain", "", "the subdomain to use for DNS records (Cloudflare)")
createCmd.Flags().StringVar(&domainNameFlag, "domain-name", "", "the DNS Name to use for DNS records (i.e. your-domain.com|subdomain.your-domain.com) (required)")
createCmd.MarkFlagRequired("domain-name")
createCmd.Flags().StringVar(&gitProviderFlag, "git-provider", "github", fmt.Sprintf("the git provider - one of: %s", supportedGitProviders))
createCmd.Flags().StringVar(&gitProtocolFlag, "git-protocol", "https", fmt.Sprintf("the git protocol - one of: %s", supportedGitProtocolOverride))
createCmd.Flags().StringVar(&githubOrgFlag, "github-org", "", "the GitHub organization for the new gitops and metaphor repositories - required if using github")
createCmd.Flags().StringVar(&gitlabGroupFlag, "gitlab-group", "", "the GitLab group for the new gitops and metaphor projects - required if using gitlab")
createCmd.Flags().StringVar(&gitopsTemplateBranchFlag, "gitops-template-branch", "", "the branch to clone for the gitops-template repository")
createCmd.Flags().StringVar(&gitopsTemplateURLFlag, "gitops-template-url", "https://github.com/kubefirst/gitops-template.git", "the fully qualified url to the gitops-template repository to clone")
createCmd.Flags().StringVar(&installCatalogApps, "install-catalog-apps", "", "comma seperated values to install after provision")
createCmd.Flags().BoolVar(&useTelemetryFlag, "use-telemetry", true, "whether to emit telemetry")

return createCmd
}

func Destroy() *cobra.Command {
destroyCmd := &cobra.Command{
Use: "destroy",
Short: "destroy the kubefirst platform",
Long: "destroy the kubefirst platform running in akamai and remove all resources",
RunE: common.Destroy,
// PreRun: common.CheckDocker,
}

return destroyCmd
}

func RootCredentials() *cobra.Command {
authCmd := &cobra.Command{
Use: "root-credentials",
Short: "retrieve root authentication information for platform components",
Long: "retrieve root authentication information for platform components",
RunE: common.GetRootCredentials,
}

authCmd.Flags().BoolVar(&copyArgoCDPasswordToClipboardFlag, "argocd", false, "copy the argocd password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyKbotPasswordToClipboardFlag, "kbot", false, "copy the kbot password to the clipboard (optional)")
authCmd.Flags().BoolVar(&copyVaultPasswordToClipboardFlag, "vault", false, "copy the vault password to the clipboard (optional)")

return authCmd
}
128 changes: 128 additions & 0 deletions cmd/akamai/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
Copyright (C) 2021-2023, Kubefirst
This program is licensed under MIT.
See the LICENSE file for more details.
*/
package akamai

import (
"fmt"
"os"

"github.com/kubefirst/kubefirst/internal/catalog"
"github.com/kubefirst/kubefirst/internal/cluster"
"github.com/kubefirst/kubefirst/internal/gitShim"
"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/kubefirst/internal/provision"
"github.com/kubefirst/kubefirst/internal/utilities"
"github.com/kubefirst/runtime/pkg"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func createAkamai(cmd *cobra.Command, args []string) error {
cliFlags, err := utilities.GetFlags(cmd, "akamai")
if err != nil {
progress.Error(err.Error())
return nil
}

progress.DisplayLogHints(15)

isValid, catalogApps, err := catalog.ValidateCatalogApps(cliFlags.InstallCatalogApps)
if !isValid {
return err
}

err = ValidateProvidedFlags(cliFlags.GitProvider)
if err != nil {
progress.Error(err.Error())
return nil
}

// If cluster setup is complete, return

utilities.CreateK1ClusterDirectory(clusterNameFlag)

gitAuth, err := gitShim.ValidateGitCredentials(cliFlags.GitProvider, cliFlags.GithubOrg, cliFlags.GitlabGroup)

if err != nil {
progress.Error(err.Error())
return nil
}

// Validate git
executionControl := viper.GetBool(fmt.Sprintf("kubefirst-checks.%s-credentials", cliFlags.GitProvider))
if !executionControl {
newRepositoryNames := []string{"gitops", "metaphor"}
newTeamNames := []string{"admins", "developers"}

initGitParameters := gitShim.GitInitParameters{
GitProvider: cliFlags.GitProvider,
GitToken: gitAuth.Token,
GitOwner: gitAuth.Owner,
Repositories: newRepositoryNames,
Teams: newTeamNames,
}

err = gitShim.InitializeGitProvider(&initGitParameters)
if err != nil {
progress.Error(err.Error())
return nil
}
}
viper.Set(fmt.Sprintf("kubefirst-checks.%s-credentials", cliFlags.GitProvider), true)
viper.WriteConfig()

// k3dClusterCreationComplete := viper.GetBool("launch.deployed")
// if !k3dClusterCreationComplete {
// launch.Up(nil, true, cliFlags.UseTelemetry)
// }

err = pkg.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresUrl()), "kubefirst api")
if err != nil {
progress.Error("unable to start kubefirst api")
}

provision.CreateMgmtCluster(gitAuth, cliFlags, catalogApps)

return nil
}

func ValidateProvidedFlags(gitProvider string) error {
progress.AddStep("Validate provided flags")

if os.Getenv("LINODE_TOKEN") == "" {
// telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricCloudCredentialsCheckFailed, "LINODE_TOKEN environment variable was not set")
return fmt.Errorf("your LINODE_TOKEN is not set - please set and re-run your last command")
}

// Validate required environment variables for dns provider
if dnsProviderFlag == "cloudflare" {
if os.Getenv("CF_API_TOKEN") == "" {
return fmt.Errorf("your CF_API_TOKEN environment variable is not set. Please set and try again")
}
}

// switch gitProvider {
// 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())
// }
// }

progress.CompleteStep("Validate provided flags")

return nil
}
34 changes: 16 additions & 18 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"github.com/kubefirst/kubefirst/internal/utilities"
"github.com/kubefirst/runtime/pkg"
awsinternal "github.com/kubefirst/runtime/pkg/aws"
internalssh "github.com/kubefirst/runtime/pkg/ssh"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -133,22 +131,22 @@ func ValidateProvidedFlags(gitProvider string) error {
}
}

switch gitProvider {
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 gitProvider {
// 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())
// }
// }

progress.CompleteStep("Validate provided flags")

Expand Down
2 changes: 2 additions & 0 deletions cmd/beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package cmd
import (
"fmt"

"github.com/kubefirst/kubefirst/cmd/akamai"
"github.com/kubefirst/kubefirst/cmd/google"
"github.com/kubefirst/kubefirst/cmd/k3s"
"github.com/kubefirst/kubefirst/cmd/vultr"
Expand All @@ -34,6 +35,7 @@ var betaCmd = &cobra.Command{
func init() {
cobra.OnInitialize()
betaCmd.AddCommand(
akamai.NewCommand(),
k3s.NewCommand(),
google.NewCommand(),
vultr.NewCommand(),
Expand Down
34 changes: 16 additions & 18 deletions cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/kubefirst/kubefirst/internal/provision"
"github.com/kubefirst/kubefirst/internal/utilities"
"github.com/kubefirst/runtime/pkg"
internalssh "github.com/kubefirst/runtime/pkg/ssh"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -108,22 +106,22 @@ func ValidateProvidedFlags(gitProvider string) error {
}
}

switch gitProvider {
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 gitProvider {
// 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())
// }
// }

progress.CompleteStep("Validate provided flags")

Expand Down
Loading

0 comments on commit 204a548

Please sign in to comment.