Skip to content

Commit

Permalink
fix: config version
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 committed Mar 13, 2024
1 parent e1238a5 commit ae0e4a2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 147 deletions.
9 changes: 5 additions & 4 deletions cmd/akamai/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/kubefirst/kubefirst/internal/catalog"
"github.com/kubefirst/kubefirst/internal/cluster"
"github.com/kubefirst/kubefirst/internal/gitShim"
"github.com/kubefirst/kubefirst/internal/launch"
"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/kubefirst/internal/provision"
"github.com/kubefirst/kubefirst/internal/utilities"
Expand Down Expand Up @@ -75,10 +76,10 @@ func createAkamai(cmd *cobra.Command, args []string) error {
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)
// }
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 {
Expand Down
18 changes: 0 additions & 18 deletions configs/config.go

This file was deleted.

107 changes: 0 additions & 107 deletions configs/viperConfig.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"strings"

"github.com/kubefirst/kubefirst-api/pkg/providerConfigs"
"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/cluster"
"github.com/kubefirst/kubefirst/internal/launch"
"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/runtime/configs"
"github.com/kubefirst/runtime/pkg/docker"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down
14 changes: 11 additions & 3 deletions internal/progress/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ func DisplaySuccessMessage(cluster types.Cluster) successMsg {

}

var fullDomainName string

if cluster.SubdomainName != "" {
fullDomainName = fmt.Sprintf("%s.%s", cluster.SubdomainName, cluster.DomainName)
} else {
fullDomainName = cluster.DomainName
}

success := `
##
#### :tada: Success` + "`Cluster " + cluster.ClusterName + " is now up and running`" + `
Expand All @@ -125,11 +133,11 @@ func DisplaySuccessMessage(cluster types.Cluster) successMsg {
### Repos ` + fmt.Sprintf("`https://%s.com/%s/gitops` \n\n", cluster.GitProvider, cluster.GitAuth.Owner) +
fmt.Sprintf("` https://%s.com/%s/metaphor`", cluster.GitProvider, cluster.GitAuth.Owner) + `
## Kubefirst Console
### URL ` + fmt.Sprintf("`https://kubefirst.%s`", cluster.DomainName) + `
### URL ` + fmt.Sprintf("`https://kubefirst.%s`", fullDomainName) + `
## Argo CD
### URL ` + fmt.Sprintf("`https://argocd.%s`", cluster.DomainName) + `
### URL ` + fmt.Sprintf("`https://argocd.%s`", fullDomainName) + `
## Vault
### URL ` + fmt.Sprintf("`https://vault.%s`", cluster.DomainName) + `
### URL ` + fmt.Sprintf("`https://vault.%s`", fullDomainName) + `
### :bulb: Quick start examples:
Expand Down
2 changes: 1 addition & 1 deletion internal/segment/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"os"

"github.com/denisbrodbeck/machineid"
"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/configs"
"github.com/kubefirst/runtime/pkg/k3d"
)

Expand Down
48 changes: 35 additions & 13 deletions internal/utilities/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package utilities
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand All @@ -18,9 +17,9 @@ import (
"time"

apiTypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/kubefirst/internal/types"
"github.com/kubefirst/runtime/configs"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
Expand All @@ -45,10 +44,6 @@ func CreateK1ClusterDirectory(clusterName string) {
}
}

const (
exportFilePath = "/tmp/api/cluster/export"
)

func CreateClusterRecordFromRaw(
useTelemetry bool,
gitOwner string,
Expand Down Expand Up @@ -238,24 +233,23 @@ func ExportCluster(cluster apiTypes.Cluster, kcfg *k8s.KubernetesClient) error {

time.Sleep(time.Second * 10)

payload, err := json.Marshal(cluster)
bytes, err := json.Marshal(cluster)
if err != nil {
log.Error().Msg(err.Error())
return err
}

secretValuesMap, _ := ParseJSONToMap(string(bytes))

secret := &v1secret.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "mongodb-state", Namespace: "kubefirst"},
Data: map[string][]byte{
"cluster-0": []byte(payload),
"cluster-name": []byte(cluster.ClusterName),
},
ObjectMeta: metav1.ObjectMeta{Name: "kubefirst-initial-state", Namespace: "kubefirst"},
Data: secretValuesMap,
}

err = k8s.CreateSecretV2(kcfg.Clientset, secret)

if err != nil {
return errors.New(fmt.Sprintf("unable to save secret to management cluster. %s", err))
return fmt.Errorf(fmt.Sprintf("unable to save secret to management cluster. %s", err))
}

viper.Set("kubefirst-checks.secret-export-state", true)
Expand Down Expand Up @@ -296,3 +290,31 @@ func ConsumeStream(url string) {
return
}
}

func ParseJSONToMap(jsonStr string) (map[string][]byte, error) {
var result map[string]interface{}
err := json.Unmarshal([]byte(jsonStr), &result)
if err != nil {
return nil, err
}

secretData := make(map[string][]byte)
for key, value := range result {
switch v := value.(type) {
case map[string]interface{}, []interface{}: // For nested structures, marshal back to JSON
bytes, err := json.Marshal(v)
if err != nil {
return nil, err
}
secretData[key] = bytes
default:
bytes, err := json.Marshal(v)
if err != nil {
return nil, err
}
secretData[key] = bytes
}
}

return secretData, nil
}

0 comments on commit ae0e4a2

Please sign in to comment.