diff --git a/pkg/api/charts.go b/pkg/api/charts.go index 12f83b559..dcda98393 100644 --- a/pkg/api/charts.go +++ b/pkg/api/charts.go @@ -5,89 +5,6 @@ import ( "github.com/pluralsh/gqlclient/pkg/utils" ) -type packageCacheEntry struct { - Charts []*ChartInstallation - Terraform []*TerraformInstallation -} - -var packageCache = make(map[string]*packageCacheEntry) - -func (client *client) GetVersions(chartId string) ([]*Version, error) { - versions := make([]*Version, 0) - resp, err := client.pluralClient.GetVersions(client.ctx, chartId) - if err != nil { - return nil, err - } - for _, version := range resp.Versions.Edges { - versions = append(versions, convertVersion(version.Node)) - } - return versions, err -} - -func (client *client) GetChartInstallations(repoId string) ([]*ChartInstallation, error) { - insts := make([]*ChartInstallation, 0) - resp, err := client.pluralClient.GetChartInstallations(client.ctx, repoId) - if err != nil { - return nil, err - } - - for _, edge := range resp.ChartInstallations.Edges { - if edge.Node != nil { - insts = append(insts, convertChartInstallation(edge.Node)) - } - } - - return insts, err -} - -func ClearPackageCache() { - packageCache = make(map[string]*packageCacheEntry) -} - -func (client *client) GetPackageInstallations(repoId string) (charts []*ChartInstallation, tfs []*TerraformInstallation, err error) { - if entry, ok := packageCache[repoId]; ok { - return entry.Charts, entry.Terraform, nil - } - - resp, err := client.pluralClient.GetPackageInstallations(client.ctx, repoId) - if err != nil { - return - } - - charts = make([]*ChartInstallation, 0) - for _, edge := range resp.ChartInstallations.Edges { - if edge.Node != nil { - charts = append(charts, convertChartInstallation(edge.Node)) - } - } - - tfs = make([]*TerraformInstallation, 0) - for _, edge := range resp.TerraformInstallations.Edges { - node := edge.Node - if node != nil { - tfInstall := &TerraformInstallation{ - Id: utils.ConvertStringPointer(node.ID), - Terraform: convertTerraform(node.Terraform), - - Version: convertVersion(node.Version), - } - - tfs = append(tfs, tfInstall) - } - } - - if err == nil { - packageCache[repoId] = &packageCacheEntry{Charts: charts, Terraform: tfs} - } - - return -} - -func (client *client) UninstallChart(id string) (err error) { - _, err = client.pluralClient.UninstallChart(client.ctx, id) - return -} - func convertVersion(version *gqlclient.VersionFragment) *Version { if version == nil { return nil diff --git a/pkg/api/client.go b/pkg/api/client.go index 3e608082b..79fa7f58d 100644 --- a/pkg/api/client.go +++ b/pkg/api/client.go @@ -38,13 +38,7 @@ type Client interface { DeleteEabCredential(cluster string, provider string) error CreateEvent(event *UserEventAttributes) error GetTfProviders() ([]string, error) - GetTfProviderScaffold(name string, version string) (string, error) GetRepository(repo string) (*Repository, error) - CreateRepository(name string, publisher string, input *gqlclient.RepositoryAttributes) error - AcquireLock(repo string) (*ApplyLock, error) - ReleaseLock(repo string, lock string) (*ApplyLock, error) - ListRepositories(query string) ([]*Repository, error) - Scaffolds(in *ScaffoldInputs) ([]*ScaffoldFile, error) UpdateVersion(spec *VersionSpec, tags []string) error CreateDomain(name string) error CreateInstallation(id string) (string, error) @@ -57,7 +51,6 @@ type Client interface { GetHelp(prompt string) (string, error) Clusters() ([]*Cluster, error) Cluster(id string) (*Cluster, error) - Release(name string, tags []string) error Chat(history []*ChatMessage) (*ChatMessage, error) CreateTrust(issuer, trust string) error DeleteTrust(id string) error diff --git a/pkg/api/installations.go b/pkg/api/installations.go index c80201c2f..e8cce82e1 100644 --- a/pkg/api/installations.go +++ b/pkg/api/installations.go @@ -26,14 +26,6 @@ func (client *client) GetInstallation(name string) (*Installation, error) { } -func (client *client) GetInstallationById(id string) (*Installation, error) { - resp, err := client.pluralClient.GetInstallationByID(client.ctx, &id) - if err != nil { - return nil, err - } - return convertInstallation(resp.Installation), nil -} - func (client *client) DeleteInstallation(id string) error { _, err := client.pluralClient.DeleteInstallation(client.ctx, id) return err diff --git a/pkg/api/recipes.go b/pkg/api/recipes.go deleted file mode 100644 index 2cdd5d95a..000000000 --- a/pkg/api/recipes.go +++ /dev/null @@ -1,71 +0,0 @@ -package api - -type RecipeInput struct { - Name string - Description string - Provider string - Restricted bool - Primary bool - Tests []RecipeTestInput `yaml:"tests" json:"tests,omitempty"` - Sections []RecipeSectionInput - Dependencies []DependencyInput - OidcSettings *OIDCSettings `yaml:"oidcSettings,omitempty"` -} - -type DependencyInput struct { - Name string - Repo string -} - -type RecipeTestInput struct { - Name string - Message string - Type string - Args []*TestArgInput -} - -type TestArgInput struct { - Name string - Repo string - Key string -} - -type RecipeSectionInput struct { - Name string - Items []RecipeItemInput - Configuration []ConfigurationItemInput -} - -type RecipeItemInput struct { - Name string - Type string -} - -type ConditionInput struct { - Field string - Value string - Operation string -} - -type ValidationInput struct { - Type string - Regex string - Message string -} - -type ConfigurationItemInput struct { - Name string - Default string - Type string - Documentation string - Placeholder string - Longform string - Optional bool - FunctionName string `yaml:"functionName,omitempty" json:"functionName,omitempty"` - Condition *ConditionInput - Validation *ValidationInput -} - -type RecipeEdge struct { - Node *Recipe -} diff --git a/pkg/api/repos.go b/pkg/api/repos.go index 96c1d23de..c114a17c8 100644 --- a/pkg/api/repos.go +++ b/pkg/api/repos.go @@ -1,18 +1,9 @@ package api import ( - "context" - "os" - "path/filepath" - "strings" - _ "github.com/AlecAivazis/survey/v2" - "sigs.k8s.io/yaml" - "github.com/pluralsh/gqlclient" "github.com/pluralsh/gqlclient/pkg/utils" - fileutils "github.com/pluralsh/plural-cli/pkg/utils" - "github.com/samber/lo" ) type ResourceDefinitionInput struct { @@ -94,204 +85,3 @@ func convertRepository(repo *gqlclient.RepositoryFragment) *Repository { }, } } - -func (client *client) CreateRepository(name, publisher string, input *gqlclient.RepositoryAttributes) error { - var uploads []gqlclient.Upload - - iconUpload, err := getIconReader(input.Icon, "icon") - if err != nil { - return err - } - - if iconUpload != nil { - input.Icon = lo.ToPtr("icon") - uploads = append(uploads, *iconUpload) - } - - darkIconUpload, err := getIconReader(input.DarkIcon, "darkicon") - if err != nil { - return err - } - - if darkIconUpload != nil { - input.DarkIcon = lo.ToPtr("darkicon") - uploads = append(uploads, *darkIconUpload) - } - - if input.Docs != nil && *input.Docs != "" { - tarFile, err := tarDir(name, *input.Docs, "") - if err != nil { - return err - } - defer os.Remove(tarFile) - - docsUpload, err := getIconReader(lo.ToPtr(tarFile), "docs") - if err != nil { - return err - } - input.Docs = lo.ToPtr("docs") - uploads = append(uploads, *docsUpload) - } - - if input.Notes != nil && *input.Notes != "" { - file, _ := filepath.Abs(*input.Notes) - notes, err := fileutils.ReadFile(file) - if err != nil { - return err - } - - input.Notes = ¬es - } - client.pluralClient.Client.CustomDo = gqlclient.WithFiles(uploads, client.httpClient) - _, err = client.pluralClient.CreateRepository(context.Background(), name, publisher, *input) - return err -} - -func (client *client) AcquireLock(repo string) (*ApplyLock, error) { - resp, err := client.pluralClient.AcquireLock(client.ctx, repo) - if err != nil { - return nil, err - } - - return &ApplyLock{ - Id: resp.AcquireLock.ID, - Lock: utils.ConvertStringPointer(resp.AcquireLock.Lock), - }, err -} - -func (client *client) ReleaseLock(repo, lock string) (*ApplyLock, error) { - resp, err := client.pluralClient.ReleaseLock(client.ctx, repo, gqlclient.LockAttributes{Lock: lock}) - if err != nil { - return nil, err - } - - return &ApplyLock{ - Id: resp.ReleaseLock.ID, - Lock: utils.ConvertStringPointer(resp.ReleaseLock.Lock), - }, nil -} - -func (client *client) ListRepositories(query string) ([]*Repository, error) { - resp, err := client.pluralClient.ListRepositories(client.ctx, &query) - if err != nil { - return nil, err - } - - res := make([]*Repository, 0) - for _, edge := range resp.Repositories.Edges { - rep := &Repository{ - Id: edge.Node.ID, - Name: edge.Node.Name, - Description: utils.ConvertStringPointer(edge.Node.Description), - Icon: utils.ConvertStringPointer(edge.Node.Icon), - DarkIcon: utils.ConvertStringPointer(edge.Node.DarkIcon), - Notes: utils.ConvertStringPointer(edge.Node.Notes), - Publisher: &Publisher{ - Name: edge.Node.Publisher.Name, - }, - Recipes: []*Recipe{}, - } - for _, rcp := range edge.Node.Recipes { - rep.Recipes = append(rep.Recipes, &Recipe{Name: rcp.Name}) - } - res = append(res, rep) - } - - return res, err -} - -func (client *client) Release(name string, tags []string) error { - _, err := client.pluralClient.Release(context.Background(), name, tags) - return err -} - -func (client *client) Scaffolds(in *ScaffoldInputs) ([]*ScaffoldFile, error) { - scaffolds, err := client.pluralClient.Scaffolds(context.Background(), in.Application, in.Publisher, gqlclient.Category(strings.ToUpper(in.Category)), &in.Ingress, &in.Postgres) - if err != nil { - return nil, err - } - - resp := make([]*ScaffoldFile, 0) - - for _, scaffold := range scaffolds.Scaffold { - resp = append(resp, &ScaffoldFile{ - Path: utils.ConvertStringPointer(scaffold.Path), - Content: utils.ConvertStringPointer(scaffold.Content), - }) - } - - return resp, err -} - -func getIconReader(icon *string, field string) (*gqlclient.Upload, error) { - if icon == nil { - return nil, nil - } - if *icon == "" { - return nil, nil - } - - file, err := filepath.Abs(*icon) - if err != nil { - return nil, err - } - f, err := os.Open(file) - if err != nil { - return nil, err - } - - return &gqlclient.Upload{ - Field: field, - Name: file, - R: f, - }, nil -} - -func ConstructRepositoryInput(marshalled []byte) (input *RepositoryInput, err error) { - input = &RepositoryInput{} - err = yaml.Unmarshal(marshalled, input) - return -} - -func ConstructGqlClientRepositoryInput(marshalled []byte) (*gqlclient.RepositoryAttributes, error) { - repoInput, err := ConstructRepositoryInput(marshalled) - if err != nil { - return nil, err - } - - category := gqlclient.Category(repoInput.Category) - - var releaseStatus *gqlclient.ReleaseStatus - if repoInput.ReleaseStatus != "" { - releaseStatus = lo.ToPtr(gqlclient.ReleaseStatus(repoInput.ReleaseStatus)) - } - - resp := &gqlclient.RepositoryAttributes{ - Category: &category, - DarkIcon: &repoInput.DarkIcon, - Description: &repoInput.Description, - ReleaseStatus: releaseStatus, - Contributors: lo.ToSlicePtr(repoInput.Contributors), - GitURL: &repoInput.GitUrl, - Homepage: &repoInput.Homepage, - Icon: &repoInput.Icon, - Docs: &repoInput.Docs, - Name: &repoInput.Name, - Notes: &repoInput.Notes, - Private: &repoInput.Private, - Tags: []*gqlclient.TagAttributes{}, - } - if repoInput.OauthSettings != nil { - resp.OauthSettings = &gqlclient.OauthSettingsAttributes{ - AuthMethod: gqlclient.OidcAuthMethod(repoInput.OauthSettings.AuthMethod), - URIFormat: repoInput.OauthSettings.UriFormat, - } - } - for _, tag := range repoInput.Tags { - resp.Tags = append(resp.Tags, &gqlclient.TagAttributes{ - Tag: tag.Tag, - }) - } - - return resp, nil -} diff --git a/pkg/api/scaffolds.go b/pkg/api/scaffolds.go index 3b7f0b515..d6d142d0e 100644 --- a/pkg/api/scaffolds.go +++ b/pkg/api/scaffolds.go @@ -1,7 +1,5 @@ package api -import "github.com/pluralsh/gqlclient" - func (client *client) GetTfProviders() ([]string, error) { resp, err := client.pluralClient.GetTfProviders(client.ctx) if err != nil { @@ -14,12 +12,3 @@ func (client *client) GetTfProviders() ([]string, error) { return result, nil } - -func (client *client) GetTfProviderScaffold(name, version string) (string, error) { - resp, err := client.pluralClient.GetTfProviderScaffold(client.ctx, gqlclient.Provider(name), &version) - if err != nil { - return "", err - } - - return *resp.TerraformProvider.Content, err -} diff --git a/pkg/api/terraform.go b/pkg/api/terraform.go deleted file mode 100644 index 5c708c934..000000000 --- a/pkg/api/terraform.go +++ /dev/null @@ -1,58 +0,0 @@ -package api - -import ( - "os" - "path/filepath" - - "github.com/pluralsh/gqlclient" - - "github.com/pluralsh/gqlclient/pkg/utils" - tarutils "github.com/pluralsh/plural-cli/pkg/utils" - "github.com/pluralsh/plural-cli/pkg/utils/pathing" -) - -func (client *client) GetTerraformVersions(id string) ([]*Version, error) { - resp, err := client.pluralClient.GetTerraformVersions(client.ctx, id) - if err != nil { - return nil, err - } - - versions := make([]*Version, 0) - for _, version := range resp.Versions.Edges { - versions = append(versions, convertVersion(version.Node)) - } - - return versions, nil -} - -func tarDir(name, dir, regex string) (res string, err error) { - fullPath, err := filepath.Abs(dir) - if err != nil { - return - } - - cwd, _ := os.Getwd() - res = pathing.SanitizeFilepath(filepath.Join(cwd, name+".tgz")) - f, err := os.Create(res) - if err != nil { - return - } - defer f.Close() - - err = tarutils.Tar(fullPath, f, regex) - return -} - -func convertTerraform(ter *gqlclient.TerraformFragment) *Terraform { - if ter == nil { - return nil - } - return &Terraform{ - Id: utils.ConvertStringPointer(ter.ID), - Name: utils.ConvertStringPointer(ter.Name), - Description: utils.ConvertStringPointer(ter.Description), - ValuesTemplate: utils.ConvertStringPointer(ter.ValuesTemplate), - Dependencies: convertDependencies(ter.Dependencies), - Package: utils.ConvertStringPointer(ter.Package), - } -} diff --git a/pkg/application/register.go b/pkg/application/register.go index 03b452a38..b3c57b22c 100644 --- a/pkg/application/register.go +++ b/pkg/application/register.go @@ -2,16 +2,13 @@ package application import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "sigs.k8s.io/application/api/v1beta1" ) var Scheme = runtime.NewScheme() -var Codecs = serializer.NewCodecFactory(Scheme) -var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ v1beta1.AddToScheme, } diff --git a/pkg/manifest/link.go b/pkg/manifest/link.go deleted file mode 100644 index 96fe72d35..000000000 --- a/pkg/manifest/link.go +++ /dev/null @@ -1,51 +0,0 @@ -package manifest - -import ( - "path/filepath" -) - -type Links struct { - Terraform map[string]string - Helm map[string]string -} - -func (man *Manifest) AddLink(tool, name, path string) { - links := man.Links - if links == nil { - links = &Links{ - Terraform: map[string]string{}, - Helm: map[string]string{}, - } - } - - absPath, _ := filepath.Abs(path) - - if tool == "terraform" { - links.Terraform[name] = absPath - } - - if tool == "helm" { - links.Helm[name] = absPath - } - - man.Links = links -} - -func (man *Manifest) Unlink(tool, name string) { - links := man.Links - if links == nil { - return - } - - if tool == "terraform" { - delete(links.Terraform, name) - } else if tool == "helm" { - delete(links.Helm, name) - } - - man.Links = links -} - -func (man *Manifest) UnlinkAll() { - man.Links = nil -} diff --git a/pkg/manifest/manifest.go b/pkg/manifest/manifest.go index 7b4c08829..ab507ce82 100644 --- a/pkg/manifest/manifest.go +++ b/pkg/manifest/manifest.go @@ -28,15 +28,6 @@ func ProjectManifestPath() string { return pathing.SanitizeFilepath(filepath.Join(root, "workspace.yaml")) } -func ManifestPath(repo string) (string, error) { - root, found := utils.ProjectRoot() - if !found { - return "", fmt.Errorf("You're not within an installation repo") - } - - return pathing.SanitizeFilepath(filepath.Join(root, repo, "manifest.yaml")), nil -} - func (pMan *ProjectManifest) Write(path string) error { versioned := &VersionedProjectManifest{ ApiVersion: "plural.sh/v1alpha1", @@ -100,24 +91,6 @@ func (man *Manifest) Write(path string) error { return os.WriteFile(path, io, 0644) } -func Read(path string) (man *Manifest, err error) { - contents, err := os.ReadFile(path) - if err != nil { - return - } - - versioned := &VersionedManifest{} - err = yaml.Unmarshal(contents, versioned) - if err != nil || versioned.Spec == nil { - man = &Manifest{} - err = yaml.Unmarshal(contents, man) - return - } - - man = versioned.Spec - return -} - func (pMan *ProjectManifest) Configure(cloud bool, cluster string) Writer { utils.Highlight("\nLet's get some final information about your workspace set up\n\n") diff --git a/pkg/manifest/types.go b/pkg/manifest/types.go index 6e87ef2aa..f52258a77 100644 --- a/pkg/manifest/types.go +++ b/pkg/manifest/types.go @@ -37,7 +37,6 @@ type Manifest struct { Terraform []*TerraformManifest Dependencies []*Dependency Context map[string]interface{} - Links *Links `yaml:"links,omitempty"` } type Owner struct { diff --git a/pkg/provider/aws.go b/pkg/provider/aws.go index da7b248ad..47efc9ac2 100644 --- a/pkg/provider/aws.go +++ b/pkg/provider/aws.go @@ -21,7 +21,6 @@ import ( "github.com/pluralsh/plural-cli/pkg/config" "github.com/pluralsh/plural-cli/pkg/kubernetes" "github.com/pluralsh/plural-cli/pkg/manifest" - "github.com/pluralsh/plural-cli/pkg/template" "github.com/pluralsh/plural-cli/pkg/utils" plrlErrors "github.com/pluralsh/plural-cli/pkg/utils/errors" @@ -209,25 +208,6 @@ func (aws *AWSProvider) CreateBucket() error { return aws.mkBucket(aws.bucket) } -func (aws *AWSProvider) CreateBackend(prefix string, version string, ctx map[string]interface{}) (string, error) { - if err := aws.mkBucket(aws.bucket); err != nil { - return "", plrlErrors.ErrorWrap(err, fmt.Sprintf("Failed to create terraform state bucket %s", aws.bucket)) - } - - ctx["Region"] = aws.Region() - ctx["Bucket"] = aws.Bucket() - ctx["Prefix"] = prefix - ctx["__CLUSTER__"] = aws.Cluster() - if _, ok := ctx["Cluster"]; !ok { - ctx["Cluster"] = fmt.Sprintf("\"%s\"", aws.Cluster()) - } - scaffold, err := GetProviderScaffold(api.ToGQLClientProvider(api.ProviderAWS), version) - if err != nil { - return "", err - } - return template.RenderString(scaffold, ctx) -} - func (aws *AWSProvider) KubeConfig() error { if kubernetes.InKubernetes() { return nil diff --git a/pkg/provider/azure.go b/pkg/provider/azure.go index 8893246b6..18bbdee53 100644 --- a/pkg/provider/azure.go +++ b/pkg/provider/azure.go @@ -27,7 +27,6 @@ import ( "github.com/pluralsh/plural-cli/pkg/kubernetes" "github.com/pluralsh/plural-cli/pkg/manifest" "github.com/pluralsh/plural-cli/pkg/provider/permissions" - "github.com/pluralsh/plural-cli/pkg/template" "github.com/pluralsh/plural-cli/pkg/utils" pluralerr "github.com/pluralsh/plural-cli/pkg/utils/errors" ) @@ -213,31 +212,6 @@ func (az *AzureProvider) CreateBucket() error { return nil } -func (az *AzureProvider) CreateBackend(prefix string, version string, ctx map[string]interface{}) (string, error) { - if err := az.CreateBucket(); err != nil { - return "", err - } - - ctx["Region"] = az.Region() - ctx["Bucket"] = az.Bucket() - ctx["Prefix"] = prefix - ctx["ResourceGroup"] = az.Project() - ctx["__CLUSTER__"] = az.Cluster() - ctx["Context"] = az.Context() - if cluster, ok := ctx["cluster"]; ok { - ctx["Cluster"] = cluster - ctx["ClusterCreated"] = true - } else { - ctx["Cluster"] = fmt.Sprintf(`"%s"`, az.Cluster()) - } - - scaffold, err := GetProviderScaffold(api.ToGQLClientProvider(api.ProviderAzure), version) - if err != nil { - return "", err - } - return template.RenderString(scaffold, ctx) -} - func (az *AzureProvider) createContainer(bucket string) (err error) { acc, err := az.upsertStorageAccount(utils.ToString(az.Context()["StorageAccount"])) if err != nil { diff --git a/pkg/provider/equinix.go b/pkg/provider/equinix.go index 40fe3b0ba..a51902e15 100644 --- a/pkg/provider/equinix.go +++ b/pkg/provider/equinix.go @@ -32,8 +32,6 @@ import ( "github.com/pluralsh/plural-cli/pkg/config" "github.com/pluralsh/plural-cli/pkg/manifest" "github.com/pluralsh/plural-cli/pkg/provider/permissions" - "github.com/pluralsh/plural-cli/pkg/template" - "github.com/pluralsh/plural-cli/pkg/utils" pluralErrors "github.com/pluralsh/plural-cli/pkg/utils/errors" "github.com/pluralsh/plural-cli/pkg/utils/git" "github.com/pluralsh/plural-cli/pkg/utils/pathing" @@ -121,33 +119,6 @@ func (equinix *EQUINIXProvider) CreateBucket() error { return nil } -func (equinix *EQUINIXProvider) CreateBackend(prefix string, version string, ctx map[string]interface{}) (string, error) { - - ctx["Region"] = equinix.Region() - ctx["Bucket"] = equinix.Bucket() - ctx["Prefix"] = prefix - ctx["ClusterCreated"] = false - ctx["__CLUSTER__"] = equinix.Cluster() - if cluster, ok := ctx["cluster"]; ok { - ctx["Cluster"] = cluster - ctx["ClusterCreated"] = true - } else { - ctx["Cluster"] = fmt.Sprintf(`"%s"`, equinix.Cluster()) - } - - if err := utils.WriteFile(pathing.SanitizeFilepath(filepath.Join(equinix.Bucket(), ".gitignore")), []byte("!/**")); err != nil { - return "", err - } - if err := utils.WriteFile(pathing.SanitizeFilepath(filepath.Join(equinix.Bucket(), ".gitattributes")), []byte("/** filter=plural-crypt diff=plural-crypt\n.gitattributes !filter !diff")); err != nil { - return "", err - } - scaffold, err := GetProviderScaffold(api.ToGQLClientProvider(api.ProviderEquinix), version) - if err != nil { - return "", err - } - return template.RenderString(scaffold, ctx) -} - func (equinix *EQUINIXProvider) KubeConfig() error { // TODO: deal with current configured KUBECONFIG // TODO: deal with KUBECONFIG env var if it is set, as then the output KUBECONFIG file will be used diff --git a/pkg/provider/gcp.go b/pkg/provider/gcp.go index 1e521ea81..a69d4d2e9 100644 --- a/pkg/provider/gcp.go +++ b/pkg/provider/gcp.go @@ -29,7 +29,6 @@ import ( "github.com/pluralsh/plural-cli/pkg/manifest" "github.com/pluralsh/plural-cli/pkg/provider/permissions" provUtils "github.com/pluralsh/plural-cli/pkg/provider/utils" - "github.com/pluralsh/plural-cli/pkg/template" "github.com/pluralsh/plural-cli/pkg/utils" utilerr "github.com/pluralsh/plural-cli/pkg/utils/errors" ) @@ -253,34 +252,6 @@ func (gcp *GCPProvider) CreateBucket() error { return utilerr.ErrorWrap(err, fmt.Sprintf("Failed to create terraform state bucket %s", gcp.Bucket())) } -func (gcp *GCPProvider) CreateBackend(prefix string, version string, ctx map[string]interface{}) (string, error) { - if err := gcp.CreateBucket(); err != nil { - return "", err - } - - ctx["Project"] = gcp.Project() - // Location is here for backwards compatibility - ctx["Location"] = gcp.Context()["Location"] - ctx["Region"] = gcp.Region() - ctx["Bucket"] = gcp.Bucket() - _, location := gcp.clusterLocation() - ctx["ClusterLocation"] = location - ctx["Prefix"] = prefix - ctx["ClusterCreated"] = false - ctx["__CLUSTER__"] = gcp.Cluster() - if cluster, ok := ctx["cluster"]; ok { - ctx["Cluster"] = cluster - ctx["ClusterCreated"] = true - } else { - ctx["Cluster"] = fmt.Sprintf(`"%s"`, gcp.Cluster()) - } - scaffold, err := GetProviderScaffold(api.ToGQLClientProvider(api.ProviderGCP), version) - if err != nil { - return "", err - } - return template.RenderString(scaffold, ctx) -} - func (gcp *GCPProvider) mkBucket(name string) error { bkt := gcp.storageClient.Bucket(name) if _, err := bkt.Attrs(context.Background()); err != nil { diff --git a/pkg/provider/kind.go b/pkg/provider/kind.go index e8f5782bd..8d78864c7 100644 --- a/pkg/provider/kind.go +++ b/pkg/provider/kind.go @@ -3,7 +3,6 @@ package provider import ( "fmt" "os/exec" - "path/filepath" "github.com/pluralsh/plural-cli/pkg/api" "github.com/pluralsh/plural-cli/pkg/kubernetes" @@ -14,9 +13,7 @@ import ( "github.com/pluralsh/plural-cli/pkg/config" "github.com/pluralsh/plural-cli/pkg/manifest" "github.com/pluralsh/plural-cli/pkg/provider/permissions" - "github.com/pluralsh/plural-cli/pkg/template" "github.com/pluralsh/plural-cli/pkg/utils" - "github.com/pluralsh/plural-cli/pkg/utils/pathing" ) type KINDProvider struct { @@ -73,33 +70,6 @@ func kindFromManifest(man *manifest.ProjectManifest) (*KINDProvider, error) { func (kind *KINDProvider) CreateBucket() error { return nil } -func (kind *KINDProvider) CreateBackend(prefix string, version string, ctx map[string]interface{}) (string, error) { - - ctx["Region"] = kind.Region() - ctx["Bucket"] = kind.Bucket() - ctx["Prefix"] = prefix - ctx["ClusterCreated"] = false - ctx["__CLUSTER__"] = kind.Cluster() - if cluster, ok := ctx["cluster"]; ok { - ctx["Cluster"] = cluster - ctx["ClusterCreated"] = true - } else { - ctx["Cluster"] = fmt.Sprintf(`"%s"`, kind.Cluster()) - } - - if err := utils.WriteFile(pathing.SanitizeFilepath(filepath.Join(kind.Bucket(), ".gitignore")), []byte("!/**")); err != nil { - return "", err - } - if err := utils.WriteFile(pathing.SanitizeFilepath(filepath.Join(kind.Bucket(), ".gitattributes")), []byte("/** filter=plural-crypt diff=plural-crypt\n.gitattributes !filter !diff")); err != nil { - return "", err - } - scaffold, err := GetProviderScaffold(api.ToGQLClientProvider(api.ProviderKind), version) - if err != nil { - return "", err - } - return template.RenderString(scaffold, ctx) -} - func (kind *KINDProvider) KubeConfig() error { if kubernetes.InKubernetes() { return nil diff --git a/pkg/provider/linode.go b/pkg/provider/linode.go index 088b4991b..73c9e1010 100644 --- a/pkg/provider/linode.go +++ b/pkg/provider/linode.go @@ -173,10 +173,6 @@ func (l *LinodeProvider) CreateBucket() error { return godotenv.Load(envPath) } -func (l *LinodeProvider) CreateBackend(prefix string, version string, ctx map[string]interface{}) (string, error) { - return "", nil -} - func (l *LinodeProvider) KubeConfig() error { if kubernetes.InKubernetes() { return nil diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index 08754fea5..0810ff906 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -25,7 +25,6 @@ type Provider interface { Bucket() string KubeConfig() error KubeContext() string - CreateBackend(prefix string, version string, ctx map[string]interface{}) (string, error) CreateBucket() error Context() map[string]interface{} Preflights() []*Preflight @@ -59,22 +58,6 @@ var ( filterProviders = containers.ToSet([]string{"GENERIC", "KIND", "LINODE"}) ) -func GetProviderScaffold(provider, version string) (string, error) { - if providers.Scaffolds == nil { - providers.Scaffolds = make(map[string]string) - } - _, ok := providers.Scaffolds[provider] - if !ok { - client := api.NewClient() - scaffold, err := client.GetTfProviderScaffold(provider, version) - providers.Scaffolds[provider] = scaffold - if err != nil { - return "", api.GetErrorResponse(err, "GetTfProviderScaffold") - } - } - return providers.Scaffolds[provider], nil -} - func GetProvider() (Provider, error) { path := manifest.ProjectManifestPath() if project, err := manifest.ReadProject(path); err == nil { diff --git a/pkg/provider/test.go b/pkg/provider/test.go index 2b4a578a2..90d092515 100644 --- a/pkg/provider/test.go +++ b/pkg/provider/test.go @@ -46,10 +46,6 @@ func (t TestProvider) KubeContext() string { func (t TestProvider) CreateBucket() error { return nil } -func (t TestProvider) CreateBackend(prefix string, version string, ctx map[string]interface{}) (string, error) { - return "test", nil -} - func (t TestProvider) Context() map[string]interface{} { return map[string]interface{}{} } diff --git a/pkg/utils/kind.go b/pkg/utils/kind.go deleted file mode 100644 index bb6705f8c..000000000 --- a/pkg/utils/kind.go +++ /dev/null @@ -1,31 +0,0 @@ -package utils - -import ( - "os/exec" - "strings" -) - -const noKindClustersError = "No kind clusters found." - -func IsKindClusterAlreadyExists(name string) bool { - cmd := exec.Command("kind", "get", "clusters") - out, err := ExecuteWithOutput(cmd) - if err != nil { - return false - } - if strings.Contains(out, noKindClustersError) { - return false - } - - return strings.Contains(out, name) -} - -func GetKindClusterKubeconfig(name string, internal bool) (string, error) { - kubeconfigArgs := []string{"get", "kubeconfig", "--name", name} - if internal { - kubeconfigArgs = append(kubeconfigArgs, "--internal") - } - - cmd := exec.Command("kind", kubeconfigArgs...) - return ExecuteWithOutput(cmd) -} diff --git a/pkg/wkspace/minimal.go b/pkg/wkspace/minimal.go index e4168b3e4..2f6e7b81f 100644 --- a/pkg/wkspace/minimal.go +++ b/pkg/wkspace/minimal.go @@ -52,22 +52,6 @@ type MinimalWorkspace struct { HelmConfig *action.Configuration } -func Minimal(name string, helmConfig *action.Configuration) (*MinimalWorkspace, error) { - root, err := git.Root() - if err != nil { - return nil, err - } - - prov, err := provider.GetProvider() - if err != nil { - return nil, err - } - - project, _ := manifest.ReadProject(pathing.SanitizeFilepath(filepath.Join(root, "workspace.yaml"))) - conf := config.Read() - return &MinimalWorkspace{Name: name, Provider: prov, Config: &conf, Manifest: project, HelmConfig: helmConfig}, nil -} - func FormatValues(w io.Writer, vals string, output *output.Output) (err error) { tmpl, err := template.New("gotpl").Parse(vals) if err != nil {