From 4b7ee62f16f8fa24c6687f7b55ce86b51d3d9011 Mon Sep 17 00:00:00 2001 From: CristhianF7 Date: Wed, 25 Oct 2023 20:24:16 -0500 Subject: [PATCH] fix: cloudflare token, error handling for cluster creation --- internal/cluster/cluster.go | 10 +++++----- internal/common/common.go | 3 ++- internal/provision/provision.go | 4 ++-- internal/utilities/utilities.go | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/cluster/cluster.go b/internal/cluster/cluster.go index ba8a11b56..0f6e5fff4 100644 --- a/internal/cluster/cluster.go +++ b/internal/cluster/cluster.go @@ -58,11 +58,6 @@ func CreateCluster(cluster apiTypes.ClusterDefinition) error { return err } - if res.StatusCode != http.StatusOK { - log.Info().Msgf("unable to create cluster %s", res.Status) - return err - } - body, err := io.ReadAll(res.Body) if err != nil { log.Info().Msgf("unable to create cluster %s", err) @@ -70,6 +65,11 @@ func CreateCluster(cluster apiTypes.ClusterDefinition) error { return err } + if res.StatusCode != http.StatusOK { + log.Info().Msgf("unable to create cluster %s %s", res.Status, body) + return fmt.Errorf("unable to create cluster %s %s", res.Status, body) + } + log.Info().Msgf("Created cluster: %s", string(body)) return nil diff --git a/internal/common/common.go b/internal/common/common.go index 2da45bc19..75c425ef3 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -116,6 +116,7 @@ func Destroy(cmd *cobra.Command, args []string) error { // Determine if there are active instal ls gitProvider := viper.GetString("flags.git-provider") gitProtocol := viper.GetString("flags.git-protocol") + cloudProvider := viper.GetString("kubefirst.cloud-provider") log.Info().Msg("destroying kubefirst platform") @@ -177,7 +178,7 @@ func Destroy(cmd *cobra.Command, args []string) error { #### :tada: Success` + "`Your K3D kubefirst platform has been destroyed.`" + ` ### :blue_book: To delete a management cluster please see documentation: -https://docs.kubefirst.io/aws/deprovision +https://docs.kubefirst.io/` + cloudProvider + `/deprovision ` progress.Success(successMessage) diff --git a/internal/provision/provision.go b/internal/provision/provision.go index e4a715320..5256818a9 100644 --- a/internal/provision/provision.go +++ b/internal/provision/provision.go @@ -27,9 +27,9 @@ func CreateMgmtCluster(gitAuth runtimeTypes.GitAuth, cliFlags types.CliFlags) { } if !clusterCreated.InProgress { - err := cluster.CreateCluster(clusterRecord) + err = cluster.CreateCluster(clusterRecord) if err != nil { - progress.Error("Unable to create the cluster") + progress.Error(err.Error()) } } diff --git a/internal/utilities/utilities.go b/internal/utilities/utilities.go index be088aef5..a60d4f3ee 100644 --- a/internal/utilities/utilities.go +++ b/internal/utilities/utilities.go @@ -153,7 +153,7 @@ func CreateClusterDefinitionRecordFromRaw(gitAuth apiTypes.GitAuth, cliFlags typ PrivateKey: viper.GetString("kbot.private-key"), }, CloudflareAuth: apiTypes.CloudflareAuth{ - Token: os.Getenv("CF_API_TOKEN"), + APIToken: os.Getenv("CF_API_TOKEN"), }, }