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: macrochart #1751

Merged
merged 20 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 60 additions & 13 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import (
"github.com/kubefirst/runtime/pkg/services"
internalssh "github.com/kubefirst/runtime/pkg/ssh"
"github.com/kubefirst/runtime/pkg/terraform"
runtimetypes "github.com/kubefirst/runtime/pkg/types"
utils "github.com/kubefirst/runtime/pkg/utils"
"github.com/kubefirst/runtime/pkg/vault"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -166,6 +168,16 @@ func createAws(cmd *cobra.Command, args []string) error {
awsClient := &awsinternal.AWSConfiguration{
Config: awsinternal.NewAwsV2(cloudRegionFlag),
}
creds, err := awsClient.Config.Credentials.Retrieve(aws.BackgroundContext())

if err != nil {
return err
}

viper.Set("kubefirst.state-store-creds.access-key-id", creds.AccessKeyID)
viper.Set("kubefirst.state-store-creds.secret-access-key-id", creds.SecretAccessKey)
viper.Set("kubefirst.state-store-creds.token", creds.SessionToken)
viper.WriteConfig()

_, err = awsClient.CheckAvailabilityZones(cloudRegionFlag)
if err != nil {
Expand Down Expand Up @@ -461,7 +473,9 @@ func createAws(cmd *cobra.Command, args []string) error {
log.Info().Msgf("state store bucket is %s", *kubefirstStateStoreBucket.Location)
log.Info().Msgf("artifacts bucket is %s", *kubefirstArtifactsBucket.Location)

viper.Set("kubefirst.state-store-bucket", strings.ReplaceAll(*kubefirstStateStoreBucket.Location, "/", ""))
viper.Set("kubefirst.state-store-bucket", kubefirstStateStoreBucketName)
viper.Set("kubefirst.state-store.name", kubefirstStateStoreBucketName)
viper.Set("kubefirst.state-store.hostname", "s3.amazonaws.com")
viper.Set("kubefirst.artifacts-bucket", strings.ReplaceAll(*kubefirstArtifactsBucket.Location, "/", ""))
viper.Set("kubefirst-checks.state-store-create", true)
viper.WriteConfig()
Expand Down Expand Up @@ -1432,7 +1446,7 @@ func createAws(cmd *cobra.Command, args []string) error {
consoleDeployment, err := k8s.ReturnDeploymentObject(
clientset,
"app.kubernetes.io/instance",
"kubefirst-console",
"kubefirst",
"kubefirst",
1200,
)
Expand Down Expand Up @@ -1462,20 +1476,11 @@ func createAws(cmd *cobra.Command, args []string) error {
consoleStopChannel,
)

log.Info().Msg("kubefirst installation complete")
log.Info().Msg("welcome to your new kubefirst platform powered by AWS")
time.Sleep(time.Second * 1) // allows progress bars to finish

err = pkg.IsConsoleUIAvailable(pkg.KubefirstConsoleLocalURLCloud)
if err != nil {
log.Error().Err(err).Msg("")
}

err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLCloud)
if err != nil {
log.Error().Err(err).Msg("")
}

// Mark cluster install as complete
telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricClusterInstallCompleted, "")
viper.Set("kubefirst-checks.cluster-install-complete", true)
Expand All @@ -1484,8 +1489,50 @@ func createAws(cmd *cobra.Command, args []string) error {
// Set flags used to track status of active options
helpers.SetClusterStatusFlags(awsinternal.CloudProvider, config.GitProvider)

if !ciFlag {
reports.AwsHandoffScreen(viper.GetString("components.argocd.password"), clusterNameFlag, domainNameFlag, cGitOwner, config, false)
//Export and Import Cluster
cl := utilities.CreateClusterRecordFromRaw(useTelemetryFlag, cGitOwner, cGitUser, cGitToken, cGitlabOwnerGroupID, gitopsTemplateURLFlag, gitopsTemplateBranchFlag)

var localFilePath = fmt.Sprintf("%s/%s.json", "/tmp/api/cluster/export", clusterNameFlag)
var remoteFilePath = fmt.Sprintf("%s.json", clusterNameFlag)
utilities.CreateClusterRecordFile(clusterNameFlag, cl)

pushObject := runtimetypes.PushBucketObject{
LocalFilePath: localFilePath,
RemoteFilePath: remoteFilePath,
ContentType: "application/json",
}

err = utils.PutClusterObject(&cl.StateStoreCredentials, &cl.StateStoreDetails, &pushObject)
if err != nil {
log.Error().Err(err).Msgf("error pushing cluster object, %s", cl.StateStoreDetails.Hostname)
return err
}

kubernetesConfig := runtimetypes.KubernetesClient{
Clientset: clientset,
KubeConfigPath: config.Kubeconfig,
RestConfig: restConfig,
}
err = utils.ExportCluster(kubernetesConfig, cl)
if err != nil {
log.Error().Err(err).Msg("error exporting cluster object")
viper.Set("kubefirst.setup-complete", false)
viper.Set("kubefirst-checks.cluster-install-complete", false)
viper.WriteConfig()
return err
} else {
err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLCloud)
if err != nil {
log.Error().Err(err).Msg("")
}

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

if !ciFlag {
reports.AwsHandoffScreen(viper.GetString("components.argocd.password"), clusterNameFlag, domainNameFlag, cGitOwner, config, false)
}
}

defer func(c segment.SegmentClient) {
Expand Down
63 changes: 51 additions & 12 deletions cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import (
internalssh "github.com/kubefirst/runtime/pkg/ssh"
"github.com/kubefirst/runtime/pkg/ssl"
"github.com/kubefirst/runtime/pkg/terraform"
runtimetypes "github.com/kubefirst/runtime/pkg/types"
utils "github.com/kubefirst/runtime/pkg/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -471,6 +473,7 @@ func createCivo(cmd *cobra.Command, args []string) error {
log.Info().Msg(err.Error())
}

// StateStoreCredentials
viper.Set("kubefirst.state-store-creds.access-key-id", creds.AccessKeyID)
viper.Set("kubefirst.state-store-creds.secret-access-key-id", creds.SecretAccessKeyID)
viper.Set("kubefirst.state-store-creds.name", creds.Name)
Expand Down Expand Up @@ -549,6 +552,7 @@ func createCivo(cmd *cobra.Command, args []string) error {

viper.Set("kubefirst.state-store.id", bucket.ID)
viper.Set("kubefirst.state-store.name", bucket.Name)
viper.Set("kubefirst.state-store.hostname", bucket.BucketURL)
viper.Set("kubefirst-checks.state-store-create", true)
viper.WriteConfig()
telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricStateStoreCreateCompleted, "")
Expand Down Expand Up @@ -1294,7 +1298,7 @@ func createCivo(cmd *cobra.Command, args []string) error {
consoleDeployment, err := k8s.ReturnDeploymentObject(
kcfg.Clientset,
"app.kubernetes.io/instance",
"kubefirst-console",
"kubefirst",
"kubefirst",
1200,
)
Expand Down Expand Up @@ -1324,20 +1328,11 @@ func createCivo(cmd *cobra.Command, args []string) error {
consoleStopChannel,
)

log.Info().Msg("kubefirst installation complete")
log.Info().Msg("welcome to your new kubefirst platform powered by Civo cloud")
time.Sleep(time.Second * 1) // allows progress bars to finish

err = pkg.IsConsoleUIAvailable(pkg.KubefirstConsoleLocalURLCloud)
if err != nil {
log.Error().Err(err).Msg("")
}

err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLCloud)
if err != nil {
log.Error().Err(err).Msg("")
}

// Mark cluster install as complete
telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricClusterInstallCompleted, "")
viper.Set("kubefirst-checks.cluster-install-complete", true)
Expand All @@ -1346,8 +1341,51 @@ func createCivo(cmd *cobra.Command, args []string) error {
// Set flags used to track status of active options
helpers.SetClusterStatusFlags(civo.CloudProvider, config.GitProvider)

if !ciFlag {
reports.CivoHandoffScreen(viper.GetString("components.argocd.password"), clusterNameFlag, domainNameFlag, cGitOwner, config, false)
//Export and Import Cluster
cl := utilities.CreateClusterRecordFromRaw(useTelemetryFlag, cGitOwner, cGitUser, cGitToken, cGitlabOwnerGroupID, gitopsTemplateURLFlag, gitopsTemplateBranchFlag)

var localFilePath = fmt.Sprintf("%s/%s.json", "/tmp/api/cluster/export", clusterNameFlag)
var remoteFilePath = fmt.Sprintf("%s.json", clusterNameFlag)
utilities.CreateClusterRecordFile(clusterNameFlag, cl)

pushObject := runtimetypes.PushBucketObject{
LocalFilePath: localFilePath,
RemoteFilePath: remoteFilePath,
ContentType: "application/json",
}

err = utils.PutClusterObject(&cl.StateStoreCredentials, &cl.StateStoreDetails, &pushObject)
if err != nil {
log.Error().Err(err).Msgf("error pushing cluster object, %s", cl.StateStoreDetails.Hostname)
return err
}

kubernetesConfig := runtimetypes.KubernetesClient{
Clientset: kcfg.Clientset,
KubeConfigPath: kcfg.KubeConfigPath,
RestConfig: kcfg.RestConfig,
}

err = utils.ExportCluster(kubernetesConfig, cl)
if err != nil {
log.Error().Err(err).Msg("error exporting cluster object")
viper.Set("kubefirst.setup-complete", false)
viper.Set("kubefirst-checks.cluster-install-complete", false)
viper.WriteConfig()
return err
} else {
err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLCloud)
if err != nil {
log.Error().Err(err).Msg("")
}

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

if !ciFlag {
reports.CivoHandoffScreen(viper.GetString("components.argocd.password"), clusterNameFlag, domainNameFlag, cGitOwner, config, false)
}
}

defer func(c segment.SegmentClient) {
Expand All @@ -1358,4 +1396,5 @@ func createCivo(cmd *cobra.Command, args []string) error {
}(*segmentClient)

return nil

}
60 changes: 47 additions & 13 deletions cmd/k3d/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import (
"github.com/kubefirst/runtime/pkg/services"
internalssh "github.com/kubefirst/runtime/pkg/ssh"
"github.com/kubefirst/runtime/pkg/terraform"
runtimetypes "github.com/kubefirst/runtime/pkg/types"
utils "github.com/kubefirst/runtime/pkg/utils"
"github.com/kubefirst/runtime/pkg/wrappers"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
Expand Down Expand Up @@ -1136,6 +1138,11 @@ func runK3d(cmd *cobra.Command, args []string) error {
bucketName := "kubefirst-state-store"
log.Info().Msgf("BucketName: %s", bucketName)

viper.Set("kubefirst.state-store.name", bucketName)
viper.Set("kubefirst.state-store.hostname", "minio-console.kubefirst.dev")
viper.Set("kubefirst.state-store-creds.access-key-id", pkg.MinioDefaultUsername)
viper.Set("kubefirst.state-store-creds.secret-access-key-id", pkg.MinioDefaultPassword)

// Upload the zip file with FPutObject
info, err := minioClient.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
if err != nil {
Expand Down Expand Up @@ -1327,7 +1334,7 @@ func runK3d(cmd *cobra.Command, args []string) error {
consoleDeployment, err := k8s.ReturnDeploymentObject(
kcfg.Clientset,
"app.kubernetes.io/instance",
"kubefirst-console",
"kubefirst",
"kubefirst",
600,
)
Expand All @@ -1341,7 +1348,7 @@ func runK3d(cmd *cobra.Command, args []string) error {
return err
}

//* console port-forward
// * console port-forward
consoleStopChannel := make(chan struct{}, 1)
defer func() {
close(consoleStopChannel)
Expand All @@ -1358,15 +1365,6 @@ func runK3d(cmd *cobra.Command, args []string) error {

progressPrinter.IncrementTracker("wrapping-up", 1)

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

err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLTLS)
if err != nil {
log.Error().Err(err).Msg("")
}

// Mark cluster install as complete
telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricClusterInstallCompleted, "")
viper.Set("kubefirst-checks.cluster-install-complete", true)
Expand All @@ -1375,8 +1373,44 @@ func runK3d(cmd *cobra.Command, args []string) error {
// Set flags used to track status of active options
helpers.SetClusterStatusFlags(k3d.CloudProvider, config.GitProvider)

if !ciFlag {
reports.LocalHandoffScreenV2(viper.GetString("components.argocd.password"), clusterNameFlag, gitDestDescriptor, cGitOwner, config, false)
//Export and Import Cluster
cl := utilities.CreateClusterRecordFromRaw(useTelemetryFlag, cGitOwner, cGitUser, cGitToken, cGitlabOwnerGroupID, gitopsTemplateURLFlag, gitopsTemplateBranchFlag)

var localFilePath = fmt.Sprintf("%s/%s.json", "/tmp/api/cluster/export", clusterNameFlag)
utilities.CreateClusterRecordFile(clusterNameFlag, cl)

// Upload the zip file with FPutObject
info, err = minioClient.FPutObject(ctx, bucketName, fmt.Sprintf("%s.json", clusterNameFlag), localFilePath, minio.PutObjectOptions{ContentType: "application/json"})
if err != nil {
log.Info().Msgf("Error uploading to Minio bucket: %s", err)
}

kubernetesConfig := runtimetypes.KubernetesClient{
Clientset: kcfg.Clientset,
KubeConfigPath: kcfg.KubeConfigPath,
RestConfig: kcfg.RestConfig,
}

err = utils.ExportCluster(kubernetesConfig, cl)
if err != nil {
log.Error().Err(err).Msg("error exporting cluster object")
viper.Set("kubefirst.setup-complete", false)
viper.Set("kubefirst-checks.cluster-install-complete", false)
viper.WriteConfig()
return err
} else {
err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLCloud)
if err != nil {
log.Error().Err(err).Msg("")
}

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

if !ciFlag {
reports.LocalHandoffScreenV2(viper.GetString("components.argocd.password"), clusterNameFlag, gitDestDescriptor, cGitOwner, config, false)
}
}

defer func(c segment.SegmentClient) {
Expand Down
5 changes: 5 additions & 0 deletions cmd/vultr/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,11 @@ func createVultr(cmd *cobra.Command, args []string) error {
tfEntrypoint := config.GitopsDir + "/terraform/github"
tfEnvs := map[string]string{}
tfEnvs = vultr.GetGithubTerraformEnvs(config, tfEnvs)
// Erase public key to prevent it from being created if the git protocol argument is set to htps
switch config.GitProtocol {
case "https":
tfEnvs["TF_VAR_kbot_ssh_public_key"] = ""
}
err := terraform.InitApplyAutoApprove(config.TerraformClient, tfEntrypoint, tfEnvs)
if err != nil {
msg := fmt.Sprintf("error creating github resources with terraform %s: %s", tfEntrypoint, err)
Expand Down
6 changes: 2 additions & 4 deletions 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.9
github.com/kubefirst/runtime v0.3.12
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
go.mongodb.org/mongo-driver v1.10.0
k8s.io/api v0.26.2
k8s.io/apimachinery v0.27.1
k8s.io/client-go v11.0.1-0.20190816222228-6d55c1b1f1ca+incompatible
Expand Down Expand Up @@ -107,15 +108,13 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-github/v45 v45.2.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/go-version v1.2.1 // indirect
github.com/jedib0t/go-pretty/v6 v6.4.6 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down Expand Up @@ -166,7 +165,6 @@ require (
github.com/xlab/treeprint v1.1.0 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.mongodb.org/mongo-driver v1.10.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.11.0 // indirect
Expand Down
Loading