Skip to content

Commit

Permalink
pulls latest remote adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
jarededwards committed Oct 22, 2023
1 parent 66cef8e commit 4e5a38d
Show file tree
Hide file tree
Showing 26 changed files with 69 additions and 174 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,5 @@ replace (
k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.24.2
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.24.2
)

replace github.com/kubefirst/metrics-client => /Users/jared/git/kubefirst/github/metrics-client
12 changes: 5 additions & 7 deletions internal/controller/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

argocdapi "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
awsext "github.com/kubefirst/kubefirst-api/extensions/aws"
"github.com/kubefirst/kubefirst-api/pkg/metrics"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg"
"github.com/kubefirst/runtime/pkg/argocd"
Expand Down Expand Up @@ -57,16 +56,16 @@ func (clctrl *ClusterController) InstallArgoCD() error {
argoCDInstallPath := fmt.Sprintf("github.com:kubefirst/manifests/argocd/cloud?ref=%s", pkg.KubefirstManifestRepoRef)
log.Infof("installing argocd")

telemetry.SendCountMetric(clctrl.Telemetry, metrics.ArgoCDInstallStarted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.ArgoCDInstallStarted, err.Error())
err = argocd.ApplyArgoCDKustomize(kcfg.Clientset, argoCDInstallPath)
if err != nil {

telemetry.SendCountMetric(clctrl.Telemetry, metrics.ArgoCDInstallFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.ArgoCDInstallFailed, err.Error())

return err
}

telemetry.SendCountMetric(clctrl.Telemetry, metrics.ArgoCDInstallCompleted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.ArgoCDInstallCompleted, err.Error())

// Wait for ArgoCD to be ready
_, err = k8s.VerifyArgoCDReadiness(kcfg.Clientset, true, 300)
Expand Down Expand Up @@ -179,7 +178,6 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {
return err
}


if !cl.ArgoCDCreateRegistryCheck {
var kcfg *k8s.KubernetesClient

Expand All @@ -196,7 +194,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {
}
}

telemetry.SendCountMetric(clctrl.Telemetry, metrics.CreateRegistryStarted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CreateRegistryStarted, err.Error())
argocdClient, err := argocdapi.NewForConfig(kcfg.RestConfig)
if err != nil {
return err
Expand Down Expand Up @@ -241,7 +239,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {

_, _ = argocdClient.ArgoprojV1alpha1().Applications("argocd").Create(context.Background(), registryApplicationObject, metav1.CreateOptions{})

telemetry.SendCountMetric(clctrl.Telemetry, metrics.CreateRegistryCompleted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CreateRegistryCompleted, err.Error())

err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "argocd_create_registry_check", true)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions internal/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
terraformext "github.com/kubefirst/kubefirst-api/extensions/terraform"
vultrext "github.com/kubefirst/kubefirst-api/extensions/vultr"
gitShim "github.com/kubefirst/kubefirst-api/internal/gitShim"
"github.com/kubefirst/kubefirst-api/pkg/metrics"
"github.com/kubefirst/kubefirst-api/pkg/providerConfigs"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/metrics-client/pkg/telemetry"
Expand Down Expand Up @@ -51,7 +50,7 @@ func (clctrl *ClusterController) CreateCluster() error {
tfEntrypoint := clctrl.ProviderConfig.GitopsDir + fmt.Sprintf("/terraform/%s", clctrl.CloudProvider)
tfEnvs := map[string]string{}

telemetry.SendCountMetric(clctrl.Telemetry, metrics.CloudTerraformApplyStarted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CloudTerraformApplyStarted, err.Error())

log.Infof("creating %s cluster", clctrl.CloudProvider)

Expand Down Expand Up @@ -87,12 +86,12 @@ func (clctrl *ClusterController) CreateCluster() error {
if err != nil {
return err
}
telemetry.SendCountMetric(clctrl.Telemetry, metrics.CloudTerraformApplyFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CloudTerraformApplyFailed, err.Error())
return fmt.Errorf(msg)
}

log.Infof("created %s cloud resources", clctrl.CloudProvider)
telemetry.SendCountMetric(clctrl.Telemetry, metrics.CloudTerraformApplyCompleted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.CloudTerraformApplyCompleted, err.Error())

err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "cloud_terraform_apply_failed_check", false)
if err != nil {
Expand Down
20 changes: 9 additions & 11 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/kubefirst/kubefirst-api/internal/utils"
google "github.com/kubefirst/kubefirst-api/pkg/google"
"github.com/kubefirst/kubefirst-api/pkg/handlers"
"github.com/kubefirst/kubefirst-api/pkg/metrics"
"github.com/kubefirst/kubefirst-api/pkg/providerConfigs"
"github.com/kubefirst/kubefirst-api/pkg/segment"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
Expand Down Expand Up @@ -107,8 +106,7 @@ type ClusterController struct {
MdbCl *db.MongoDBClient

// Telemetry
Telemetry *telemetry.SegmentClient
UseTelemetry bool
SegmentClient *telemetry.SegmentClient

// Provider clients
AwsClient *awsinternal.AWSConfiguration
Expand Down Expand Up @@ -149,9 +147,9 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)
}

if os.Getenv("USE_TELEMETRY") == "false" {
clctrl.UseTelemetry = false
clctrl.SegmentClient.UseTelemetry = false
} else {
clctrl.UseTelemetry = true
clctrl.SegmentClient.UseTelemetry = true
}

// Telemetry handle
Expand All @@ -172,7 +170,7 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)
MachineID: machineID,
ErrorMessage: "",
UserId: machineID,
MetricName: metrics.ClusterInstallStarted,
MetricName: telemetry.ClusterInstallStarted,
},
Client: analytics.New(segment.SegmentIOWriteKey),
}
Expand All @@ -181,8 +179,8 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)
}
defer segClient.Client.Close()

if clctrl.UseTelemetry {
telemetry.SendCountMetric(&segClient, metrics.ClusterInstallStarted, err.Error())
if clctrl.SegmentClient.UseTelemetry {
telemetry.SendCountMetric(&segClient, telemetry.ClusterInstallStarted, err.Error())
}
clctrl.Telemetry = &segClient

Expand Down Expand Up @@ -293,16 +291,16 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)
}

if os.Getenv("USE_TELEMETRY") == "false" {
clctrl.UseTelemetry = false
clctrl.SegmentClient.UseTelemetry = false
} else {
clctrl.UseTelemetry = true
clctrl.SegmentClient.UseTelemetry = true
}

// Write cluster record if it doesn't exist
cl := pkgtypes.Cluster{
ID: primitive.NewObjectID(),
CreationTimestamp: fmt.Sprintf("%v", primitive.NewDateTimeFromTime(time.Now().UTC())),
UseTelemetry: clctrl.UseTelemetry,
UseTelemetry: clctrl.SegmentClient.UseTelemetry,
Status: constants.ClusterStatusProvisioning,
AlertsEmail: clctrl.AlertsEmail,
ClusterName: clctrl.ClusterName,
Expand Down
7 changes: 3 additions & 4 deletions internal/controller/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"

cloudflare_api "github.com/cloudflare/cloudflare-go"
"github.com/kubefirst/kubefirst-api/pkg/metrics"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/civo"
"github.com/kubefirst/runtime/pkg/digitalocean"
Expand All @@ -28,7 +27,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error {
}

if !cl.DomainLivenessCheck {
telemetry.SendCountMetric(clctrl.Telemetry, metrics.DomainLivenessStarted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.DomainLivenessStarted, err.Error())

switch clctrl.DnsProvider {
case "aws":
Expand All @@ -47,7 +46,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error {
// domain id
domainId, err := civoConf.GetDNSInfo(clctrl.DomainName, clctrl.CloudRegion)
if err != nil {
telemetry.SendCountMetric(clctrl.Telemetry, metrics.DomainLivenessFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.DomainLivenessFailed, err.Error())
log.Info(err.Error())
}

Expand Down Expand Up @@ -122,7 +121,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error {
return err
}

telemetry.SendCountMetric(clctrl.Telemetry, metrics.DomainLivenessCompleted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.DomainLivenessCompleted, err.Error())

log.Infof("domain %s verified", clctrl.DomainName)
}
Expand Down
7 changes: 3 additions & 4 deletions internal/controller/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
terraformext "github.com/kubefirst/kubefirst-api/extensions/terraform"
vultrext "github.com/kubefirst/kubefirst-api/extensions/vultr"
gitShim "github.com/kubefirst/kubefirst-api/internal/gitShim"
"github.com/kubefirst/kubefirst-api/pkg/metrics"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/gitlab"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -73,7 +72,7 @@ func (clctrl *ClusterController) RunGitTerraform() error {
}

// //* create teams and repositories in github
telemetry.SendCountMetric(clctrl.Telemetry, metrics.GitTerraformApplyStarted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitTerraformApplyStarted, err.Error())

log.Infof("Creating %s resources with terraform", clctrl.GitProvider)

Expand Down Expand Up @@ -114,12 +113,12 @@ func (clctrl *ClusterController) RunGitTerraform() error {
if err != nil {
msg := fmt.Sprintf("error creating %s resources with terraform %s: %s", clctrl.GitProvider, tfEntrypoint, err)
log.Error(msg)
telemetry.SendCountMetric(clctrl.Telemetry, metrics.GitTerraformApplyFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitTerraformApplyFailed, err.Error())
return fmt.Errorf(msg)
}

log.Infof("created git projects and groups for %s.com/%s", clctrl.GitProvider, clctrl.GitAuth.Owner)
telemetry.SendCountMetric(clctrl.Telemetry, metrics.GitTerraformApplyCompleted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitTerraformApplyCompleted, err.Error())

err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "git_terraform_apply_check", true)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/controller/kbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package controller
import (
"os"

"github.com/kubefirst/kubefirst-api/pkg/metrics"
"github.com/kubefirst/metrics-client/pkg/telemetry"
internalssh "github.com/kubefirst/runtime/pkg/ssh"
log "github.com/sirupsen/logrus"
Expand All @@ -35,7 +34,7 @@ func (clctrl *ClusterController) InitializeBot() error {
clctrl.GitAuth.PrivateKey, clctrl.GitAuth.PublicKey, err = internalssh.CreateSshKeyPair()
if err != nil {
log.Errorf("error generating ssh keys: %s", err)
telemetry.SendCountMetric(clctrl.Telemetry, metrics.KbotSetupFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.KbotSetupFailed, err.Error())
return err
}

Expand Down
9 changes: 4 additions & 5 deletions internal/controller/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/go-git/go-git/v5"
githttps "github.com/go-git/go-git/v5/plumbing/transport/http"
google "github.com/kubefirst/kubefirst-api/pkg/google"
"github.com/kubefirst/kubefirst-api/pkg/metrics"
"github.com/kubefirst/kubefirst-api/pkg/providerConfigs"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/civo"
Expand Down Expand Up @@ -195,7 +194,7 @@ func (clctrl *ClusterController) RepositoryPush() error {
gitopsDir := clctrl.ProviderConfig.GitopsDir
metaphorDir := clctrl.ProviderConfig.MetaphorDir

telemetry.SendCountMetric(clctrl.Telemetry, metrics.GitopsRepoPushStarted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitopsRepoPushStarted, err.Error())
gitopsRepo, err := git.PlainOpen(gitopsDir)
if err != nil {
log.Infof("error opening repo at: %s", gitopsDir)
Expand Down Expand Up @@ -251,7 +250,7 @@ func (clctrl *ClusterController) RepositoryPush() error {
)
if err != nil {
msg := fmt.Sprintf("error pushing detokenized gitops repository to remote %s: %s", clctrl.ProviderConfig.DestinationGitopsRepoURL, err)
telemetry.SendCountMetric(clctrl.Telemetry, metrics.GitopsRepoPushFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitopsRepoPushFailed, err.Error())
return fmt.Errorf(msg)
}

Expand All @@ -267,14 +266,14 @@ func (clctrl *ClusterController) RepositoryPush() error {
)
if err != nil {
msg := fmt.Sprintf("error pushing detokenized metaphor repository to remote %s: %s", clctrl.ProviderConfig.DestinationMetaphorRepoURL, err)
telemetry.SendCountMetric(clctrl.Telemetry, metrics.GitopsRepoPushFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitopsRepoPushFailed, err.Error())
return fmt.Errorf(msg)
}

log.Infof("successfully pushed gitops and metaphor repositories to git@%s/%s", clctrl.GitHost, clctrl.GitAuth.Owner)
// todo delete the local gitops repo and re-clone it
// todo that way we can stop worrying about which origin we're going to push to
telemetry.SendCountMetric(clctrl.Telemetry, metrics.GitopsRepoPushCompleted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.GitopsRepoPushCompleted, err.Error())

err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "gitops_pushed_check", true)
if err != nil {
Expand Down
15 changes: 7 additions & 8 deletions internal/controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"os"
"strings"

"github.com/kubefirst/kubefirst-api/pkg/metrics"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/civo"
Expand All @@ -38,7 +37,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error {
}

var stateStoreData pkgtypes.StateStoreCredentials
telemetry.SendCountMetric(clctrl.Telemetry, metrics.StateStoreCredentialsCreateStarted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCredentialsCreateStarted, err.Error())

if !cl.StateStoreCredsCheck {
switch clctrl.CloudProvider {
Expand Down Expand Up @@ -101,7 +100,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error {
if err != nil {
msg := fmt.Sprintf("error creating spaces bucket %s: %s", clctrl.KubefirstStateStoreBucketName, err)
log.Error(msg)
telemetry.SendCountMetric(clctrl.Telemetry, metrics.StateStoreCredentialsCreateFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCredentialsCreateFailed, err.Error())
return fmt.Errorf(msg)
}

Expand All @@ -127,7 +126,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error {
if err != nil {
msg := fmt.Sprintf("error creating google bucket %s: %s", clctrl.KubefirstStateStoreBucketName, err)
log.Error()
telemetry.SendCountMetric(clctrl.Telemetry, metrics.StateStoreCredentialsCreateFailed, msg)
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateFailed, msg)
return fmt.Errorf(msg)
}

Expand All @@ -142,7 +141,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error {

objst, err := vultrConf.CreateObjectStorage(clctrl.KubefirstStateStoreBucketName)
if err != nil {
telemetry.SendCountMetric(clctrl.Telemetry, metrics.StateStoreCredentialsCreateFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateFailed, err.Error())
log.Error(err.Error())
return err
}
Expand Down Expand Up @@ -203,14 +202,14 @@ func (clctrl *ClusterController) StateStoreCreate() error {
Context: context.Background(),
}

telemetry.SendCountMetric(clctrl.Telemetry, metrics.StateStoreCreateStarted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateStarted, err.Error())

accessKeyId := cl.StateStoreCredentials.AccessKeyID
log.Infof("access key id %s", accessKeyId)

bucket, err := civoConf.CreateStorageBucket(accessKeyId, clctrl.KubefirstStateStoreBucketName, clctrl.CloudRegion)
if err != nil {
telemetry.SendCountMetric(clctrl.Telemetry, metrics.StateStoreCreateFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateFailed, err.Error())
log.Error(err.Error())
return err
}
Expand All @@ -230,7 +229,7 @@ func (clctrl *ClusterController) StateStoreCreate() error {
return err
}

telemetry.SendCountMetric(clctrl.Telemetry, metrics.StateStoreCreateCompleted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.StateStoreCreateCompleted, err.Error())
log.Infof("%s state store bucket created", clctrl.CloudProvider)
}
}
Expand Down
7 changes: 3 additions & 4 deletions internal/controller/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
googleext "github.com/kubefirst/kubefirst-api/extensions/google"
terraformext "github.com/kubefirst/kubefirst-api/extensions/terraform"
vultrext "github.com/kubefirst/kubefirst-api/extensions/vultr"
"github.com/kubefirst/kubefirst-api/pkg/metrics"
"github.com/kubefirst/metrics-client/pkg/telemetry"
"github.com/kubefirst/runtime/pkg/k8s"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -53,7 +52,7 @@ func (clctrl *ClusterController) RunUsersTerraform() error {
}
}

telemetry.SendCountMetric(clctrl.Telemetry, metrics.UsersTerraformApplyStarted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.UsersTerraformApplyStarted, err.Error())
log.Info("applying users terraform")

tfEnvs := map[string]string{}
Expand Down Expand Up @@ -81,11 +80,11 @@ func (clctrl *ClusterController) RunUsersTerraform() error {
err = terraformext.InitApplyAutoApprove(terraformClient, tfEntrypoint, tfEnvs)
if err != nil {
log.Errorf("error applying users terraform: %s", err)
telemetry.SendCountMetric(clctrl.Telemetry, metrics.UsersTerraformApplyFailed, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.UsersTerraformApplyFailed, err.Error())
return err
}
log.Info("executed users terraform successfully")
telemetry.SendCountMetric(clctrl.Telemetry, metrics.UsersTerraformApplyCompleted, err.Error())
telemetry.SendCountMetric(clctrl.SegmentClient, telemetry.UsersTerraformApplyCompleted, err.Error())

clctrl.VaultAuth.RootToken = tfEnvs["VAULT_TOKEN"]
err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "vault_auth.root_token", clctrl.VaultAuth.RootToken)
Expand Down
Loading

0 comments on commit 4e5a38d

Please sign in to comment.