diff --git a/cmd/cdev/includes.go b/cmd/cdev/includes.go index 6b98917e..9db9e9d1 100644 --- a/cmd/cdev/includes.go +++ b/cmd/cdev/includes.go @@ -1,18 +1,18 @@ package main import ( - _ "github.com/shalb/cluster.dev/pkg/backend/azurerm" - _ "github.com/shalb/cluster.dev/pkg/backend/gcs" - _ "github.com/shalb/cluster.dev/pkg/backend/local" - _ "github.com/shalb/cluster.dev/pkg/backend/s3" + _ "github.com/shalb/cluster.dev/internal/backend/azurerm" + _ "github.com/shalb/cluster.dev/internal/backend/gcs" + _ "github.com/shalb/cluster.dev/internal/backend/local" + _ "github.com/shalb/cluster.dev/internal/backend/s3" + _ "github.com/shalb/cluster.dev/internal/project" + _ "github.com/shalb/cluster.dev/internal/secrets/aws_secretmanager" + _ "github.com/shalb/cluster.dev/internal/secrets/sops" + _ "github.com/shalb/cluster.dev/internal/units/shell/common" + _ "github.com/shalb/cluster.dev/internal/units/shell/k8s_manifest" + _ "github.com/shalb/cluster.dev/internal/units/shell/terraform/helm" + _ "github.com/shalb/cluster.dev/internal/units/shell/terraform/kubernetes" + _ "github.com/shalb/cluster.dev/internal/units/shell/terraform/module" + _ "github.com/shalb/cluster.dev/internal/units/shell/terraform/printer" _ "github.com/shalb/cluster.dev/pkg/logging" - _ "github.com/shalb/cluster.dev/pkg/project" - _ "github.com/shalb/cluster.dev/pkg/secrets/aws_secretmanager" - _ "github.com/shalb/cluster.dev/pkg/secrets/sops" - _ "github.com/shalb/cluster.dev/pkg/units/shell/common" - _ "github.com/shalb/cluster.dev/pkg/units/shell/k8s_manifest" - _ "github.com/shalb/cluster.dev/pkg/units/shell/terraform/helm" - _ "github.com/shalb/cluster.dev/pkg/units/shell/terraform/kubernetes" - _ "github.com/shalb/cluster.dev/pkg/units/shell/terraform/module" - _ "github.com/shalb/cluster.dev/pkg/units/shell/terraform/printer" ) diff --git a/cmd/cdev/main.go b/cmd/cdev/main.go index fe2e792b..4acad907 100644 --- a/cmd/cdev/main.go +++ b/cmd/cdev/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/shalb/cluster.dev/pkg/cmd/cdev" + "github.com/shalb/cluster.dev/internal/cmd/cdev" ) func main() { diff --git a/go.mod b/go.mod index af7d7c24..e5c0a00e 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.0 github.com/aws/aws-sdk-go-v2/service/s3 v1.50.2 github.com/getsops/sops/v3 v3.8.1 + github.com/google/go-github v17.0.0+incompatible github.com/gookit/color v1.5.4 github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.48 github.com/hashicorp/hcl/v2 v2.19.1 @@ -29,7 +30,7 @@ require ( github.com/spf13/cobra v1.7.0 github.com/tj/go-spin v1.1.0 github.com/zclconf/go-cty v1.14.1 - golang.org/x/crypto v0.21.0 + golang.org/x/crypto v0.24.0 golang.org/x/oauth2 v0.13.0 google.golang.org/api v0.148.0 gopkg.in/yaml.v3 v3.0.1 @@ -40,7 +41,6 @@ require ( require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0 // indirect github.com/go-jose/go-jose/v3 v3.0.1 // indirect - github.com/google/go-github v17.0.0+incompatible // indirect github.com/google/go-github/v60 v60.0.0 // indirect github.com/google/go-querystring v1.1.0 // indirect ) @@ -191,12 +191,12 @@ require ( go.opentelemetry.io/otel/trace v1.23.1 // indirect go.starlark.net v0.0.0-20231016134836-22325403fcb3 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect - golang.org/x/mod v0.13.0 // indirect - golang.org/x/net v0.21.0 // indirect - golang.org/x/sync v0.4.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/term v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/term v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/appengine v1.6.8 // indirect @@ -204,7 +204,7 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect google.golang.org/grpc v1.59.0 // indirect - google.golang.org/protobuf v1.31.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/evanphx/json-patch.v5 v5.7.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/pkg/backend/azurerm/azurerm.go b/internal/backend/azurerm/azurerm.go similarity index 99% rename from pkg/backend/azurerm/azurerm.go rename to internal/backend/azurerm/azurerm.go index 0ec59c58..355d9e6b 100644 --- a/pkg/backend/azurerm/azurerm.go +++ b/internal/backend/azurerm/azurerm.go @@ -6,12 +6,12 @@ import ( "fmt" "strings" - "github.com/apex/log" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" + "github.com/apex/log" "github.com/hashicorp/hcl/v2/hclwrite" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/hcltools" - "github.com/shalb/cluster.dev/pkg/project" "github.com/shalb/cluster.dev/pkg/utils" "github.com/zclconf/go-cty/cty" "gopkg.in/yaml.v3" diff --git a/pkg/backend/azurerm/factory.go b/internal/backend/azurerm/factory.go similarity index 93% rename from pkg/backend/azurerm/factory.go rename to internal/backend/azurerm/factory.go index e2d527af..2c428d70 100644 --- a/pkg/backend/azurerm/factory.go +++ b/internal/backend/azurerm/factory.go @@ -2,7 +2,7 @@ package azurerm import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) diff --git a/pkg/backend/gcs/factory.go b/internal/backend/gcs/factory.go similarity index 94% rename from pkg/backend/gcs/factory.go rename to internal/backend/gcs/factory.go index e7cf5551..9806efc0 100644 --- a/pkg/backend/gcs/factory.go +++ b/internal/backend/gcs/factory.go @@ -2,7 +2,7 @@ package gcs import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) diff --git a/pkg/backend/gcs/gcs.go b/internal/backend/gcs/gcs.go similarity index 99% rename from pkg/backend/gcs/gcs.go rename to internal/backend/gcs/gcs.go index a08d2ae5..6131434f 100644 --- a/pkg/backend/gcs/gcs.go +++ b/internal/backend/gcs/gcs.go @@ -12,7 +12,7 @@ import ( "cloud.google.com/go/storage" "github.com/hashicorp/hcl/v2/hclwrite" "github.com/shalb/cluster.dev/pkg/hcltools" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" "github.com/zclconf/go-cty/cty" "golang.org/x/oauth2" diff --git a/pkg/backend/local/factory.go b/internal/backend/local/factory.go similarity index 92% rename from pkg/backend/local/factory.go rename to internal/backend/local/factory.go index 80f3a4c2..ef63ad3d 100644 --- a/pkg/backend/local/factory.go +++ b/internal/backend/local/factory.go @@ -6,8 +6,8 @@ import ( "path/filepath" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) diff --git a/pkg/backend/local/project.go b/internal/backend/local/project.go similarity index 100% rename from pkg/backend/local/project.go rename to internal/backend/local/project.go diff --git a/pkg/backend/local/unit.go b/internal/backend/local/unit.go similarity index 97% rename from pkg/backend/local/unit.go rename to internal/backend/local/unit.go index 2a86df90..3d82235a 100644 --- a/pkg/backend/local/unit.go +++ b/internal/backend/local/unit.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/hashicorp/hcl/v2/hclwrite" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/zclconf/go-cty/cty" ) diff --git a/pkg/backend/s3/factory.go b/internal/backend/s3/factory.go similarity index 94% rename from pkg/backend/s3/factory.go rename to internal/backend/s3/factory.go index 2b932595..4fc099e7 100644 --- a/pkg/backend/s3/factory.go +++ b/internal/backend/s3/factory.go @@ -2,7 +2,7 @@ package s3 import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) diff --git a/pkg/backend/s3/s3.go b/internal/backend/s3/s3.go similarity index 98% rename from pkg/backend/s3/s3.go rename to internal/backend/s3/s3.go index 29bb8c02..14e6de88 100644 --- a/pkg/backend/s3/s3.go +++ b/internal/backend/s3/s3.go @@ -15,8 +15,8 @@ import ( "github.com/aws/aws-sdk-go-v2/service/s3/types" awsbase "github.com/hashicorp/aws-sdk-go-base/v2" "github.com/hashicorp/hcl/v2/hclwrite" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" "github.com/zclconf/go-cty/cty" "gopkg.in/yaml.v3" diff --git a/pkg/cmd/cdev/apply.go b/internal/cmd/cdev/apply.go similarity index 94% rename from pkg/cmd/cdev/apply.go rename to internal/cmd/cdev/apply.go index b9b7461b..e81ce851 100644 --- a/pkg/cmd/cdev/apply.go +++ b/internal/cmd/cdev/apply.go @@ -2,8 +2,8 @@ package cdev import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" "github.com/spf13/cobra" ) diff --git a/pkg/cmd/cdev/build.go b/internal/cmd/cdev/build.go similarity index 92% rename from pkg/cmd/cdev/build.go rename to internal/cmd/cdev/build.go index ef82c8ce..b440bc1d 100644 --- a/pkg/cmd/cdev/build.go +++ b/internal/cmd/cdev/build.go @@ -2,7 +2,7 @@ package cdev import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/spf13/cobra" ) diff --git a/pkg/cmd/cdev/destroy.go b/internal/cmd/cdev/destroy.go similarity index 92% rename from pkg/cmd/cdev/destroy.go rename to internal/cmd/cdev/destroy.go index 6859fc71..a3db2939 100644 --- a/pkg/cmd/cdev/destroy.go +++ b/internal/cmd/cdev/destroy.go @@ -2,8 +2,8 @@ package cdev import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/spf13/cobra" ) diff --git a/pkg/cmd/cdev/main.go b/internal/cmd/cdev/main.go similarity index 98% rename from pkg/cmd/cdev/main.go rename to internal/cmd/cdev/main.go index c2a78a31..27c56c17 100644 --- a/pkg/cmd/cdev/main.go +++ b/internal/cmd/cdev/main.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/profiler" "github.com/shalb/cluster.dev/pkg/utils" "github.com/spf13/cobra" diff --git a/pkg/cmd/cdev/output.go b/internal/cmd/cdev/output.go similarity index 89% rename from pkg/cmd/cdev/output.go rename to internal/cmd/cdev/output.go index acb9262b..6865b162 100644 --- a/pkg/cmd/cdev/output.go +++ b/internal/cmd/cdev/output.go @@ -2,8 +2,8 @@ package cdev import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/spf13/cobra" ) diff --git a/pkg/cmd/cdev/plan.go b/internal/cmd/cdev/plan.go similarity index 91% rename from pkg/cmd/cdev/plan.go rename to internal/cmd/cdev/plan.go index 220a859e..427a7712 100644 --- a/pkg/cmd/cdev/plan.go +++ b/internal/cmd/cdev/plan.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/spf13/cobra" ) diff --git a/pkg/cmd/cdev/project.go b/internal/cmd/cdev/project.go similarity index 92% rename from pkg/cmd/cdev/project.go rename to internal/cmd/cdev/project.go index 00113ca2..88cb1c3a 100644 --- a/pkg/cmd/cdev/project.go +++ b/internal/cmd/cdev/project.go @@ -5,9 +5,9 @@ import ( "strings" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/project/ui" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/project/ui" "github.com/spf13/cobra" ) diff --git a/pkg/cmd/cdev/secrets.go b/internal/cmd/cdev/secrets.go similarity index 93% rename from pkg/cmd/cdev/secrets.go rename to internal/cmd/cdev/secrets.go index 8f900564..eecc9533 100644 --- a/pkg/cmd/cdev/secrets.go +++ b/internal/cmd/cdev/secrets.go @@ -2,8 +2,8 @@ package cdev import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/project/ui" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/project/ui" "github.com/spf13/cobra" ) diff --git a/pkg/cmd/cdev/state.go b/internal/cmd/cdev/state.go similarity index 95% rename from pkg/cmd/cdev/state.go rename to internal/cmd/cdev/state.go index d13570d6..def9108d 100644 --- a/pkg/cmd/cdev/state.go +++ b/internal/cmd/cdev/state.go @@ -2,8 +2,8 @@ package cdev import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/spf13/cobra" ) diff --git a/pkg/cmd/cdev/types.go b/internal/cmd/cdev/types.go similarity index 84% rename from pkg/cmd/cdev/types.go rename to internal/cmd/cdev/types.go index 9e75d207..9d21b40d 100644 --- a/pkg/cmd/cdev/types.go +++ b/internal/cmd/cdev/types.go @@ -3,8 +3,8 @@ package cdev import ( "runtime" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" ) type CmdErrExtended struct { diff --git a/pkg/config/config.go b/internal/config/config.go similarity index 100% rename from pkg/config/config.go rename to internal/config/config.go diff --git a/pkg/config/targetcheck.go b/internal/config/targetcheck.go similarity index 100% rename from pkg/config/targetcheck.go rename to internal/config/targetcheck.go diff --git a/pkg/project/backend.go b/internal/project/backend.go similarity index 100% rename from pkg/project/backend.go rename to internal/project/backend.go diff --git a/pkg/project/commands.go b/internal/project/commands.go similarity index 99% rename from pkg/project/commands.go rename to internal/project/commands.go index 4c3c3033..a30389b4 100644 --- a/pkg/project/commands.go +++ b/internal/project/commands.go @@ -8,8 +8,8 @@ import ( "github.com/apex/log" "github.com/paulrademacher/climenu" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/colors" - "github.com/shalb/cluster.dev/pkg/config" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/project/dependencies.go b/internal/project/dependencies.go similarity index 100% rename from pkg/project/dependencies.go rename to internal/project/dependencies.go diff --git a/pkg/project/graph.go b/internal/project/graph.go similarity index 99% rename from pkg/project/graph.go rename to internal/project/graph.go index f1b6e540..e1bb01ce 100644 --- a/pkg/project/graph.go +++ b/internal/project/graph.go @@ -5,7 +5,7 @@ import ( "sync" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" ) type ExecutionStatus uint16 diff --git a/pkg/project/helpers.go b/internal/project/helpers.go similarity index 91% rename from pkg/project/helpers.go rename to internal/project/helpers.go index f2311153..2db31f3d 100644 --- a/pkg/project/helpers.go +++ b/internal/project/helpers.go @@ -1,6 +1,7 @@ package project import ( + "context" "fmt" "os" "path/filepath" @@ -8,11 +9,13 @@ import ( "regexp" "strings" + "github.com/Masterminds/semver" "github.com/apex/log" + "github.com/google/go-github/github" "github.com/olekukonko/tablewriter" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/colors" - "github.com/shalb/cluster.dev/pkg/config" "github.com/shalb/cluster.dev/pkg/utils" ) @@ -129,6 +132,33 @@ func (s *ProjectPlanningStatus) AddOrUpdate(u Unit, op UnitOperation, diff strin } } +func DiscoverCdevLastRelease() error { + var ( + client = github.NewClient(nil) + ctx = context.Background() + org string = "shalb" + project string = "cluster.dev" + ) + + latestRelease, _, err := client.Repositories.GetLatestRelease(ctx, org, project) + if err != nil { + return err + } + curVersion, err := semver.NewVersion(config.Version) + if err != nil { + return fmt.Errorf("check failed: %v, current version: %v", err, config.Global.Version) + } + reqVerConstraints, err := semver.NewConstraint(*latestRelease.TagName) + if err != nil { + return fmt.Errorf("check failed: %v, latest stable release: %v", err, *latestRelease.TagName) + } + ok, _ := reqVerConstraints.Validate(curVersion) + if !ok { + return fmt.Errorf("the new cdev version is available. Current version: '%v', latest stable release: '%v'. Visit https://docs.cluster.dev/installation-upgrade/ to upgrade", curVersion, *latestRelease.TagName) + } + return nil +} + func (s *ProjectPlanningStatus) AddIfNotExists(u Unit, op UnitOperation, diff string, tainted bool) { existingUnit := s.FindUnitByKey(u) if existingUnit == nil { diff --git a/pkg/project/project.go b/internal/project/project.go similarity index 99% rename from pkg/project/project.go rename to internal/project/project.go index 87029ca2..454b9ce7 100644 --- a/pkg/project/project.go +++ b/internal/project/project.go @@ -10,7 +10,7 @@ import ( "github.com/apex/log" "github.com/gookit/color" "github.com/olekukonko/tablewriter" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) @@ -77,7 +77,7 @@ func NewEmptyProject() *Project { CodeCacheDir: config.Global.CacheDir, } log.Info("Checking for newer releases...") - err := utils.DiscoverCdevLastRelease() + err := DiscoverCdevLastRelease() if err != nil { log.Warnf("Version check: %v.", err) project.NewVersionMessage = fmt.Sprintf("Version check: %v", err.Error()) diff --git a/pkg/project/project_config.go b/internal/project/project_config.go similarity index 98% rename from pkg/project/project_config.go rename to internal/project/project_config.go index e52be347..448e195c 100644 --- a/pkg/project/project_config.go +++ b/internal/project/project_config.go @@ -7,7 +7,7 @@ import ( "regexp" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) diff --git a/pkg/project/scanners.go b/internal/project/scanners.go similarity index 100% rename from pkg/project/scanners.go rename to internal/project/scanners.go diff --git a/pkg/project/secret.go b/internal/project/secret.go similarity index 98% rename from pkg/project/secret.go rename to internal/project/secret.go index 74330e35..89e6d182 100644 --- a/pkg/project/secret.go +++ b/internal/project/secret.go @@ -8,7 +8,7 @@ import ( "github.com/apex/log" "github.com/olekukonko/tablewriter" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/project/stack.go b/internal/project/stack.go similarity index 99% rename from pkg/project/stack.go rename to internal/project/stack.go index f7524c3c..f6ec6b7b 100644 --- a/pkg/project/stack.go +++ b/internal/project/stack.go @@ -6,7 +6,7 @@ import ( "path/filepath" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/project/stack_template.go b/internal/project/stack_template.go similarity index 98% rename from pkg/project/stack_template.go rename to internal/project/stack_template.go index 508c862c..c56a7bb5 100644 --- a/pkg/project/stack_template.go +++ b/internal/project/stack_template.go @@ -5,7 +5,7 @@ import ( "github.com/Masterminds/semver" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) diff --git a/pkg/project/state.go b/internal/project/state.go similarity index 98% rename from pkg/project/state.go rename to internal/project/state.go index 749cd348..81d5b69f 100644 --- a/pkg/project/state.go +++ b/internal/project/state.go @@ -11,8 +11,8 @@ import ( "github.com/apex/log" "github.com/google/uuid" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/colors" - "github.com/shalb/cluster.dev/pkg/config" "github.com/shalb/cluster.dev/pkg/utils" ) @@ -237,7 +237,7 @@ func (p *Project) LoadState() (*StateProject, error) { if err != nil { return nil, err } - for key, _ := range statePrj.Units { + for key := range statePrj.Units { log.Warnf("LoadState %v", key) } diff --git a/pkg/project/templating.go b/internal/project/templating.go similarity index 99% rename from pkg/project/templating.go rename to internal/project/templating.go index b5252a04..bbcce76d 100644 --- a/pkg/project/templating.go +++ b/internal/project/templating.go @@ -10,7 +10,7 @@ import ( "github.com/Masterminds/sprig" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" "github.com/shalb/cluster.dev/pkg/utils" "golang.org/x/crypto/bcrypt" "gopkg.in/yaml.v3" diff --git a/pkg/project/ui/fs.go b/internal/project/ui/fs.go similarity index 100% rename from pkg/project/ui/fs.go rename to internal/project/ui/fs.go diff --git a/pkg/project/ui/generator.go b/internal/project/ui/generator.go similarity index 99% rename from pkg/project/ui/generator.go rename to internal/project/ui/generator.go index 4876e8f2..957bad56 100644 --- a/pkg/project/ui/generator.go +++ b/internal/project/ui/generator.go @@ -12,8 +12,8 @@ import ( "github.com/apex/log" "github.com/paulrademacher/climenu" - "github.com/shalb/cluster.dev/pkg/config" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) diff --git a/pkg/project/ui/templates/secret/aws_secretmanager/config.yaml b/internal/project/ui/templates/secret/aws_secretmanager/config.yaml similarity index 100% rename from pkg/project/ui/templates/secret/aws_secretmanager/config.yaml rename to internal/project/ui/templates/secret/aws_secretmanager/config.yaml diff --git a/pkg/project/ui/templates/secret/aws_secretmanager/data/secret_name.yaml b/internal/project/ui/templates/secret/aws_secretmanager/data/secret_name.yaml similarity index 100% rename from pkg/project/ui/templates/secret/aws_secretmanager/data/secret_name.yaml rename to internal/project/ui/templates/secret/aws_secretmanager/data/secret_name.yaml diff --git a/pkg/project/ui/templates/secret/config.yaml b/internal/project/ui/templates/secret/config.yaml similarity index 100% rename from pkg/project/ui/templates/secret/config.yaml rename to internal/project/ui/templates/secret/config.yaml diff --git a/pkg/project/ui/templates/secret/sops/config.yaml b/internal/project/ui/templates/secret/sops/config.yaml similarity index 100% rename from pkg/project/ui/templates/secret/sops/config.yaml rename to internal/project/ui/templates/secret/sops/config.yaml diff --git a/pkg/project/ui/templates/secret/sops/data/secret_name.yaml b/internal/project/ui/templates/secret/sops/data/secret_name.yaml similarity index 100% rename from pkg/project/ui/templates/secret/sops/data/secret_name.yaml rename to internal/project/ui/templates/secret/sops/data/secret_name.yaml diff --git a/pkg/project/ulinks.go b/internal/project/ulinks.go similarity index 100% rename from pkg/project/ulinks.go rename to internal/project/ulinks.go diff --git a/pkg/project/unit.go b/internal/project/unit.go similarity index 100% rename from pkg/project/unit.go rename to internal/project/unit.go diff --git a/pkg/secrets/aws_secretmanager/main.go b/internal/secrets/aws_secretmanager/main.go similarity index 88% rename from pkg/secrets/aws_secretmanager/main.go rename to internal/secrets/aws_secretmanager/main.go index c72e1b9c..543f51d5 100644 --- a/pkg/secrets/aws_secretmanager/main.go +++ b/internal/secrets/aws_secretmanager/main.go @@ -7,10 +7,10 @@ import ( "path/filepath" "github.com/apex/log" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/aws" - "github.com/shalb/cluster.dev/pkg/config" "github.com/shalb/cluster.dev/pkg/executor" - "github.com/shalb/cluster.dev/pkg/project" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) @@ -52,10 +52,8 @@ func (s *smDriver) Read(rawData []byte) (name string, data interface{}, err erro return } if spec.Region == "" || spec.SecretName == "" { - if err != nil { - err = fmt.Errorf("aws_secretmanager: can't parse secret '%v', fields 'spec.region' and 'spec.secret_name' are required", name) - return - } + err = fmt.Errorf("aws_secretmanager: can't parse secret '%v', fields 'spec.region' and 'spec.secret_name' are required", name) + return } data, err = aws.GetSecret(spec.Region, spec.SecretName) if err != nil { @@ -77,7 +75,7 @@ func init() { } func (s *smDriver) Edit(sec project.Secret) error { - runner, err := executor.NewExecutor(config.Global.WorkingDir) + runner, err := executor.NewExecutor(config.Global.WorkingDir, &config.Interrupted) if err != nil { return err } @@ -94,7 +92,7 @@ func (s *smDriver) Edit(sec project.Secret) error { } func (s *smDriver) Create(files map[string][]byte) error { - runner, err := executor.NewExecutor(config.Global.WorkingDir) + runner, err := executor.NewExecutor(config.Global.WorkingDir, &config.Interrupted) if err != nil { return fmt.Errorf("create secret: %v", err.Error()) } diff --git a/pkg/secrets/sops/main.go b/internal/secrets/sops/main.go similarity index 91% rename from pkg/secrets/sops/main.go rename to internal/secrets/sops/main.go index d7dbe6fa..19db82e6 100644 --- a/pkg/secrets/sops/main.go +++ b/internal/secrets/sops/main.go @@ -7,9 +7,9 @@ import ( "path/filepath" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/executor" - "github.com/shalb/cluster.dev/pkg/project" "github.com/shalb/cluster.dev/pkg/sopstools" "github.com/shalb/cluster.dev/pkg/utils" ) @@ -56,7 +56,7 @@ func init() { } func (s *sopsDriver) Edit(sec project.Secret) error { - runner, err := executor.NewExecutor(config.Global.WorkingDir) + runner, err := executor.NewExecutor(config.Global.WorkingDir, &config.Interrupted) if err != nil { return err } @@ -70,7 +70,7 @@ func (s *sopsDriver) Edit(sec project.Secret) error { } func (s *sopsDriver) Create(files map[string][]byte) error { - runner, err := executor.NewExecutor(config.Global.WorkingDir) + runner, err := executor.NewExecutor(config.Global.WorkingDir, &config.Interrupted) if err != nil { return err } diff --git a/pkg/units/shell/common/factory.go b/internal/units/shell/common/factory.go similarity index 97% rename from pkg/units/shell/common/factory.go rename to internal/units/shell/common/factory.go index 74b8e97e..59a5ea75 100644 --- a/pkg/units/shell/common/factory.go +++ b/internal/units/shell/common/factory.go @@ -2,7 +2,7 @@ package common import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" ) // Factory factory for s3 backends. diff --git a/pkg/units/shell/common/files.go b/internal/units/shell/common/files.go similarity index 100% rename from pkg/units/shell/common/files.go rename to internal/units/shell/common/files.go diff --git a/pkg/units/shell/common/generators.go b/internal/units/shell/common/generators.go similarity index 96% rename from pkg/units/shell/common/generators.go rename to internal/units/shell/common/generators.go index 2dcb0aeb..9754f4ec 100644 --- a/pkg/units/shell/common/generators.go +++ b/internal/units/shell/common/generators.go @@ -6,7 +6,7 @@ import ( "os" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/common/parsers.go b/internal/units/shell/common/parsers.go similarity index 98% rename from pkg/units/shell/common/parsers.go rename to internal/units/shell/common/parsers.go index 1d694779..81561e48 100644 --- a/pkg/units/shell/common/parsers.go +++ b/internal/units/shell/common/parsers.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/common/state.go b/internal/units/shell/common/state.go similarity index 98% rename from pkg/units/shell/common/state.go rename to internal/units/shell/common/state.go index bcd5da28..2313d232 100644 --- a/pkg/units/shell/common/state.go +++ b/internal/units/shell/common/state.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/common/unit.go b/internal/units/shell/common/unit.go similarity index 98% rename from pkg/units/shell/common/unit.go rename to internal/units/shell/common/unit.go index b090216b..a305db50 100644 --- a/pkg/units/shell/common/unit.go +++ b/internal/units/shell/common/unit.go @@ -8,9 +8,9 @@ import ( "sync" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/executor" - "github.com/shalb/cluster.dev/pkg/project" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) @@ -345,7 +345,7 @@ func (u *Unit) runCommands(commandsCnf OperationConfig, name string) ([]byte, er if err != nil { return nil, err } - rn, err := executor.NewExecutor(u.CacheDir, u.EnvSlice()...) + rn, err := executor.NewExecutor(u.CacheDir, &config.Interrupted, u.EnvSlice()...) if err != nil { log.Debug(err.Error()) return nil, err diff --git a/pkg/units/shell/k8s_manifest/factory.go b/internal/units/shell/k8s_manifest/factory.go similarity index 93% rename from pkg/units/shell/k8s_manifest/factory.go rename to internal/units/shell/k8s_manifest/factory.go index 34b38a35..c7c7b985 100644 --- a/pkg/units/shell/k8s_manifest/factory.go +++ b/internal/units/shell/k8s_manifest/factory.go @@ -2,8 +2,8 @@ package base import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" ) // Factory factory for s3 backends. diff --git a/pkg/units/shell/k8s_manifest/state.go b/internal/units/shell/k8s_manifest/state.go similarity index 94% rename from pkg/units/shell/k8s_manifest/state.go rename to internal/units/shell/k8s_manifest/state.go index 6ec14d25..171ecf4e 100644 --- a/pkg/units/shell/k8s_manifest/state.go +++ b/internal/units/shell/k8s_manifest/state.go @@ -5,8 +5,8 @@ import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/k8s_manifest/unit.go b/internal/units/shell/k8s_manifest/unit.go similarity index 97% rename from pkg/units/shell/k8s_manifest/unit.go rename to internal/units/shell/k8s_manifest/unit.go index b6b2aba1..24adb1f0 100644 --- a/pkg/units/shell/k8s_manifest/unit.go +++ b/internal/units/shell/k8s_manifest/unit.go @@ -6,10 +6,10 @@ import ( "path/filepath" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" "github.com/shalb/cluster.dev/pkg/executor" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" "github.com/shalb/cluster.dev/pkg/utils" "gopkg.in/yaml.v3" ) @@ -84,7 +84,7 @@ func (u *Unit) fillShellUnit() { } func (u *Unit) createNamespacesIfNotExists() error { - rn, err := executor.NewExecutor(u.CacheDir) + rn, err := executor.NewExecutor(u.CacheDir, &config.Interrupted) if err != nil { log.Debug(err.Error()) return fmt.Errorf("create namespace: %w", err) diff --git a/pkg/units/shell/terraform/base/factory.go b/internal/units/shell/terraform/base/factory.go similarity index 91% rename from pkg/units/shell/terraform/base/factory.go rename to internal/units/shell/terraform/base/factory.go index 6fcf7e3f..dd74b2db 100644 --- a/pkg/units/shell/terraform/base/factory.go +++ b/internal/units/shell/terraform/base/factory.go @@ -2,8 +2,8 @@ package base import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" ) // Factory factory for s3 backends. diff --git a/pkg/units/shell/terraform/base/generators.go b/internal/units/shell/terraform/base/generators.go similarity index 98% rename from pkg/units/shell/terraform/base/generators.go rename to internal/units/shell/terraform/base/generators.go index 0c3d7dcd..4eb3f826 100644 --- a/pkg/units/shell/terraform/base/generators.go +++ b/internal/units/shell/terraform/base/generators.go @@ -6,8 +6,8 @@ import ( "strings" "github.com/apex/log" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/hcltools" - "github.com/shalb/cluster.dev/pkg/project" ) // genBackendCodeBlock generate backend code block for this unit. diff --git a/pkg/units/shell/terraform/base/parsers.go b/internal/units/shell/terraform/base/parsers.go similarity index 96% rename from pkg/units/shell/terraform/base/parsers.go rename to internal/units/shell/terraform/base/parsers.go index 0bbd0e67..69f1f931 100644 --- a/pkg/units/shell/terraform/base/parsers.go +++ b/internal/units/shell/terraform/base/parsers.go @@ -5,7 +5,7 @@ import ( "reflect" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/terraform/base/scanners.go b/internal/units/shell/terraform/base/scanners.go similarity index 97% rename from pkg/units/shell/terraform/base/scanners.go rename to internal/units/shell/terraform/base/scanners.go index 8369f743..8b2d209c 100644 --- a/pkg/units/shell/terraform/base/scanners.go +++ b/internal/units/shell/terraform/base/scanners.go @@ -5,7 +5,7 @@ import ( "reflect" "strings" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" ) // RemoteStatesScanner - project scanner function, witch process dependencies markers in unit data setted by AddRemoteStateMarker template function. diff --git a/pkg/units/shell/terraform/base/state.go b/internal/units/shell/terraform/base/state.go similarity index 96% rename from pkg/units/shell/terraform/base/state.go rename to internal/units/shell/terraform/base/state.go index 58a3e305..e43d91b6 100644 --- a/pkg/units/shell/terraform/base/state.go +++ b/internal/units/shell/terraform/base/state.go @@ -5,8 +5,8 @@ import ( "strings" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/terraform/base/template.go b/internal/units/shell/terraform/base/template.go similarity index 97% rename from pkg/units/shell/terraform/base/template.go rename to internal/units/shell/terraform/base/template.go index db5a3db7..ef73e960 100644 --- a/pkg/units/shell/terraform/base/template.go +++ b/internal/units/shell/terraform/base/template.go @@ -5,7 +5,7 @@ import ( "strings" "text/template" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" ) type terraformTemplateFunctions struct { diff --git a/pkg/units/shell/terraform/base/unit.go b/internal/units/shell/terraform/base/unit.go similarity index 93% rename from pkg/units/shell/terraform/base/unit.go rename to internal/units/shell/terraform/base/unit.go index 5ad85710..f847968b 100644 --- a/pkg/units/shell/terraform/base/unit.go +++ b/internal/units/shell/terraform/base/unit.go @@ -6,10 +6,10 @@ import ( "path/filepath" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" "github.com/shalb/cluster.dev/pkg/executor" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" ) // const remoteStateLinkType = "RemoteStateMarkers" @@ -136,7 +136,7 @@ func (u *Unit) Destroy() error { // Output unit. // TODO check this method, should be removed func (u *Unit) Output() (string, error) { - rn, err := executor.NewExecutor(u.CacheDir, u.EnvSlice()...) + rn, err := executor.NewExecutor(u.CacheDir, &config.Interrupted, u.EnvSlice()...) if err != nil { log.Debug(err.Error()) return "", err diff --git a/pkg/units/shell/terraform/base/utils.go b/internal/units/shell/terraform/base/utils.go similarity index 90% rename from pkg/units/shell/terraform/base/utils.go rename to internal/units/shell/terraform/base/utils.go index c9a33c6e..650ff581 100644 --- a/pkg/units/shell/terraform/base/utils.go +++ b/internal/units/shell/terraform/base/utils.go @@ -3,7 +3,7 @@ package base import ( "fmt" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" ) func DependencyToRemoteStateRef(dep *project.ULinkT) (remoteStateRef string) { diff --git a/pkg/units/shell/terraform/helm/factory.go b/internal/units/shell/terraform/helm/factory.go similarity index 90% rename from pkg/units/shell/terraform/helm/factory.go rename to internal/units/shell/terraform/helm/factory.go index 8bd03ad7..e67497da 100644 --- a/pkg/units/shell/terraform/helm/factory.go +++ b/internal/units/shell/terraform/helm/factory.go @@ -2,9 +2,9 @@ package helm import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" ) // Factory factory for s3 backends. diff --git a/pkg/units/shell/terraform/helm/main.go b/internal/units/shell/terraform/helm/main.go similarity index 97% rename from pkg/units/shell/terraform/helm/main.go rename to internal/units/shell/terraform/helm/main.go index 81d98666..7996f3ec 100644 --- a/pkg/units/shell/terraform/helm/main.go +++ b/internal/units/shell/terraform/helm/main.go @@ -9,11 +9,11 @@ import ( "github.com/apex/log" "github.com/hashicorp/hcl/v2/hclwrite" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/hcltools" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/utils" "github.com/zclconf/go-cty/cty" "gopkg.in/yaml.v3" diff --git a/pkg/units/shell/terraform/helm/state.go b/internal/units/shell/terraform/helm/state.go similarity index 94% rename from pkg/units/shell/terraform/helm/state.go rename to internal/units/shell/terraform/helm/state.go index f33c028d..8eb06f40 100644 --- a/pkg/units/shell/terraform/helm/state.go +++ b/internal/units/shell/terraform/helm/state.go @@ -6,8 +6,8 @@ import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/terraform/kubernetes/factory.go b/internal/units/shell/terraform/kubernetes/factory.go similarity index 92% rename from pkg/units/shell/terraform/kubernetes/factory.go rename to internal/units/shell/terraform/kubernetes/factory.go index 7b13978f..e66ac427 100644 --- a/pkg/units/shell/terraform/kubernetes/factory.go +++ b/internal/units/shell/terraform/kubernetes/factory.go @@ -2,8 +2,8 @@ package kubernetes import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" ) // Factory factory for s3 backends. diff --git a/pkg/units/shell/terraform/kubernetes/main.go b/internal/units/shell/terraform/kubernetes/main.go similarity index 98% rename from pkg/units/shell/terraform/kubernetes/main.go rename to internal/units/shell/terraform/kubernetes/main.go index 2fd40bbf..aedf537e 100644 --- a/pkg/units/shell/terraform/kubernetes/main.go +++ b/internal/units/shell/terraform/kubernetes/main.go @@ -9,10 +9,10 @@ import ( "github.com/apex/log" "github.com/hashicorp/hcl/v2/hclwrite" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/hcltools" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" - "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/internal/project" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/terraform/kubernetes/state.go b/internal/units/shell/terraform/kubernetes/state.go similarity index 91% rename from pkg/units/shell/terraform/kubernetes/state.go rename to internal/units/shell/terraform/kubernetes/state.go index f7d326a3..5569e0e1 100644 --- a/pkg/units/shell/terraform/kubernetes/state.go +++ b/internal/units/shell/terraform/kubernetes/state.go @@ -5,8 +5,8 @@ import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/terraform/module/factory.go b/internal/units/shell/terraform/module/factory.go similarity index 91% rename from pkg/units/shell/terraform/module/factory.go rename to internal/units/shell/terraform/module/factory.go index 1b46af8e..ba7b540f 100644 --- a/pkg/units/shell/terraform/module/factory.go +++ b/internal/units/shell/terraform/module/factory.go @@ -4,9 +4,9 @@ import ( "path/filepath" "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" ) // Factory factory for s3 backends. diff --git a/pkg/units/shell/terraform/module/main.go b/internal/units/shell/terraform/module/main.go similarity index 96% rename from pkg/units/shell/terraform/module/main.go rename to internal/units/shell/terraform/module/main.go index 0e325ab8..0cc1367e 100644 --- a/pkg/units/shell/terraform/module/main.go +++ b/internal/units/shell/terraform/module/main.go @@ -9,11 +9,11 @@ import ( "github.com/apex/log" "github.com/hashicorp/hcl/v2/hclwrite" - "github.com/shalb/cluster.dev/pkg/config" + "github.com/shalb/cluster.dev/internal/config" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/common" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/hcltools" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/common" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/utils" "github.com/zclconf/go-cty/cty" ) diff --git a/pkg/units/shell/terraform/module/state.go b/internal/units/shell/terraform/module/state.go similarity index 94% rename from pkg/units/shell/terraform/module/state.go rename to internal/units/shell/terraform/module/state.go index ee09cef9..b987d19f 100644 --- a/pkg/units/shell/terraform/module/state.go +++ b/internal/units/shell/terraform/module/state.go @@ -6,8 +6,8 @@ import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/units/shell/terraform/printer/factory.go b/internal/units/shell/terraform/printer/factory.go similarity index 91% rename from pkg/units/shell/terraform/printer/factory.go rename to internal/units/shell/terraform/printer/factory.go index c4d77f6d..965f432d 100644 --- a/pkg/units/shell/terraform/printer/factory.go +++ b/internal/units/shell/terraform/printer/factory.go @@ -2,8 +2,8 @@ package tfmodule import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" ) // Factory factory for s3 backends. diff --git a/pkg/units/shell/terraform/printer/main.go b/internal/units/shell/terraform/printer/main.go similarity index 97% rename from pkg/units/shell/terraform/printer/main.go rename to internal/units/shell/terraform/printer/main.go index 2eb5db87..02723df5 100644 --- a/pkg/units/shell/terraform/printer/main.go +++ b/internal/units/shell/terraform/printer/main.go @@ -6,9 +6,9 @@ import ( "github.com/apex/log" "github.com/hashicorp/hcl/v2/hclwrite" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/hcltools" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" "github.com/zclconf/go-cty/cty" ) diff --git a/pkg/units/shell/terraform/printer/state.go b/internal/units/shell/terraform/printer/state.go similarity index 92% rename from pkg/units/shell/terraform/printer/state.go rename to internal/units/shell/terraform/printer/state.go index 293f7605..43b651e8 100644 --- a/pkg/units/shell/terraform/printer/state.go +++ b/internal/units/shell/terraform/printer/state.go @@ -5,8 +5,8 @@ import ( "github.com/apex/log" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/shalb/cluster.dev/pkg/units/shell/terraform/base" + "github.com/shalb/cluster.dev/internal/project" + "github.com/shalb/cluster.dev/internal/units/shell/terraform/base" "github.com/shalb/cluster.dev/pkg/utils" ) diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index d3155a10..a4a85a95 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -14,7 +14,6 @@ import ( "github.com/apex/log" "github.com/shalb/cluster.dev/pkg/colors" - "github.com/shalb/cluster.dev/pkg/config" "github.com/shalb/cluster.dev/pkg/logging" ) @@ -25,7 +24,7 @@ type ShRunner struct { Timeout time.Duration LogLabels []string ShowResultMessage bool - Interrupted bool + Interrupted *bool } // Env - global list of environment variables. @@ -35,7 +34,7 @@ var Env []string var DefaultLogWriter io.Writer // NewExecutor - create new sh runner. -func NewExecutor(workingDir string, envVariables ...string) (*ShRunner, error) { +func NewExecutor(workingDir string, interruptPointer *bool, envVariables ...string) (*ShRunner, error) { fi, err := os.Stat(workingDir) if workingDir != "" { if os.IsNotExist(err) { @@ -47,7 +46,7 @@ func NewExecutor(workingDir string, envVariables ...string) (*ShRunner, error) { } // Create runner. runner := ShRunner{ - Interrupted: false, + Interrupted: interruptPointer, workingDir: workingDir, Timeout: 0, Env: envVariables, @@ -59,7 +58,7 @@ func NewExecutor(workingDir string, envVariables ...string) (*ShRunner, error) { func (b *ShRunner) commandExecCommon(outputBuff io.Writer, errBuff io.Writer, command string, args ...string) error { // Prepare command, set outputs, run. - if config.Interrupted { + if *b.Interrupted { return fmt.Errorf("interrupted") } var ctx context.Context @@ -85,7 +84,7 @@ func (b *ShRunner) commandExecCommon(outputBuff io.Writer, errBuff io.Writer, co // Run command. stopChan := make(chan struct{}) - sigChan := StartSigTrap(cmd, stopChan) + sigChan := b.StartSigTrap(cmd, stopChan) defer sigChan.Close() cmd.Start() err := cmd.Wait() @@ -98,8 +97,8 @@ func (b *ShRunner) commandExecCommon(outputBuff io.Writer, errBuff io.Writer, co } func (b *ShRunner) commandExecCommonInShell(command string, outputBuff io.Writer, errBuff io.Writer) error { - // Prepere command, set outputs, run. - if config.Interrupted { + // Prepare command, set outputs, run. + if *b.Interrupted { return fmt.Errorf("interrupted") } var ctx context.Context @@ -124,7 +123,7 @@ func (b *ShRunner) commandExecCommonInShell(command string, outputBuff io.Writer cmd.Env = append(envTmp, b.Env...) // Run command. stopChan := make(chan struct{}) - sigChan := StartSigTrap(cmd, stopChan) + sigChan := b.StartSigTrap(cmd, stopChan) defer sigChan.Close() cmd.Start() err := cmd.Wait() @@ -175,7 +174,7 @@ func (b *ShRunner) Run(command string) ([]byte, []byte, error) { errOutput := &bytes.Buffer{} bannerStopChan := make(chan struct{}) - if config.Global.LogLevel != "debug" { + if logging.LogLevel() != "debug" { // banner = fmt.Sprintf("%s[dir='%s'][cmd='%s']", banner, "./"+dir, command) banner := fmt.Sprintf("%s executing in progress...", logPrefix) @@ -238,7 +237,7 @@ func showBanner(banner string, done chan struct{}) { type SigTrap chan os.Signal -func StartSigTrap(cmd *exec.Cmd, stop chan struct{}) SigTrap { +func (b *ShRunner) StartSigTrap(cmd *exec.Cmd, stop chan struct{}) SigTrap { sChan := make(chan os.Signal, 1) signals := []os.Signal{syscall.SIGTERM, syscall.SIGINT} signal.Notify(sChan, signals...) @@ -246,9 +245,8 @@ func StartSigTrap(cmd *exec.Cmd, stop chan struct{}) SigTrap { for { select { case s := <-sChan: - config.Interrupted = true - config.Global.LogLevel = "debug" - logging.InitLogLevel(config.Global.LogLevel, config.Global.TraceLog) + *b.Interrupted = true + logging.InitLogLevel("debug", logging.TraceLog()) // add trace log log.Debugf("executor: forward signal %v", s) err := cmd.Process.Signal(s) if err != nil { diff --git a/pkg/logging/delay_handler.go b/pkg/logging/delay_handler.go index 2a577397..9b6d38a7 100644 --- a/pkg/logging/delay_handler.go +++ b/pkg/logging/delay_handler.go @@ -100,7 +100,7 @@ func (h *DelayHandler) loop() { case <-h.done: ticker.Stop() if !h.afterTimeOut { - fmt.Println("\n\n\n\n") + fmt.Print("\n\n\n\n\n") } return } diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go index 97e3c906..731bb576 100644 --- a/pkg/logging/logging.go +++ b/pkg/logging/logging.go @@ -8,6 +8,17 @@ import ( "github.com/shalb/cluster.dev/pkg/colors" ) +// global log level +var logLevel = "info" + +func LogLevel() string { + return logLevel +} + +func TraceLog() bool { + return traceLog +} + // color function. type colorFunc func(string, ...interface{}) string @@ -30,7 +41,7 @@ var Strings = [...]string{ } // utilStartTime time. -var utilStartTime = time.Now() +// var utilStartTime = time.Now() // loggingInit - initial function for logging subsystem. func init() { @@ -45,6 +56,7 @@ func InitLogLevel(ll string, trace bool) { log.Fatalf("Can't parse logging level '%s': %s", ll, err.Error()) } log.SetLevel(lvl) + logLevel = ll traceLog = trace Colors = []colorFunc{ log.DebugLevel: colors.Fmt(colors.Purple).Sprintf, diff --git a/pkg/utils/convert.go b/pkg/utils/convert.go index 5cf17304..1a2dcab6 100644 --- a/pkg/utils/convert.go +++ b/pkg/utils/convert.go @@ -70,6 +70,7 @@ func JSONDecode(in []byte, out interface{}) error { } func MergeMaps(mOne, mTwo map[string]interface{}) (res map[string]interface{}) { + res = make(map[string]interface{}) for k, v := range mOne { res[k] = v } diff --git a/pkg/utils/files.go b/pkg/utils/files.go index 29118ec3..0cbddc59 100644 --- a/pkg/utils/files.go +++ b/pkg/utils/files.go @@ -15,19 +15,13 @@ import ( // FileExists check if file exists. func FileExists(filename string) bool { _, err := os.Stat(filename) - if os.IsNotExist(err) { - return false - } - return true + return !os.IsNotExist(err) } func IsLocalPath(path string) bool { re := regexp.MustCompile(`^(/|\./|\.\./).*`) outputName := re.FindString(path) - if len(outputName) < 1 { - return false - } - return true + return len(outputName) >= 1 } func IsAbsolutePath(path string) bool { @@ -186,10 +180,10 @@ func Copy(srcFile, dstFile string) error { defer out.Close() in, err := os.Open(srcFile) - defer in.Close() if err != nil { return err } + defer in.Close() _, err = io.Copy(out, in) if err != nil { diff --git a/pkg/utils/git.go b/pkg/utils/git.go index 94c49297..a87b582b 100644 --- a/pkg/utils/git.go +++ b/pkg/utils/git.go @@ -1,15 +1,11 @@ package utils import ( - "context" "fmt" "path/filepath" "strings" - "github.com/Masterminds/semver" "github.com/apex/log" - "github.com/google/go-github/v60/github" - "github.com/shalb/cluster.dev/pkg/config" "github.com/shalb/cluster.dev/pkg/executor" ) @@ -26,25 +22,26 @@ func GetTemplate(gitURL, targetDir, templateName string) (string, error) { if err != nil { return "", fmt.Errorf("get template: %v", err.Error()) } + var interruptMoc = false pulledTemplatePath := filepath.Join(targetDir, templateName) if IsDir(pulledTemplatePath) { log.Debugf("Template is already exists, updating...") - shell, err := executor.NewExecutor(pulledTemplatePath) + shell, err := executor.NewExecutor(pulledTemplatePath, &interruptMoc) if err != nil { return "", fmt.Errorf("get template: %v", err.Error()) } - command := fmt.Sprintf("git pull") + command := "git pull" _, errOutput, err := shell.RunMutely(command) if err != nil { return pulledTemplatePath, fmt.Errorf("get template: %v\n%v", err.Error(), errOutput) } return filepath.Join(pulledTemplatePath, parsedGitURL.SubDir), nil } - shell, err := executor.NewExecutor(targetDir) + shell, err := executor.NewExecutor(targetDir, &interruptMoc) if err != nil { return "", fmt.Errorf("get template: %v", err.Error()) } - command := fmt.Sprintf("git clone --single-branch --depth=1 ") + command := "git clone --single-branch --depth=1 " if parsedGitURL.Version != "" { command = command + "-b " + parsedGitURL.Version + " " } @@ -83,31 +80,3 @@ func ParseGitUrl(gitURL string) (repo GitRepo, err error) { // log.Warnf("ParseGitUrl %+v", repo) return } - -func DiscoverCdevLastRelease() error { - var ( - client = github.NewClient(nil) - ctx = context.Background() - org string = "shalb" - project string = "cluster.dev" - ) - - latestRelease, _, err := client.Repositories.GetLatestRelease(ctx, org, project) - if err != nil { - return err - } - config.Version = "v0.9.0" - curVersion, err := semver.NewVersion(config.Version) - if err != nil { - return fmt.Errorf("check failed: %v, current version: %v", err, config.Global.Version) - } - reqVerConstraints, err := semver.NewConstraint(*latestRelease.TagName) - if err != nil { - return fmt.Errorf("check failed: %v, latest stable release: %v", err, *latestRelease.TagName) - } - ok, _ := reqVerConstraints.Validate(curVersion) - if !ok { - return fmt.Errorf("the new cdev version is available. Current version: '%v', latest stable release: '%v'. Visit https://docs.cluster.dev/installation-upgrade/ to upgrade", curVersion, *latestRelease.TagName) - } - return nil -} diff --git a/pkg/utils/strings.go b/pkg/utils/strings.go index 56d44a4c..8f5a802c 100644 --- a/pkg/utils/strings.go +++ b/pkg/utils/strings.go @@ -36,7 +36,7 @@ func RandString(n int) string { // URLToFolderName convert URL to string which can be used as a directory name. func URLToFolderName(URL string) (string, error) { - reg, err := regexp.Compile("[^A-Za-z0-9_\\-=\\?\\.]+") + reg, err := regexp.Compile(`[^A-Za-z0-9_\-=\?\.]+`) if err != nil { return "", err }