diff --git a/cmd/helm-migrate-values/main.go b/cmd/helm-migrate-values/main.go index 0c7b6be..828383a 100644 --- a/cmd/helm-migrate-values/main.go +++ b/cmd/helm-migrate-values/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "github.com/octopusdeploylabs/helm-migrate-values/internal" + "github.com/octopusdeploylabs/helm-migrate-values/pkg" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/cli" "log" @@ -18,7 +18,7 @@ func init() { func main() { var actionConfig = new(action.Configuration) - logger := *internal.NewLogger(settings.Debug) + logger := *pkg.NewLogger(settings.Debug) logger.Debug("Debug mode enabled") cmd, err := NewRootCmd(actionConfig, settings, os.Stdout, logger) diff --git a/cmd/helm-migrate-values/root.go b/cmd/helm-migrate-values/root.go index f673d5f..9fda741 100644 --- a/cmd/helm-migrate-values/root.go +++ b/cmd/helm-migrate-values/root.go @@ -47,7 +47,7 @@ The command will return an error if: - no migrations are defined in the chart ` -func NewRootCmd(actionConfig *action.Configuration, settings *cli.EnvSettings, out io.Writer, log internal.Logger) (*cobra.Command, error) { +func NewRootCmd(actionConfig *action.Configuration, settings *cli.EnvSettings, out io.Writer, log pkg.Logger) (*cobra.Command, error) { cmd := &cobra.Command{ Use: "migrate-values [RELEASE] [CHART] [flags]", Short: "helm migrator for values schemas", @@ -67,7 +67,7 @@ func NewRootCmd(actionConfig *action.Configuration, settings *cli.EnvSettings, o return cmd, nil } -func newRunner(actionConfig *action.Configuration, flags *pflag.FlagSet, settings *cli.EnvSettings, out io.Writer, outputFile *string, log internal.Logger) func(cmd *cobra.Command, args []string) error { +func newRunner(actionConfig *action.Configuration, flags *pflag.FlagSet, settings *cli.EnvSettings, out io.Writer, outputFile *string, log pkg.Logger) func(cmd *cobra.Command, args []string) error { // We use the install action for locating the chart var installAction = action.NewInstall(actionConfig) var listAction = action.NewList(actionConfig) diff --git a/internal/chart_pull.go b/internal/chart_pull.go index 11c77fc..4a8f404 100644 --- a/internal/chart_pull.go +++ b/internal/chart_pull.go @@ -1,6 +1,7 @@ package internal import ( + "github.com/octopusdeploylabs/helm-migrate-values/pkg" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/cli" @@ -9,7 +10,7 @@ import ( ) // Locates the chart. If this is a remote (OCI/Repo URL) it downloads the chart and extract the tgz to a temporary file -func LocateChart(chart string, client *action.Install, settings *cli.EnvSettings, log Logger) (*string, bool, error) { +func LocateChart(chart string, client *action.Install, settings *cli.EnvSettings, log pkg.Logger) (*string, bool, error) { err := setupRegistryClient(client, settings) if err != nil { return nil, false, err diff --git a/pkg/integration_test.go b/pkg/integration_test.go index 465ea24..9195e66 100644 --- a/pkg/integration_test.go +++ b/pkg/integration_test.go @@ -1,7 +1,6 @@ package pkg import ( - "github.com/octopusdeploylabs/helm-migrate-values/internal" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "helm.sh/helm/v3/pkg/action" @@ -71,7 +70,7 @@ func migrateCharts(t *testing.T, chartV1Path, chartV2Path string) { req.NoError(err, "Error installing chart v1") // Migrate the release user values (config) - migratedValues, err := MigrateFromPath(rel1.Config, 1, nil, "test-charts/v2/value-migrations/", *internal.NewLogger(false)) + migratedValues, err := MigrateFromPath(rel1.Config, 1, nil, "test-charts/v2/value-migrations/", *NewLogger(false)) req.NoError(err, "Error migrating values") // Load the v2 chart diff --git a/internal/logging.go b/pkg/logging.go similarity index 96% rename from internal/logging.go rename to pkg/logging.go index 2133b60..88a0cd7 100644 --- a/internal/logging.go +++ b/pkg/logging.go @@ -1,4 +1,4 @@ -package internal +package pkg import ( "fmt" diff --git a/pkg/migrator.go b/pkg/migrator.go index 52043aa..f8ead3a 100644 --- a/pkg/migrator.go +++ b/pkg/migrator.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "github.com/Masterminds/sprig/v3" - "github.com/octopusdeploylabs/helm-migrate-values/internal" "gopkg.in/yaml.v2" "os" "slices" @@ -12,7 +11,7 @@ import ( "text/template" ) -func MigrateFromPath(currentConfig map[string]interface{}, vFrom int, vTo *int, migrationsDir string, log internal.Logger) (map[string]interface{}, error) { +func MigrateFromPath(currentConfig map[string]interface{}, vFrom int, vTo *int, migrationsDir string, log Logger) (map[string]interface{}, error) { if len(currentConfig) == 0 { log.Warning("No existing user-supplied values to migrate") @@ -48,7 +47,7 @@ func MigrateFromPath(currentConfig map[string]interface{}, vFrom int, vTo *int, return Migrate(currentConfig, vFrom, vTo, mp, log) } -func Migrate(currentConfig map[string]interface{}, vFrom int, vTo *int, mp MigrationProvider, log internal.Logger) (map[string]interface{}, error) { +func Migrate(currentConfig map[string]interface{}, vFrom int, vTo *int, mp MigrationProvider, log Logger) (map[string]interface{}, error) { log.Debug("migrating user-supplied values") versions := slices.Sorted(mp.GetVersions()) diff --git a/pkg/migrator_test.go b/pkg/migrator_test.go index 7381124..c4f2ea1 100644 --- a/pkg/migrator_test.go +++ b/pkg/migrator_test.go @@ -1,7 +1,6 @@ package pkg import ( - "github.com/octopusdeploylabs/helm-migrate-values/internal" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "testing" @@ -77,7 +76,7 @@ func TestMigrator_MigrateAcrossVersions(t *testing.T) { ms := loadMigrationsToVersions(tc.includeMigrationsToVersions) - migrated, err := Migrate(currentConfig, tc.currentVersion, tc.versionTo, ms, *internal.NewLogger(false)) + migrated, err := Migrate(currentConfig, tc.currentVersion, tc.versionTo, ms, *NewLogger(false)) req.NoError(err) is.EqualValues(tc.expected, migrated)