Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: round out gcp #1779

Merged
merged 12 commits into from
Aug 29, 2023
8 changes: 5 additions & 3 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ func createAws(cmd *cobra.Command, args []string) error {
externalDNSProviderTokenEnvName = "CF_API_TOKEN"
externalDNSProviderSecretKey = "cf-api-token"
} else {
externalDNSProviderTokenEnvName = "CIVO_TOKEN"
externalDNSProviderSecretKey = fmt.Sprintf("%s-token", awsinternal.CloudProvider)
externalDNSProviderTokenEnvName = "AWS_AUTH"
externalDNSProviderSecretKey = fmt.Sprintf("%s-auth", awsinternal.CloudProvider)
}

// Swap tokens for git protocol
Expand Down Expand Up @@ -642,7 +642,7 @@ func createAws(cmd *cobra.Command, args []string) error {

ExternalDNSProviderName: dnsProviderFlag,
ExternalDNSProviderTokenEnvName: externalDNSProviderTokenEnvName,
ExternalDNSProviderSecretName: fmt.Sprintf("%s-creds", awsinternal.CloudProvider),
ExternalDNSProviderSecretName: fmt.Sprintf("%s-auth", awsinternal.CloudProvider),
ExternalDNSProviderSecretKey: externalDNSProviderSecretKey,

ArgoCDIngressURL: fmt.Sprintf("https://argocd.%s", domainNameFlag),
Expand Down Expand Up @@ -1146,6 +1146,8 @@ func createAws(cmd *cobra.Command, args []string) error {
clientset,
ecrFlag,
containerRegistryURL,
dnsProviderFlag,
gitopsDirectoryTokens.CloudProvider,
)
if err != nil {
log.Info().Msg("Error adding kubernetes secrets for bootstrap")
Expand Down
6 changes: 4 additions & 2 deletions cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func createCivo(cmd *cobra.Command, args []string) error {
externalDNSProviderSecretKey = "cf-api-token"
} else {
externalDNSProviderTokenEnvName = "CIVO_TOKEN"
externalDNSProviderSecretKey = fmt.Sprintf("%s-token", civo.CloudProvider)
externalDNSProviderSecretKey = fmt.Sprintf("%s-auth", civo.CloudProvider)
}

// Swap tokens for git protocol; used by tokens, argocd registry object, and secret bootstrapping for argo template credentials
Expand Down Expand Up @@ -346,7 +346,7 @@ func createCivo(cmd *cobra.Command, args []string) error {

ExternalDNSProviderName: dnsProviderFlag,
ExternalDNSProviderTokenEnvName: externalDNSProviderTokenEnvName,
ExternalDNSProviderSecretName: fmt.Sprintf("%s-creds", civo.CloudProvider),
ExternalDNSProviderSecretName: fmt.Sprintf("%s-auth", civo.CloudProvider),
ExternalDNSProviderSecretKey: externalDNSProviderSecretKey,

ArgoCDIngressURL: fmt.Sprintf("https://argocd.%s", domainNameFlag),
Expand Down Expand Up @@ -963,6 +963,8 @@ func createCivo(cmd *cobra.Command, args []string) error {
os.Getenv("CF_API_TOKEN"),
gitopsRepoURL,
config.GitProtocol,
dnsProviderFlag,
gitopsDirectoryTokens.CloudProvider,
)
if err != nil {
log.Info().Msg("Error adding kubernetes secrets for bootstrap")
Expand Down
6 changes: 4 additions & 2 deletions cmd/digitalocean/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func createDigitalocean(cmd *cobra.Command, args []string) error {
externalDNSProviderSecretKey = "cf-api-token"
} else {
externalDNSProviderTokenEnvName = "DO_TOKEN"
externalDNSProviderSecretKey = fmt.Sprintf("%s-token", digitalocean.CloudProvider)
externalDNSProviderSecretKey = fmt.Sprintf("%s-auth", digitalocean.CloudProvider)
}

// Swap tokens for git protocol
Expand Down Expand Up @@ -344,7 +344,7 @@ func createDigitalocean(cmd *cobra.Command, args []string) error {

ExternalDNSProviderName: dnsProviderFlag,
ExternalDNSProviderTokenEnvName: externalDNSProviderTokenEnvName,
ExternalDNSProviderSecretName: fmt.Sprintf("%s-creds", digitalocean.CloudProvider),
ExternalDNSProviderSecretName: fmt.Sprintf("%s-auth", digitalocean.CloudProvider),
ExternalDNSProviderSecretKey: externalDNSProviderSecretKey,

ArgoCDIngressURL: fmt.Sprintf("https://argocd.%s", domainNameFlag),
Expand Down Expand Up @@ -953,6 +953,8 @@ func createDigitalocean(cmd *cobra.Command, args []string) error {
os.Getenv("CF_API_TOKEN"),
gitopsRepoURL,
config.GitProtocol,
dnsProviderFlag,
gitopsDirectoryTokens.CloudProvider,
)
if err != nil {
log.Info().Msg("Error adding kubernetes secrets for bootstrap")
Expand Down
4 changes: 2 additions & 2 deletions cmd/gcp/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
copyVaultPasswordToClipboardFlag bool

// Supported providers
supportedDNSProviders = []string{"gcp", "cloudflare"}
supportedDNSProviders = []string{"google", "cloudflare"}
supportedGitProviders = []string{"github", "gitlab"}

// Supported git providers
Expand Down Expand Up @@ -87,7 +87,7 @@ func Create() *cobra.Command {
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().BoolVar(&useTelemetryFlag, "use-telemetry", true, "whether to emit telemetry")
createCmd.Flags().BoolVar(&forceDestroyFlag, "force_destroy", false, "allows force destruction on objects (helpful for test environments, defaults to false)")
createCmd.Flags().BoolVar(&forceDestroyFlag, "force-destroy", false, "allows force destruction on objects (helpful for test environments, defaults to false)")
return createCmd
}

Expand Down
47 changes: 26 additions & 21 deletions cmd/gcp/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/kubefirst/runtime/pkg/vault"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/thanhpk/randstr"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth"
Expand Down Expand Up @@ -87,7 +88,7 @@ func createGCP(cmd *cobra.Command, args []string) error {
return err
}

forceDestroy, err := cmd.Flags().GetBool("force_destroy")
forceDestroy, err := cmd.Flags().GetBool("force-destroy")
if err != nil {
return err
}
Expand Down Expand Up @@ -307,6 +308,15 @@ func createGCP(cmd *cobra.Command, args []string) error {
kubefirstTeam = "false"
}

var externalDNSProviderTokenEnvName, externalDNSProviderSecretKey string
if dnsProviderFlag == "cloudflare" {
externalDNSProviderTokenEnvName = "CF_API_TOKEN"
externalDNSProviderSecretKey = "cf-api-token"
} else {
externalDNSProviderTokenEnvName = "GOOGLE_AUTH"
externalDNSProviderSecretKey = fmt.Sprintf("%s-auth", dnsProviderFlag)
}

// Swap tokens for git protocol
var gitopsRepoURL string
switch config.GitProtocol {
Expand All @@ -331,8 +341,10 @@ func createGCP(cmd *cobra.Command, args []string) error {
KubefirstTeam: kubefirstTeam,
KubefirstVersion: configs.K1Version,

GCPAuth: config.GCPAuth,
GCPProject: gcpProjectFlag,
GCPAuth: config.GCPAuth,
GCPProject: gcpProjectFlag,
GoogleUniqueness: strings.ToLower(randstr.String(5)),
ForceDestroy: strconv.FormatBool(forceDestroy),

ArgoCDIngressURL: fmt.Sprintf("https://argocd.%s", domainNameFlag),
ArgoCDIngressNoHTTPSURL: fmt.Sprintf("argocd.%s", domainNameFlag),
Expand All @@ -346,6 +358,11 @@ func createGCP(cmd *cobra.Command, args []string) error {
VaultDataBucketName: fmt.Sprintf("%s-vault-data-%s", gcpProjectFlag, clusterNameFlag),
VouchIngressURL: fmt.Sprintf("https://vouch.%s", domainNameFlag),

ExternalDNSProviderName: dnsProviderFlag,
ExternalDNSProviderTokenEnvName: externalDNSProviderTokenEnvName,
ExternalDNSProviderSecretName: fmt.Sprintf("%s-auth", dnsProviderFlag),
ExternalDNSProviderSecretKey: externalDNSProviderSecretKey,

GitDescription: fmt.Sprintf("%s hosted git", config.GitProvider),
GitNamespace: "N/A",
GitProvider: config.GitProvider,
Expand All @@ -369,7 +386,7 @@ func createGCP(cmd *cobra.Command, args []string) error {
GitopsRepoNoHTTPSURL: fmt.Sprintf("%s.com/%s/gitops.git", cGitHost, cGitOwner),
ClusterId: clusterId,

ContainerRegistryURL: fmt.Sprintf("%s/%s/metaphor", containerRegistryHost, cGitOwner),
ContainerRegistryURL: fmt.Sprintf("%s/%s", containerRegistryHost, cGitOwner),
}

viper.Set(fmt.Sprintf("%s.atlantis.webhook.url", config.GitProvider), fmt.Sprintf("https://atlantis.%s/events", domainNameFlag))
Expand Down Expand Up @@ -603,7 +620,8 @@ func createGCP(cmd *cobra.Command, args []string) error {
}

log.Info().Msg("validation and kubefirst cli environment check is complete")

progressPrinter.IncrementTracker("preflight-checks", 1)
progressPrinter.IncrementTracker("preflight-checks", 1)
telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricInitCompleted, "")
telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricClusterInstallStarted, "")

Expand Down Expand Up @@ -650,7 +668,7 @@ func createGCP(cmd *cobra.Command, args []string) error {
metaphorDirectoryTokens := providerConfigs.MetaphorTokenValues{
ClusterName: clusterNameFlag,
CloudRegion: cloudRegionFlag,
ContainerRegistryURL: fmt.Sprintf("%s/%s/metaphor", containerRegistryHost, cGitOwner),
ContainerRegistryURL: fmt.Sprintf("%s/%s", containerRegistryHost, cGitOwner),
DomainName: domainNameFlag,
MetaphorDevelopmentIngressURL: fmt.Sprintf("metaphor-development.%s", domainNameFlag),
MetaphorStagingIngressURL: fmt.Sprintf("metaphor-staging.%s", domainNameFlag),
Expand All @@ -671,20 +689,6 @@ func createGCP(cmd *cobra.Command, args []string) error {
viper.Set(fmt.Sprintf("%s.repos.gitops.git-url", config.GitProvider), config.DestinationGitopsRepoURL)
viper.WriteConfig()

var externalDNSProviderTokenEnvName, externalDNSProviderSecretKey string
if dnsProviderFlag == "cloudflare" {
externalDNSProviderTokenEnvName = "CF_API_TOKEN"
externalDNSProviderSecretKey = "cf-api-token"
} else {
externalDNSProviderTokenEnvName = "GCP_AUTH"
externalDNSProviderSecretKey = fmt.Sprintf("google_application_credentials")
}

gitopsDirectoryTokens.ExternalDNSProviderName = dnsProviderFlag
gitopsDirectoryTokens.ExternalDNSProviderTokenEnvName = externalDNSProviderTokenEnvName
gitopsDirectoryTokens.ExternalDNSProviderSecretName = fmt.Sprintf("%s-creds", gcp.CloudProvider)
gitopsDirectoryTokens.ExternalDNSProviderSecretKey = externalDNSProviderSecretKey

// Determine if anything exists at domain apex
apexContentExists := gcp.GetDomainApexContent(domainNameFlag)

Expand Down Expand Up @@ -871,7 +875,6 @@ func createGCP(cmd *cobra.Command, args []string) error {
a, _ := os.ReadFile(config.GCPAuth)
tfEnvs["GOOGLE_CLOUD_KEYFILE_JSON"] = string(a)
tfEnvs["TF_VAR_project"] = gcpProjectFlag
tfEnvs["TF_VAR_force_destroy"] = strconv.FormatBool(forceDestroy)
tfEntrypoint := config.GitopsDir + "/terraform/gcp/services"
err = terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs)
if err != nil {
Expand Down Expand Up @@ -943,6 +946,8 @@ func createGCP(cmd *cobra.Command, args []string) error {
config.GitProtocol,
os.Getenv("CF_API_TOKEN"),
config.GCPAuth,
dnsProviderFlag,
gitopsDirectoryTokens.CloudProvider,
)

if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions cmd/gcp/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func destroyGCP(cmd *cobra.Command, args []string) error {
// Determine if there are active installs
gitProvider := viper.GetString("flags.git-provider")
gitProtocol := viper.GetString("flags.git-protocol")
forceDestroy := viper.GetBool("flags.force_destroy")
// _, err := helpers.EvalDestroy(gcp.CloudProvider, gitProvider)
// if err != nil {
// return err
Expand Down Expand Up @@ -168,7 +167,6 @@ func destroyGCP(cmd *cobra.Command, args []string) error {
tfEnvs["GITLAB_TOKEN"] = cGitToken
tfEnvs["GOOGLE_CLOUD_KEYFILE_JSON"] = string(a)
tfEnvs["TF_VAR_project"] = gcpProject
tfEnvs["TF_VAR_force_destroy"] = strconv.FormatBool(forceDestroy)
err = terraform.InitDestroyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs)
if err != nil {
log.Printf("error executing terraform destroy %s", tfEntrypoint)
Expand Down
2 changes: 2 additions & 0 deletions cmd/k3d/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ func runK3d(cmd *cobra.Command, args []string) error {
//* git clone and detokenize the gitops repository
// todo improve this logic for removing `kubefirst clean`
// if !viper.GetBool("template-repo.gitops.cloned") || viper.GetBool("template-repo.gitops.removed") {
progressPrinter.IncrementTracker("preflight-checks", 1)
progressPrinter.IncrementTracker("preflight-checks", 1)
progressPrinter.AddTracker("cloning-and-formatting-git-repositories", "Cloning and formatting git repositories", 1)
progressPrinter.SetupProgress(progressPrinter.TotalOfTrackers(), false)
if !viper.GetBool("kubefirst-checks.gitops-ready-to-push") {
Expand Down
6 changes: 4 additions & 2 deletions cmd/vultr/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func createVultr(cmd *cobra.Command, args []string) error {
externalDNSProviderSecretKey = "cf-api-token"
} else {
externalDNSProviderTokenEnvName = "VULTR_API_KEY"
externalDNSProviderSecretKey = fmt.Sprintf("%s-token", vultr.CloudProvider)
externalDNSProviderSecretKey = fmt.Sprintf("%s-auth", vultr.CloudProvider)
}

// Swap tokens for git protocol
Expand Down Expand Up @@ -343,7 +343,7 @@ func createVultr(cmd *cobra.Command, args []string) error {

ExternalDNSProviderName: dnsProviderFlag,
ExternalDNSProviderTokenEnvName: externalDNSProviderTokenEnvName,
ExternalDNSProviderSecretName: fmt.Sprintf("%s-creds", vultr.CloudProvider),
ExternalDNSProviderSecretName: fmt.Sprintf("%s-auth", vultr.CloudProvider),
ExternalDNSProviderSecretKey: externalDNSProviderSecretKey,

ArgoCDIngressURL: fmt.Sprintf("https://argocd.%s", domainNameFlag),
Expand Down Expand Up @@ -952,6 +952,8 @@ func createVultr(cmd *cobra.Command, args []string) error {
os.Getenv("CF_API_TOKEN"),
gitopsRepoURL,
config.GitProtocol,
dnsProviderFlag,
gitopsDirectoryTokens.CloudProvider,
)
if err != nil {
log.Info().Msg("Error adding kubernetes secrets for bootstrap")
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ require (
github.com/dustin/go-humanize v1.0.1
github.com/go-git/go-git/v5 v5.6.1
github.com/hashicorp/vault/api v1.9.0
github.com/kubefirst/runtime v0.3.12
github.com/kubefirst/runtime v0.3.13
github.com/rs/zerolog v1.29.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
github.com/thanhpk/randstr v1.0.6
go.mongodb.org/mongo-driver v1.10.0
k8s.io/api v0.26.2
k8s.io/apimachinery v0.27.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubefirst/runtime v0.3.12 h1:C1k81WNQt59teLN6/CgQgaITz/Js2flOTkcyF8pYB1Y=
github.com/kubefirst/runtime v0.3.12/go.mod h1:NUa8VcB99UKEwVUvhdCfiuEYQI44XfGFV2pBtX8YnVo=
github.com/kubefirst/runtime v0.3.13 h1:Efp1ZKz1QrQsvVm84lQjEOpDReJ07YBqDlNGF65AJA8=
github.com/kubefirst/runtime v0.3.13/go.mod h1:NUa8VcB99UKEwVUvhdCfiuEYQI44XfGFV2pBtX8YnVo=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo=
Expand Down Expand Up @@ -1080,6 +1080,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 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
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=
Expand Down