Skip to content

Commit

Permalink
removing dependency on segment in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
johndietz committed Oct 21, 2023
1 parent 3d6df67 commit f153525
Show file tree
Hide file tree
Showing 24 changed files with 83 additions and 89 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/charmbracelet/lipgloss v0.8.0
github.com/civo/civogo v0.3.28
github.com/cloudflare/cloudflare-go v0.73.0
github.com/denisbrodbeck/machineid v1.0.1
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.8.2
github.com/go-git/go-git/v5 v5.6.1
Expand All @@ -29,6 +30,7 @@ require (
github.com/minio/minio-go/v7 v7.0.49
github.com/otiai10/copy v1.7.0
github.com/rs/zerolog v1.29.0
github.com/segmentio/analytics-go v3.1.0+incompatible
github.com/sirupsen/logrus v1.9.0
github.com/swaggo/files v1.0.0
github.com/swaggo/gin-swagger v1.5.3
Expand Down Expand Up @@ -99,7 +101,6 @@ require (
github.com/cloudflare/circl v1.1.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/denisbrodbeck/machineid v1.0.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/digitalocean/godo v1.98.0 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
Expand Down Expand Up @@ -211,7 +212,6 @@ require (
github.com/rs/xid v1.4.0 // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/segmentio/analytics-go v3.1.0+incompatible // indirect
github.com/segmentio/backo-go v1.0.1 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
Expand Down Expand Up @@ -325,3 +325,4 @@ replace (
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.24.2
)

replace github.com/kubefirst/runtime => /Users/jdietz/git/github/kubefirst/runtime
14 changes: 7 additions & 7 deletions internal/controller/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ 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/internal/telemetryShim"
"github.com/kubefirst/kubefirst-api/pkg/segment"
"github.com/kubefirst/runtime/pkg"
"github.com/kubefirst/runtime/pkg/argocd"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/kubefirst/runtime/pkg/segment"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -66,13 +66,13 @@ func (clctrl *ClusterController) InstallArgoCD() error {

err = argocd.ApplyArgoCDKustomize(kcfg.Clientset, argoCDInstallPath)
if err != nil {
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricArgoCDInstallFailed, err.Error())
telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallFailed, err.Error())
return err
}
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricArgoCDInstallCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallCompleted, "")

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricArgoCDInstallStarted, "")
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricArgoCDInstallCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricArgoCDInstallCompleted, "")

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

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCreateRegistryStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricCreateRegistryStarted, "")
argocdClient, err := argocdapi.NewForConfig(kcfg.RestConfig)
if err != nil {
return err
Expand Down Expand Up @@ -253,7 +253,7 @@ func (clctrl *ClusterController) DeployRegistryApplication() error {

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

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCreateRegistryCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricCreateRegistryCompleted, "")

err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "argocd_create_registry_check", true)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions internal/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
gitShim "github.com/kubefirst/kubefirst-api/internal/gitShim"
"github.com/kubefirst/kubefirst-api/internal/telemetryShim"
"github.com/kubefirst/kubefirst-api/pkg/providerConfigs"
"github.com/kubefirst/kubefirst-api/pkg/segment"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/kubefirst/runtime/pkg/segment"
log "github.com/sirupsen/logrus"
"github.com/thanhpk/randstr"
v1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -54,12 +54,12 @@ func (clctrl *ClusterController) CreateCluster() error {

if !cl.CloudTerraformApplyCheck || cl.CloudTerraformApplyFailedCheck {

telemetryShim.Transmit(true, segmentClient, segment.MetricCloudTerraformApplyStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyStarted, "")

log.Info("creating aws cloud resources with terraform")
tfEntrypoint := clctrl.ProviderConfig.GitopsDir + fmt.Sprintf("/terraform/%s", clctrl.CloudProvider)
tfEnvs := map[string]string{}
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCloudTerraformApplyStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyStarted, "")

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

Expand Down Expand Up @@ -95,17 +95,17 @@ func (clctrl *ClusterController) CreateCluster() error {
if err != nil {
return err
}
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCloudTerraformApplyFailed, msg)
telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyFailed, msg)
return fmt.Errorf(msg)
}

log.Infof("created %s cloud resources", clctrl.CloudProvider)

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCloudTerraformApplyCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyCompleted, "")

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

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricCloudTerraformApplyCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricCloudTerraformApplyCompleted, "")

err = clctrl.MdbCl.UpdateCluster(clctrl.ClusterName, "cloud_terraform_apply_failed_check", false)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
google "github.com/kubefirst/kubefirst-api/pkg/google"
"github.com/kubefirst/kubefirst-api/pkg/handlers"
"github.com/kubefirst/kubefirst-api/pkg/providerConfigs"
"github.com/kubefirst/kubefirst-api/pkg/segment"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/runtime/pkg"
runtime "github.com/kubefirst/runtime/pkg"
awsinternal "github.com/kubefirst/runtime/pkg/aws"
"github.com/kubefirst/runtime/pkg/github"
"github.com/kubefirst/runtime/pkg/gitlab"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/kubefirst/runtime/pkg/segment"
"github.com/kubefirst/runtime/pkg/services"
log "github.com/sirupsen/logrus"
"go.mongodb.org/mongo-driver/bson/primitive"
Expand Down Expand Up @@ -150,7 +150,7 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)
}
defer segmentClient.Client.Close()

telemetryShim.Transmit(rec.UseTelemetry, segmentClient, segment.MetricClusterInstallStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricClusterInstallStarted, "")

//Copy Cluster Definiion to Cluster Controller
clctrl.AlertsEmail = def.AdminEmail
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (

cloudflare_api "github.com/cloudflare/cloudflare-go"
"github.com/kubefirst/kubefirst-api/internal/telemetryShim"
"github.com/kubefirst/kubefirst-api/pkg/segment"
"github.com/kubefirst/runtime/pkg/civo"
"github.com/kubefirst/runtime/pkg/digitalocean"
"github.com/kubefirst/runtime/pkg/dns"
"github.com/kubefirst/runtime/pkg/segment"
"github.com/kubefirst/runtime/pkg/vultr"
log "github.com/sirupsen/logrus"
)
Expand All @@ -35,7 +35,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error {
defer segmentClient.Client.Close()

if !cl.DomainLivenessCheck {
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricDomainLivenessStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricDomainLivenessStarted, "")

switch clctrl.DnsProvider {
case "aws":
Expand All @@ -54,7 +54,7 @@ func (clctrl *ClusterController) DomainLivenessTest() error {
// domain id
domainId, err := civoConf.GetDNSInfo(clctrl.DomainName, clctrl.CloudRegion)
if err != nil {
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricDomainLivenessFailed, "domain liveness test failed")
telemetryShim.Transmit(segmentClient, segment.MetricDomainLivenessFailed, "domain liveness test failed")
log.Info(err.Error())
}

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

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricDomainLivenessCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricDomainLivenessCompleted, "")

log.Infof("domain %s verified", clctrl.DomainName)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
vultrext "github.com/kubefirst/kubefirst-api/extensions/vultr"
gitShim "github.com/kubefirst/kubefirst-api/internal/gitShim"
"github.com/kubefirst/kubefirst-api/internal/telemetryShim"
"github.com/kubefirst/kubefirst-api/pkg/segment"
"github.com/kubefirst/runtime/pkg/gitlab"
"github.com/kubefirst/runtime/pkg/segment"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -80,7 +80,7 @@ func (clctrl *ClusterController) RunGitTerraform() error {
defer segmentClient.Client.Close()

// //* create teams and repositories in github
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitTerraformApplyStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricGitTerraformApplyStarted, "")

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

Expand Down Expand Up @@ -121,12 +121,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)
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitTerraformApplyFailed, msg)
telemetryShim.Transmit(segmentClient, segment.MetricGitTerraformApplyFailed, msg)
return fmt.Errorf(msg)
}

log.Infof("created git projects and groups for %s.com/%s", clctrl.GitProvider, clctrl.GitAuth.Owner)
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitTerraformApplyCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricGitTerraformApplyCompleted, "")

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

"github.com/kubefirst/kubefirst-api/internal/telemetryShim"
"github.com/kubefirst/runtime/pkg/segment"
"github.com/kubefirst/kubefirst-api/pkg/segment"
internalssh "github.com/kubefirst/runtime/pkg/ssh"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -42,7 +42,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)
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricKbotSetupFailed, err.Error())
telemetryShim.Transmit(segmentClient, segment.MetricKbotSetupFailed, err.Error())
return err
}

Expand Down
10 changes: 5 additions & 5 deletions internal/controller/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"github.com/kubefirst/kubefirst-api/internal/telemetryShim"
google "github.com/kubefirst/kubefirst-api/pkg/google"
"github.com/kubefirst/kubefirst-api/pkg/providerConfigs"
"github.com/kubefirst/kubefirst-api/pkg/segment"
"github.com/kubefirst/runtime/pkg/civo"
"github.com/kubefirst/runtime/pkg/digitalocean"
"github.com/kubefirst/runtime/pkg/gitlab"
"github.com/kubefirst/runtime/pkg/segment"
"github.com/kubefirst/runtime/pkg/vultr"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -202,7 +202,7 @@ func (clctrl *ClusterController) RepositoryPush() error {
gitopsDir := clctrl.ProviderConfig.GitopsDir
metaphorDir := clctrl.ProviderConfig.MetaphorDir

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitopsRepoPushStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricGitopsRepoPushStarted, "")
gitopsRepo, err := git.PlainOpen(gitopsDir)
if err != nil {
log.Infof("error opening repo at: %s", gitopsDir)
Expand Down Expand Up @@ -258,7 +258,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)
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitopsRepoPushFailed, msg)
telemetryShim.Transmit(segmentClient, segment.MetricGitopsRepoPushFailed, msg)
return fmt.Errorf(msg)
}

Expand All @@ -274,14 +274,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)
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitopsRepoPushFailed, msg)
telemetryShim.Transmit(segmentClient, segment.MetricGitopsRepoPushFailed, msg)
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
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricGitopsRepoPushCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricGitopsRepoPushCompleted, "")

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

"github.com/kubefirst/kubefirst-api/internal/telemetryShim"
"github.com/kubefirst/kubefirst-api/pkg/segment"
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/runtime/pkg/civo"
"github.com/kubefirst/runtime/pkg/digitalocean"
"github.com/kubefirst/runtime/pkg/segment"
"github.com/kubefirst/runtime/pkg/vultr"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -107,7 +107,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error {
if err != nil {
msg := fmt.Sprintf("error creating spaces bucket %s: %s", clctrl.KubefirstStateStoreBucketName, err)
log.Error(msg)
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateFailed, msg)
telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateFailed, msg)
return fmt.Errorf(msg)
}

Expand All @@ -133,7 +133,7 @@ func (clctrl *ClusterController) StateStoreCredentials() error {
if err != nil {
msg := fmt.Sprintf("error creating google bucket %s: %s", clctrl.KubefirstStateStoreBucketName, err)
log.Error(msg)
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateFailed, msg)
telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateFailed, msg)
return fmt.Errorf(msg)
}

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

objst, err := vultrConf.CreateObjectStorage(clctrl.KubefirstStateStoreBucketName)
if err != nil {
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateFailed, err.Error())
telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateFailed, err.Error())
log.Error(err.Error())
return err
}
Expand Down Expand Up @@ -216,14 +216,14 @@ func (clctrl *ClusterController) StateStoreCreate() error {
Context: context.Background(),
}

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateStarted, "")

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

bucket, err := civoConf.CreateStorageBucket(accessKeyId, clctrl.KubefirstStateStoreBucketName, clctrl.CloudRegion)
if err != nil {
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateFailed, err.Error())
telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateFailed, err.Error())
log.Error(err.Error())
return err
}
Expand All @@ -243,7 +243,7 @@ func (clctrl *ClusterController) StateStoreCreate() error {
return err
}

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricStateStoreCreateCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricStateStoreCreateCompleted, "")
log.Infof("%s state store bucket created", clctrl.CloudProvider)
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
terraformext "github.com/kubefirst/kubefirst-api/extensions/terraform"
vultrext "github.com/kubefirst/kubefirst-api/extensions/vultr"
"github.com/kubefirst/kubefirst-api/internal/telemetryShim"
"github.com/kubefirst/kubefirst-api/pkg/segment"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/kubefirst/runtime/pkg/segment"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -60,7 +60,7 @@ func (clctrl *ClusterController) RunUsersTerraform() error {
}
}

telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricUsersTerraformApplyStarted, "")
telemetryShim.Transmit(segmentClient, segment.MetricUsersTerraformApplyStarted, "")
log.Info("applying users terraform")

tfEnvs := map[string]string{}
Expand Down Expand Up @@ -88,11 +88,11 @@ func (clctrl *ClusterController) RunUsersTerraform() error {
err = terraformext.InitApplyAutoApprove(terraformClient, tfEntrypoint, tfEnvs)
if err != nil {
log.Errorf("error applying users terraform: %s", err)
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricUsersTerraformApplyStarted, err.Error())
telemetryShim.Transmit(segmentClient, segment.MetricUsersTerraformApplyStarted, err.Error())
return err
}
log.Info("executed users terraform successfully")
telemetryShim.Transmit(clctrl.UseTelemetry, segmentClient, segment.MetricUsersTerraformApplyCompleted, "")
telemetryShim.Transmit(segmentClient, segment.MetricUsersTerraformApplyCompleted, "")

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 f153525

Please sign in to comment.