Skip to content

Commit

Permalink
fix: error handling (#1859)
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 authored Oct 23, 2023
1 parent 8dcd21e commit b8e25d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
12 changes: 6 additions & 6 deletions cmd/k3d/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ func runK3d(cmd *cobra.Command, args []string) error {
"app.kubernetes.io/instance",
"argo",
"argo",
600,
1200,
)
if err != nil {
log.Error().Msgf("Error finding argo workflows Deployment: %s", err)
Expand All @@ -1376,11 +1376,6 @@ func runK3d(cmd *cobra.Command, args []string) error {
return err
}

// Mark cluster install as complete
telemetry.SendEvent(segClient, telemetry.ClusterInstallCompleted, "")
viper.Set("kubefirst-checks.cluster-install-complete", true)
viper.WriteConfig()

// Set flags used to track status of active options
helpers.SetClusterStatusFlags(k3d.CloudProvider, config.GitProvider)

Expand Down Expand Up @@ -1417,6 +1412,11 @@ func runK3d(cmd *cobra.Command, args []string) error {
log.Error().Err(err).Msg("")
}

// Mark cluster install as complete
telemetry.SendEvent(segClient, telemetry.ClusterInstallCompleted, "")
viper.Set("kubefirst-checks.cluster-install-complete", true)
viper.WriteConfig()

log.Info().Msg("kubefirst installation complete")
log.Info().Msg("welcome to your new kubefirst platform running in K3d")
time.Sleep(time.Second * 1) // allows progress bars to finish
Expand Down
14 changes: 9 additions & 5 deletions cmd/k3d/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"time"

"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/runtime/pkg"
gitlab "github.com/kubefirst/runtime/pkg/gitlab"
"github.com/kubefirst/runtime/pkg/helpers"
Expand All @@ -30,11 +31,13 @@ func destroyK3d(cmd *cobra.Command, args []string) error {

// Determine if there are active installs
gitProvider := viper.GetString("flags.git-provider")
clusterName := viper.GetString("flags.cluster-name")
gitProtocol := viper.GetString("flags.git-protocol")
// _, err := helpers.EvalDestroy(k3d.CloudProvider, gitProvider)
// if err != nil {
// return err
// }

if clusterName == "" {
fmt.Printf("Your kubefirst platform running has been already destroyed.")
progress.Progress.Quit()
}

// Check for existing port forwards before continuing
err := k8s.CheckForExistingPortForwards(9000)
Expand All @@ -49,7 +52,6 @@ func destroyK3d(cmd *cobra.Command, args []string) error {

log.Info().Msg("destroying kubefirst platform running in k3d")

clusterName := viper.GetString("flags.cluster-name")
atlantisWebhookURL := fmt.Sprintf("%s/events", viper.GetString("ngrok.host"))

// Switch based on git provider, set params
Expand Down Expand Up @@ -240,6 +242,7 @@ func destroyK3d(cmd *cobra.Command, args []string) error {
viper.Set("kbot", "")
viper.Set("kubefirst-checks", "")
viper.Set("kubefirst", "")
viper.Set("flags", "")
viper.WriteConfig()
}

Expand All @@ -251,6 +254,7 @@ func destroyK3d(cmd *cobra.Command, args []string) error {
}
time.Sleep(time.Millisecond * 200) // allows progress bars to finish
fmt.Printf("Your kubefirst platform running in %s has been destroyed.", k3d.CloudProvider)
progress.Progress.Quit()

return nil
}
7 changes: 7 additions & 0 deletions internal/utilities/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func ExportCluster(cluster apiTypes.Cluster, kcfg *k8s.KubernetesClient) error {
cluster.Status = "provisioned"
cluster.InProgress = false

if viper.GetBool("kubefirst-checks.secret-export-state") {
return nil
}

time.Sleep(time.Second * 10)

payload, err := json.Marshal(cluster)
Expand All @@ -223,5 +227,8 @@ func ExportCluster(cluster apiTypes.Cluster, kcfg *k8s.KubernetesClient) error {
return errors.New(fmt.Sprintf("unable to save secret to management cluster. %s", err))
}

viper.Set("kubefirst-checks.secret-export-state", true)
viper.WriteConfig()

return nil
}

0 comments on commit b8e25d4

Please sign in to comment.