From e209887caa4587a00c7a1ef170737fef5ab4f518 Mon Sep 17 00:00:00 2001 From: Alessio Pragliola <83355398+Al-Pragliola@users.noreply.github.com> Date: Thu, 18 Jul 2024 18:04:38 +0200 Subject: [PATCH] feat: move to pkg (#522) * feat: move distribution download to pkg * feat: move dependencies download/validation to pkg * feat: move x net hashicorp to pkg * fix: move missing files to pkg x net * fix: tests * feat: move templates to pkg * feat: move x yaml to pkg * feat: move merge to pkg * feat: move x map to pkg * feat: mode diffs package to external pkg * fix: missing files * feat: move rules extractors to pkg * chore: move rules and reducers to pkg * chore: rename reducers package name * fix: linting * chore: refactor reducers builder function * fix: reducers null in array * fix: wrong import --- cmd/apply.go | 12 +-- cmd/connect/openvpn.go | 2 +- cmd/create/config.go | 12 +-- cmd/delete/cluster.go | 12 +-- cmd/diff.go | 12 +-- cmd/download/dependencies.go | 12 +-- cmd/dump/template.go | 15 ++-- cmd/get/kubeconfig.go | 12 +-- cmd/validate/config.go | 12 +-- cmd/validate/dependencies.go | 12 +-- .../kfd/v1alpha2/common/create/plugins.go | 4 +- .../kfd/v1alpha2/common/create/preupgrade.go | 10 +-- .../ekscluster/common/distribution.go | 6 +- .../ekscluster/common/infrastructure.go | 2 +- .../v1alpha2/ekscluster/common/kubernetes.go | 6 +- .../v1alpha2/ekscluster/common/preflight.go | 4 +- .../ekscluster/create/distribution.go | 24 +++--- .../v1alpha2/ekscluster/create/preflight.go | 6 +- .../apis/kfd/v1alpha2/ekscluster/creator.go | 81 +++++-------------- .../apis/kfd/v1alpha2/ekscluster/schema.go | 2 +- internal/apis/kfd/v1alpha2/ekscluster/tool.go | 2 +- .../kfddistribution/create/distribution.go | 20 ++--- .../kfddistribution/create/preflight.go | 6 +- .../kfd/v1alpha2/kfddistribution/creator.go | 71 ++++------------ .../kfddistribution/delete/distribution.go | 4 +- .../onpremises/create/distribution.go | 20 ++--- .../v1alpha2/onpremises/create/kubernetes.go | 2 +- .../v1alpha2/onpremises/create/preflight.go | 8 +- .../apis/kfd/v1alpha2/onpremises/creator.go | 73 ++++------------- .../onpremises/delete/distribution.go | 4 +- .../v1alpha2/onpremises/delete/kubernetes.go | 2 +- .../v1alpha2/onpremises/delete/preflight.go | 2 +- .../v1alpha2/onpremises/kubeconfig_getter.go | 2 +- internal/cluster/creator.go | 2 +- internal/cluster/deleter.go | 2 +- internal/cluster/kubeconfig_getter.go | 2 +- internal/cluster/phase.go | 6 +- internal/config/validate.go | 7 +- internal/distribution/iac.go | 6 +- internal/legacy/furyfile.go | 2 +- internal/state/store.go | 2 +- internal/tool/furyagent/config.go | 2 +- internal/upgrade/store.go | 2 +- internal/x/kube/configmap.go | 2 +- internal/x/kube/configmap_test.go | 2 +- internal/x/kube/secret.go | 2 +- internal/x/kube/secret_test.go | 2 +- {internal => pkg}/dependencies/download.go | 13 +-- {internal => pkg}/dependencies/validate.go | 4 +- {internal => pkg}/diffs/checker.go | 2 +- {internal => pkg}/diffs/checker_test.go | 2 +- {internal => pkg}/distribution/download.go | 7 +- .../distribution/download_test.go | 6 +- {internal => pkg}/merge/merge.go | 0 {internal => pkg}/merge/merge_test.go | 2 +- {internal => pkg}/merge/model.go | 2 +- {internal => pkg}/merge/model_test.go | 2 +- pkg/reducers/builder.go | 46 +++++++++++ .../kfd/v1alpha2 => pkg/reducers}/reducer.go | 2 +- .../rulesextractor/ekscluster.go | 45 +++++------ .../rulesextractor/ekscluster_test.go | 6 +- .../rules => pkg/rulesextractor}/extractor.go | 2 +- .../rulesextractor}/extractor_test.go | 4 +- .../rulesextractor/kfddistribution.go | 28 +++---- .../rulesextractor/kfddistribution_test.go | 10 +-- .../rulesextractor/onpremises.go | 37 ++++----- .../rulesextractor/onpremises_test.go | 8 +- {internal => pkg}/template/config.go | 4 +- {internal => pkg}/template/config_test.go | 4 +- {internal => pkg}/template/funcmap.go | 0 {internal => pkg}/template/funcmap_test.go | 2 +- {internal => pkg}/template/generator.go | 0 {internal => pkg}/template/generator_test.go | 2 +- {internal => pkg}/template/mapper/mapper.go | 0 .../template/mapper/mapper_test.go | 2 +- {internal => pkg}/template/model.go | 4 +- {internal => pkg}/template/model_test.go | 2 +- {internal => pkg}/template/node.go | 0 {internal => pkg}/template/node_test.go | 2 +- {internal => pkg}/x/map/build.go | 0 {internal => pkg}/x/map/build_test.go | 2 +- {internal => pkg}/x/net/client.go | 0 {internal => pkg}/x/net/client_test.go | 2 +- {internal => pkg}/x/net/hashicorp.go | 0 {internal => pkg}/x/net/hashicorp_test.go | 2 +- {internal => pkg}/x/yaml/yaml.go | 0 {internal => pkg}/x/yaml/yaml_test.go | 2 +- test/expensive/onpremises/furyctl_test.go | 2 +- test/utils/testutils.go | 16 ++-- 89 files changed, 361 insertions(+), 430 deletions(-) rename {internal => pkg}/dependencies/download.go (94%) rename {internal => pkg}/dependencies/validate.go (91%) rename {internal => pkg}/diffs/checker.go (98%) rename {internal => pkg}/diffs/checker_test.go (98%) rename {internal => pkg}/distribution/download.go (96%) rename {internal => pkg}/distribution/download_test.go (91%) rename {internal => pkg}/merge/merge.go (100%) rename {internal => pkg}/merge/merge_test.go (97%) rename {internal => pkg}/merge/model.go (97%) rename {internal => pkg}/merge/model_test.go (98%) create mode 100644 pkg/reducers/builder.go rename {internal/apis/kfd/v1alpha2 => pkg/reducers}/reducer.go (99%) rename internal/apis/kfd/v1alpha2/ekscluster/rules/extractor.go => pkg/rulesextractor/ekscluster.go (63%) rename internal/apis/kfd/v1alpha2/ekscluster/rules/extractor_test.go => pkg/rulesextractor/ekscluster_test.go (93%) rename {internal/rules => pkg/rulesextractor}/extractor.go (99%) rename {internal/rules => pkg/rulesextractor}/extractor_test.go (99%) rename internal/apis/kfd/v1alpha2/kfddistribution/rules/extractor.go => pkg/rulesextractor/kfddistribution.go (65%) rename internal/apis/kfd/v1alpha2/kfddistribution/rules/extractor_test.go => pkg/rulesextractor/kfddistribution_test.go (80%) rename internal/apis/kfd/v1alpha2/onpremises/rules/extractor.go => pkg/rulesextractor/onpremises.go (63%) rename internal/apis/kfd/v1alpha2/onpremises/rules/extractor_test.go => pkg/rulesextractor/onpremises_test.go (88%) rename {internal => pkg}/template/config.go (97%) rename {internal => pkg}/template/config_test.go (97%) rename {internal => pkg}/template/funcmap.go (100%) rename {internal => pkg}/template/funcmap_test.go (97%) rename {internal => pkg}/template/generator.go (100%) rename {internal => pkg}/template/generator_test.go (98%) rename {internal => pkg}/template/mapper/mapper.go (100%) rename {internal => pkg}/template/mapper/mapper_test.go (99%) rename {internal => pkg}/template/model.go (97%) rename {internal => pkg}/template/model_test.go (95%) rename {internal => pkg}/template/node.go (100%) rename {internal => pkg}/template/node_test.go (99%) rename {internal => pkg}/x/map/build.go (100%) rename {internal => pkg}/x/map/build_test.go (97%) rename {internal => pkg}/x/net/client.go (100%) rename {internal => pkg}/x/net/client_test.go (99%) rename {internal => pkg}/x/net/hashicorp.go (100%) rename {internal => pkg}/x/net/hashicorp_test.go (96%) rename {internal => pkg}/x/yaml/yaml.go (100%) rename {internal => pkg}/x/yaml/yaml_test.go (96%) diff --git a/cmd/apply.go b/cmd/apply.go index 355cc1760..7da3a7eca 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -19,12 +19,12 @@ import ( "github.com/sighupio/furyctl/internal/app" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/config" - "github.com/sighupio/furyctl/internal/dependencies" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" - netx "github.com/sighupio/furyctl/internal/x/net" + "github.com/sighupio/furyctl/pkg/dependencies" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" ) const WrappedErrMessage = "%w: %s" @@ -126,7 +126,7 @@ func NewApplyCmd() *cobra.Command { } } - var distrodl *distribution.Downloader + var distrodl *dist.Downloader // Init first half of collaborators. client := netx.NewGoGetterClient() @@ -134,9 +134,9 @@ func NewApplyCmd() *cobra.Command { depsvl := dependencies.NewValidator(executor, flags.BinPath, flags.FuryctlPath, flags.VpnAutoConnect) if flags.DistroLocation == "" { - distrodl = distribution.NewCachingDownloader(client, outDir, flags.GitProtocol, absDistroPatchesLocation) + distrodl = dist.NewCachingDownloader(client, outDir, flags.GitProtocol, absDistroPatchesLocation) } else { - distrodl = distribution.NewDownloader(client, flags.GitProtocol, absDistroPatchesLocation) + distrodl = dist.NewDownloader(client, flags.GitProtocol, absDistroPatchesLocation) } // Init packages. diff --git a/cmd/connect/openvpn.go b/cmd/connect/openvpn.go index d17de14d7..47f6ba6bd 100644 --- a/cmd/connect/openvpn.go +++ b/cmd/connect/openvpn.go @@ -19,7 +19,7 @@ import ( "github.com/sighupio/furyctl/internal/app" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type OpenVPNCmdFlags struct { diff --git a/cmd/create/config.go b/cmd/create/config.go index f31d22268..301fd74e5 100644 --- a/cmd/create/config.go +++ b/cmd/create/config.go @@ -18,13 +18,13 @@ import ( "github.com/sighupio/furyctl/internal/analytics" "github.com/sighupio/furyctl/internal/app" "github.com/sighupio/furyctl/internal/config" - "github.com/sighupio/furyctl/internal/dependencies" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" "github.com/sighupio/furyctl/internal/semver" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" - netx "github.com/sighupio/furyctl/internal/x/net" + "github.com/sighupio/furyctl/pkg/dependencies" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" ) var ( @@ -115,7 +115,7 @@ func NewConfigCmd() *cobra.Command { } } - var distrodl *distribution.Downloader + var distrodl *dist.Downloader // Init collaborators. client := netx.NewGoGetterClient() @@ -123,9 +123,9 @@ func NewConfigCmd() *cobra.Command { depsvl := dependencies.NewValidator(executor, "", "", false) if distroLocation == "" { - distrodl = distribution.NewCachingDownloader(client, outDir, typedGitProtocol, absDistroPatchesLocation) + distrodl = dist.NewCachingDownloader(client, outDir, typedGitProtocol, absDistroPatchesLocation) } else { - distrodl = distribution.NewDownloader(client, typedGitProtocol, absDistroPatchesLocation) + distrodl = dist.NewDownloader(client, typedGitProtocol, absDistroPatchesLocation) } // Init packages. diff --git a/cmd/delete/cluster.go b/cmd/delete/cluster.go index 997fcbaeb..1f943098c 100644 --- a/cmd/delete/cluster.go +++ b/cmd/delete/cluster.go @@ -19,13 +19,13 @@ import ( "github.com/sighupio/furyctl/internal/app" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/config" - "github.com/sighupio/furyctl/internal/dependencies" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" - netx "github.com/sighupio/furyctl/internal/x/net" + "github.com/sighupio/furyctl/pkg/dependencies" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" ) const WrappedErrMessage = "%w: %s" @@ -116,7 +116,7 @@ func NewClusterCmd() *cobra.Command { } } - var distrodl *distribution.Downloader + var distrodl *dist.Downloader // Init first half of collaborators. client := netx.NewGoGetterClient() @@ -124,9 +124,9 @@ func NewClusterCmd() *cobra.Command { depsvl := dependencies.NewValidator(executor, flags.BinPath, flags.FuryctlPath, flags.VpnAutoConnect) if flags.DistroLocation == "" { - distrodl = distribution.NewCachingDownloader(client, outDir, flags.GitProtocol, absDistroPatchesLocation) + distrodl = dist.NewCachingDownloader(client, outDir, flags.GitProtocol, absDistroPatchesLocation) } else { - distrodl = distribution.NewDownloader(client, flags.GitProtocol, absDistroPatchesLocation) + distrodl = dist.NewDownloader(client, flags.GitProtocol, absDistroPatchesLocation) } execx.NoTTY = flags.NoTTY diff --git a/cmd/diff.go b/cmd/diff.go index 363b7e3b0..a056da374 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -18,14 +18,14 @@ import ( "github.com/sighupio/furyctl/internal/analytics" "github.com/sighupio/furyctl/internal/app" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/diffs" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" "github.com/sighupio/furyctl/internal/state" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" - netx "github.com/sighupio/furyctl/internal/x/net" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/diffs" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type DiffCommandFlags struct { @@ -100,10 +100,10 @@ func NewDiffCmd() *cobra.Command { client := netx.NewGoGetterClient() - distrodl := distribution.NewDownloader(client, flags.GitProtocol, absDistroPatchesLocation) + distrodl := dist.NewDownloader(client, flags.GitProtocol, absDistroPatchesLocation) if flags.DistroLocation == "" { - distrodl = distribution.NewCachingDownloader(client, outDir, flags.GitProtocol, absDistroPatchesLocation) + distrodl = dist.NewCachingDownloader(client, outDir, flags.GitProtocol, absDistroPatchesLocation) } logrus.Info("Downloading distribution...") diff --git a/cmd/download/dependencies.go b/cmd/download/dependencies.go index d2c27d847..4ce842697 100644 --- a/cmd/download/dependencies.go +++ b/cmd/download/dependencies.go @@ -16,12 +16,12 @@ import ( "github.com/sighupio/furyctl/internal/analytics" "github.com/sighupio/furyctl/internal/app" - "github.com/sighupio/furyctl/internal/dependencies" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" - netx "github.com/sighupio/furyctl/internal/x/net" + "github.com/sighupio/furyctl/pkg/dependencies" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" ) var ( @@ -91,16 +91,16 @@ func NewDependenciesCmd() *cobra.Command { } } - var distrodl *distribution.Downloader + var distrodl *dist.Downloader client := netx.NewGoGetterClient() executor := execx.NewStdExecutor() depsvl := dependencies.NewValidator(executor, binPath, furyctlPath, false) if distroLocation == "" { - distrodl = distribution.NewCachingDownloader(client, outDir, typedGitProtocol, absDistroPatchesLocation) + distrodl = dist.NewCachingDownloader(client, outDir, typedGitProtocol, absDistroPatchesLocation) } else { - distrodl = distribution.NewDownloader(client, typedGitProtocol, absDistroPatchesLocation) + distrodl = dist.NewDownloader(client, typedGitProtocol, absDistroPatchesLocation) } // Validate base requirements. diff --git a/cmd/dump/template.go b/cmd/dump/template.go index 2e061bca4..f177ea38d 100644 --- a/cmd/dump/template.go +++ b/cmd/dump/template.go @@ -17,14 +17,15 @@ import ( "github.com/sighupio/furyctl/internal/analytics" "github.com/sighupio/furyctl/internal/app" "github.com/sighupio/furyctl/internal/config" - "github.com/sighupio/furyctl/internal/dependencies" "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" - "github.com/sighupio/furyctl/internal/template" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" - netx "github.com/sighupio/furyctl/internal/x/net" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/dependencies" + dist "github.com/sighupio/furyctl/pkg/distribution" + "github.com/sighupio/furyctl/pkg/template" + netx "github.com/sighupio/furyctl/pkg/x/net" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type TemplateCmdFlags struct { @@ -108,16 +109,16 @@ The generated folder will be created starting from a provided templates folder a } } - var distrodl *distribution.Downloader + var distrodl *dist.Downloader client := netx.NewGoGetterClient() executor := execx.NewStdExecutor() depsvl := dependencies.NewValidator(executor, "", absFuryctlPath, false) if flags.DistroLocation == "" { - distrodl = distribution.NewCachingDownloader(client, outDir, flags.GitProtocol, absDistroPatchesLocation) + distrodl = dist.NewCachingDownloader(client, outDir, flags.GitProtocol, absDistroPatchesLocation) } else { - distrodl = distribution.NewDownloader(client, flags.GitProtocol, absDistroPatchesLocation) + distrodl = dist.NewDownloader(client, flags.GitProtocol, absDistroPatchesLocation) } if err := depsvl.ValidateBaseReqs(); err != nil { diff --git a/cmd/get/kubeconfig.go b/cmd/get/kubeconfig.go index e17efac1f..3c25711d1 100644 --- a/cmd/get/kubeconfig.go +++ b/cmd/get/kubeconfig.go @@ -18,12 +18,12 @@ import ( "github.com/sighupio/furyctl/internal/app" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/config" - "github.com/sighupio/furyctl/internal/dependencies" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" - netx "github.com/sighupio/furyctl/internal/x/net" + "github.com/sighupio/furyctl/pkg/dependencies" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" ) var ( @@ -96,16 +96,16 @@ func NewKubeconfigCmd() *cobra.Command { executor := execx.NewStdExecutor() - distrodl := &distribution.Downloader{} + distrodl := &dist.Downloader{} depsvl := dependencies.NewValidator(executor, binPath, furyctlPath, false) // Init first half of collaborators. client := netx.NewGoGetterClient() if distroLocation == "" { - distrodl = distribution.NewCachingDownloader(client, outDir, parsedGitProtocol, "") + distrodl = dist.NewCachingDownloader(client, outDir, parsedGitProtocol, "") } else { - distrodl = distribution.NewDownloader(client, parsedGitProtocol, "") + distrodl = dist.NewDownloader(client, parsedGitProtocol, "") } // Validate base requirements. diff --git a/cmd/validate/config.go b/cmd/validate/config.go index 20fb7c3fc..da7c8982f 100644 --- a/cmd/validate/config.go +++ b/cmd/validate/config.go @@ -17,12 +17,12 @@ import ( "github.com/sighupio/furyctl/internal/analytics" "github.com/sighupio/furyctl/internal/app" "github.com/sighupio/furyctl/internal/config" - "github.com/sighupio/furyctl/internal/dependencies" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" - netx "github.com/sighupio/furyctl/internal/x/net" + "github.com/sighupio/furyctl/pkg/dependencies" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" ) var ( @@ -84,16 +84,16 @@ func NewConfigCmd() *cobra.Command { } } - var distrodl *distribution.Downloader + var distrodl *dist.Downloader client := netx.NewGoGetterClient() executor := execx.NewStdExecutor() depsvl := dependencies.NewValidator(executor, "", furyctlPath, false) if distroLocation == "" { - distrodl = distribution.NewCachingDownloader(client, outDir, typedGitProtocol, absDistroPatchesLocation) + distrodl = dist.NewCachingDownloader(client, outDir, typedGitProtocol, absDistroPatchesLocation) } else { - distrodl = distribution.NewDownloader(client, typedGitProtocol, absDistroPatchesLocation) + distrodl = dist.NewDownloader(client, typedGitProtocol, absDistroPatchesLocation) } // Validate base requirements. diff --git a/cmd/validate/dependencies.go b/cmd/validate/dependencies.go index 2beae75dd..d437e759d 100644 --- a/cmd/validate/dependencies.go +++ b/cmd/validate/dependencies.go @@ -16,14 +16,14 @@ import ( "github.com/sighupio/furyctl/internal/analytics" "github.com/sighupio/furyctl/internal/app" - "github.com/sighupio/furyctl/internal/dependencies" "github.com/sighupio/furyctl/internal/dependencies/envvars" "github.com/sighupio/furyctl/internal/dependencies/tools" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" cobrax "github.com/sighupio/furyctl/internal/x/cobra" execx "github.com/sighupio/furyctl/internal/x/exec" - netx "github.com/sighupio/furyctl/internal/x/net" + "github.com/sighupio/furyctl/pkg/dependencies" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" ) var ErrDependencies = errors.New("dependencies are not satisfied") @@ -87,16 +87,16 @@ func NewDependenciesCmd() *cobra.Command { } } - var distrodl *distribution.Downloader + var distrodl *dist.Downloader client := netx.NewGoGetterClient() executor := execx.NewStdExecutor() depsvl := dependencies.NewValidator(executor, "", furyctlPath, false) if distroLocation == "" { - distrodl = distribution.NewCachingDownloader(client, outDir, typedGitProtocol, absDistroPatchesLocation) + distrodl = dist.NewCachingDownloader(client, outDir, typedGitProtocol, absDistroPatchesLocation) } else { - distrodl = distribution.NewDownloader(client, typedGitProtocol, absDistroPatchesLocation) + distrodl = dist.NewDownloader(client, typedGitProtocol, absDistroPatchesLocation) } // Validate base requirements. diff --git a/internal/apis/kfd/v1alpha2/common/create/plugins.go b/internal/apis/kfd/v1alpha2/common/create/plugins.go index c0060125d..d44ac8b80 100644 --- a/internal/apis/kfd/v1alpha2/common/create/plugins.go +++ b/internal/apis/kfd/v1alpha2/common/create/plugins.go @@ -16,12 +16,12 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/distribution" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/helmfile" "github.com/sighupio/furyctl/internal/tool/shell" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type Plugins struct { diff --git a/internal/apis/kfd/v1alpha2/common/create/preupgrade.go b/internal/apis/kfd/v1alpha2/common/create/preupgrade.go index e7620c0bd..d357a989e 100644 --- a/internal/apis/kfd/v1alpha2/common/create/preupgrade.go +++ b/internal/apis/kfd/v1alpha2/common/create/preupgrade.go @@ -19,13 +19,13 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/furyctl/configs" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/semver" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/upgrade" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/reducers" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ( @@ -42,7 +42,7 @@ type PreUpgrade struct { kind string upgrade *upgrade.Upgrade upgradeFlag bool - reducers v1alpha2.Reducers + reducers reducers.Reducers diffs diff.Changelog forceFlag []string paths cluster.CreatorPaths @@ -59,7 +59,7 @@ func NewPreUpgrade( upgradeFlag bool, forceFlag []string, upgr *upgrade.Upgrade, - reducers v1alpha2.Reducers, + reducers reducers.Reducers, diffs diff.Changelog, externalUpgradesPath string, skipNodesUpgrade bool, diff --git a/internal/apis/kfd/v1alpha2/ekscluster/common/distribution.go b/internal/apis/kfd/v1alpha2/ekscluster/common/distribution.go index 44207dfcb..6c456bae9 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/common/distribution.go +++ b/internal/apis/kfd/v1alpha2/ekscluster/common/distribution.go @@ -15,11 +15,11 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/ekscluster/v1alpha2/private" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/merge" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/terraform" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/merge" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ( diff --git a/internal/apis/kfd/v1alpha2/ekscluster/common/infrastructure.go b/internal/apis/kfd/v1alpha2/ekscluster/common/infrastructure.go index 94384c096..8c5aff4d4 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/common/infrastructure.go +++ b/internal/apis/kfd/v1alpha2/ekscluster/common/infrastructure.go @@ -10,7 +10,7 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/ekscluster/v1alpha2/private" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/template" + "github.com/sighupio/furyctl/pkg/template" ) type Infrastructure struct { diff --git a/internal/apis/kfd/v1alpha2/ekscluster/common/kubernetes.go b/internal/apis/kfd/v1alpha2/ekscluster/common/kubernetes.go index 08b7739a4..ab685eb02 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/common/kubernetes.go +++ b/internal/apis/kfd/v1alpha2/ekscluster/common/kubernetes.go @@ -14,10 +14,10 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/ekscluster/v1alpha2/private" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/distribution" - "github.com/sighupio/furyctl/internal/merge" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/terraform" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/merge" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type Kubernetes struct { diff --git a/internal/apis/kfd/v1alpha2/ekscluster/common/preflight.go b/internal/apis/kfd/v1alpha2/ekscluster/common/preflight.go index 69bee1dbe..f7c5fcc91 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/common/preflight.go +++ b/internal/apis/kfd/v1alpha2/ekscluster/common/preflight.go @@ -20,12 +20,12 @@ import ( "github.com/sighupio/furyctl/configs" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/vpn" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/awscli" "github.com/sighupio/furyctl/internal/tool/furyagent" "github.com/sighupio/furyctl/internal/tool/terraform" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const vpnDefaultPort = 1194 diff --git a/internal/apis/kfd/v1alpha2/ekscluster/create/distribution.go b/internal/apis/kfd/v1alpha2/ekscluster/create/distribution.go index cb88e74f0..de28d3f3e 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/create/distribution.go +++ b/internal/apis/kfd/v1alpha2/ekscluster/create/distribution.go @@ -17,18 +17,18 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/ekscluster/v1alpha2/private" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/common" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/merge" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/kubectl" "github.com/sighupio/furyctl/internal/tool/shell" "github.com/sighupio/furyctl/internal/tool/terraform" "github.com/sighupio/furyctl/internal/upgrade" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" + "github.com/sighupio/furyctl/pkg/merge" + "github.com/sighupio/furyctl/pkg/reducers" + "github.com/sighupio/furyctl/pkg/template" ) const ( @@ -132,7 +132,7 @@ func (*Distribution) SupportsLifecycle(lifecycle string) bool { } func (d *Distribution) Exec( - reducers v1alpha2.Reducers, + rdcs reducers.Reducers, startFrom string, upgradeState *upgrade.State, ) error { @@ -158,7 +158,7 @@ func (d *Distribution) Exec( } if err := d.coreDistribution( - reducers, + rdcs, tfCfg, startFrom, upgradeState, @@ -206,7 +206,7 @@ func (d *Distribution) preDistribution( } func (d *Distribution) coreDistribution( - reducers v1alpha2.Reducers, + rdcs reducers.Reducers, tfCfg *template.Config, startFrom string, upgradeState *upgrade.State, @@ -215,7 +215,7 @@ func (d *Distribution) coreDistribution( timestamp int64, ) error { if startFrom != cluster.OperationSubPhasePostDistribution { - if err := d.runReducers(reducers, tfCfg, LifecyclePreTf, []string{"manifests", ".gitignore"}); err != nil { + if err := d.runReducers(rdcs, tfCfg, LifecyclePreTf, []string{"manifests", ".gitignore"}); err != nil { return fmt.Errorf("error running pre-tf reducers: %w", err) } @@ -275,7 +275,7 @@ func (d *Distribution) coreDistribution( return fmt.Errorf("error preparing distribution phase (post terraform): %w", err) } - if err := d.runReducers(reducers, mCfg, LifecyclePostTf, []string{"manifests", ".gitignore"}); err != nil { + if err := d.runReducers(rdcs, mCfg, LifecyclePostTf, []string{"manifests", ".gitignore"}); err != nil { return fmt.Errorf("error running post-tf reducers: %w", err) } @@ -285,7 +285,7 @@ func (d *Distribution) coreDistribution( return fmt.Errorf("error checking cluster reachability: %w", err) } - if err := d.runReducers(reducers, mCfg, LifecyclePreApply, []string{"manifests", ".gitignore"}); err != nil { + if err := d.runReducers(rdcs, mCfg, LifecyclePreApply, []string{"manifests", ".gitignore"}); err != nil { return fmt.Errorf("error running pre-apply reducers: %w", err) } @@ -303,7 +303,7 @@ func (d *Distribution) coreDistribution( upgradeState.Phases.Distribution.Status = upgrade.PhaseStatusSuccess } - if err := d.runReducers(reducers, mCfg, LifecyclePostApply, []string{"manifests", ".gitignore"}); err != nil { + if err := d.runReducers(rdcs, mCfg, LifecyclePostApply, []string{"manifests", ".gitignore"}); err != nil { return fmt.Errorf("error running post-apply reducers: %w", err) } } @@ -345,12 +345,12 @@ func (d *Distribution) checkKubeVersion() error { } func (d *Distribution) runReducers( - reducers v1alpha2.Reducers, + rdcs reducers.Reducers, cfg *template.Config, lifecycle string, excludes []string, ) error { - r := reducers.ByLifecycle(lifecycle) + r := rdcs.ByLifecycle(lifecycle) if len(r) > 0 { preTfReducersCfg := cfg diff --git a/internal/apis/kfd/v1alpha2/ekscluster/create/preflight.go b/internal/apis/kfd/v1alpha2/ekscluster/create/preflight.go index 79be8e531..aa31326ba 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/create/preflight.go +++ b/internal/apis/kfd/v1alpha2/ekscluster/create/preflight.go @@ -15,18 +15,18 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/ekscluster/v1alpha2/private" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/common" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/rules" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/supported" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/vpn" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/diffs" "github.com/sighupio/furyctl/internal/state" "github.com/sighupio/furyctl/internal/tool/awscli" "github.com/sighupio/furyctl/internal/tool/kubectl" "github.com/sighupio/furyctl/internal/tool/terraform" execx "github.com/sighupio/furyctl/internal/x/exec" kubex "github.com/sighupio/furyctl/internal/x/kube" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/diffs" + rules "github.com/sighupio/furyctl/pkg/rulesextractor" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ( diff --git a/internal/apis/kfd/v1alpha2/ekscluster/creator.go b/internal/apis/kfd/v1alpha2/ekscluster/creator.go index c5d7780b3..ea693b8ef 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/creator.go +++ b/internal/apis/kfd/v1alpha2/ekscluster/creator.go @@ -14,23 +14,21 @@ import ( "sync" "time" - r3diff "github.com/r3labs/diff/v3" "github.com/sirupsen/logrus" "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/ekscluster/v1alpha2/private" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2" commcreate "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/common/create" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/create" - eksrules "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/rules" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/vpn" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/distribution" - "github.com/sighupio/furyctl/internal/rules" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/upgrade" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/reducers" + eksrules "github.com/sighupio/furyctl/pkg/rulesextractor" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( @@ -68,7 +66,7 @@ type Phases struct { *create.PreFlight Infrastructure upgrade.OperatorPhaseAsync Kubernetes upgrade.OperatorPhaseAsync - Distribution upgrade.ReducersOperatorPhaseAsync[v1alpha2.Reducers] + Distribution upgrade.ReducersOperatorPhaseAsync[reducers.Reducers] *commcreate.Plugins } @@ -341,7 +339,7 @@ func (v *ClusterCreator) CreateAsync( } } - reducers := v.buildReducers(status.Diffs, r, cluster.OperationPhaseDistribution) + rdcs := reducers.Build(status.Diffs, r, cluster.OperationPhaseDistribution) unsafeReducers := r.UnsafeReducerRulesByDiffs( r.GetReducers( @@ -350,9 +348,9 @@ func (v *ClusterCreator) CreateAsync( status.Diffs, ) - if len(reducers) > 0 { + if len(rdcs) > 0 { logrus.Infof("Differences found from previous cluster configuration, "+ - "handling the following changes:\n%s", reducers.ToString()) + "handling the following changes:\n%s", rdcs.ToString()) } if distribution.HasFeature(v.kfdManifest, distribution.FeatureClusterUpgrade) { @@ -364,7 +362,7 @@ func (v *ClusterCreator) CreateAsync( v.upgrade, v.force, upgr, - reducers, + rdcs, status.Diffs, v.externalUpgradesPath, false, @@ -389,7 +387,7 @@ func (v *ClusterCreator) CreateAsync( } case cluster.OperationPhaseDistribution: - if len(reducers) > 0 && len(unsafeReducers) > 0 { + if len(rdcs) > 0 && len(unsafeReducers) > 0 { confirm, err := cluster.AskConfirmation(cluster.IsForceEnabledForFeature(v.force, cluster.ForceFeatureMigrations)) if err != nil { errCh <- err @@ -400,7 +398,7 @@ func (v *ClusterCreator) CreateAsync( } } - if err := v.distributionPhase(phases.Distribution, vpnConnector, reducers, renderedConfig); err != nil { + if err := v.distributionPhase(phases.Distribution, vpnConnector, rdcs, renderedConfig); err != nil { errCh <- err } @@ -414,7 +412,7 @@ func (v *ClusterCreator) CreateAsync( } case cluster.OperationPhaseAll: - if len(reducers) > 0 && len(unsafeReducers) > 0 { + if len(rdcs) > 0 && len(unsafeReducers) > 0 { confirm, err := cluster.AskConfirmation(cluster.IsForceEnabledForFeature(v.force, cluster.ForceFeatureMigrations)) if err != nil { errCh <- err @@ -429,7 +427,7 @@ func (v *ClusterCreator) CreateAsync( startFrom, phases, vpnConnector, - reducers, + rdcs, upgr, renderedConfig, ) @@ -536,9 +534,9 @@ func (v *ClusterCreator) kubernetesPhase( } func (v *ClusterCreator) distributionPhase( - distro upgrade.ReducersOperatorPhaseAsync[v1alpha2.Reducers], + distro upgrade.ReducersOperatorPhaseAsync[reducers.Reducers], vpnConnector *vpn.Connector, - reducers v1alpha2.Reducers, + rdcs reducers.Reducers, renderedConfig map[string]any, ) error { upgradeState := upgrade.State{ @@ -557,7 +555,7 @@ func (v *ClusterCreator) distributionPhase( } } - if err := distro.Exec(reducers, StartFromFlagNotSet, &upgradeState); err != nil { + if err := distro.Exec(rdcs, StartFromFlagNotSet, &upgradeState); err != nil { return fmt.Errorf("error while installing Kubernetes Fury Distribution: %w", err) } @@ -588,7 +586,7 @@ func (v *ClusterCreator) allPhases( startFrom string, phases *Phases, vpnConnector *vpn.Connector, - reducers v1alpha2.Reducers, + rdcs reducers.Reducers, upgr *upgrade.Upgrade, renderedConfig map[string]any, ) error { @@ -633,7 +631,7 @@ func (v *ClusterCreator) allPhases( startFrom, phases, vpnConnector, - reducers, + rdcs, upgradeState, ); err != nil { return err @@ -676,7 +674,7 @@ func (v *ClusterCreator) allPhasesExec( startFrom string, phases *Phases, vpnConnector *vpn.Connector, - reducers v1alpha2.Reducers, + rdcs reducers.Reducers, upgradeState *upgrade.State, ) error { if v.furyctlConf.Spec.Infrastructure != nil && @@ -713,7 +711,7 @@ func (v *ClusterCreator) allPhasesExec( } if startFrom != cluster.OperationPhasePlugins { - if err := phases.Distribution.Exec(reducers, v.getDistributionSubPhase(startFrom), upgradeState); err != nil { + if err := phases.Distribution.Exec(rdcs, v.getDistributionSubPhase(startFrom), upgradeState); err != nil { return fmt.Errorf("error while executing distribution phase: %w", err) } } @@ -755,41 +753,6 @@ func (*ClusterCreator) getDistributionSubPhase(startFrom string) string { } } -func (*ClusterCreator) buildReducers( - statusDiffs r3diff.Changelog, - rulesExtractor rules.Extractor, - phase string, -) v1alpha2.Reducers { - reducersRules := rulesExtractor.GetReducers(phase) - - filteredReducers := rulesExtractor.ReducerRulesByDiffs(reducersRules, statusDiffs) - - reducers := make(v1alpha2.Reducers, len(filteredReducers)) - - if len(filteredReducers) > 0 { - for _, reducer := range filteredReducers { - if reducer.Reducers != nil { - if reducer.Description != nil { - logrus.Infof("%s", *reducer.Description) - } - - for _, red := range *reducer.Reducers { - reducers = append(reducers, v1alpha2.NewBaseReducer( - red.Key, - red.From, - red.To, - red.Lifecycle, - reducer.Path, - ), - ) - } - } - } - } - - return reducers -} - func (v *ClusterCreator) RenderConfig() (map[string]any, error) { specMap := map[string]any{} @@ -825,7 +788,7 @@ func (v *ClusterCreator) RenderConfig() (map[string]any, error) { func (v *ClusterCreator) setupPhases(upgr *upgrade.Upgrade, upgradeFlag bool) ( *upgrade.OperatorPhaseAsyncDecorator, *upgrade.OperatorPhaseAsyncDecorator, - *upgrade.ReducerOperatorPhaseAsyncDecorator[v1alpha2.Reducers], + *upgrade.ReducerOperatorPhaseAsyncDecorator[reducers.Reducers], *commcreate.Plugins, *create.PreFlight, error, @@ -857,7 +820,7 @@ func (v *ClusterCreator) setupPhases(upgr *upgrade.Upgrade, upgradeFlag bool) ( upgr, ) - distro := upgrade.NewReducerOperatorPhaseAsyncDecorator[v1alpha2.Reducers]( + distro := upgrade.NewReducerOperatorPhaseAsyncDecorator[reducers.Reducers]( v.upgradeStateStore, create.NewDistribution( v.paths, diff --git a/internal/apis/kfd/v1alpha2/ekscluster/schema.go b/internal/apis/kfd/v1alpha2/ekscluster/schema.go index 77e5f9b7e..16d92d3e7 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/schema.go +++ b/internal/apis/kfd/v1alpha2/ekscluster/schema.go @@ -9,7 +9,7 @@ import ( "fmt" "github.com/sighupio/fury-distribution/pkg/apis/ekscluster/v1alpha2/private" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ( diff --git a/internal/apis/kfd/v1alpha2/ekscluster/tool.go b/internal/apis/kfd/v1alpha2/ekscluster/tool.go index 1e3a34df2..0d2e30808 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/tool.go +++ b/internal/apis/kfd/v1alpha2/ekscluster/tool.go @@ -10,7 +10,7 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/ekscluster/v1alpha2/private" "github.com/sighupio/furyctl/internal/tool/openvpn" execx "github.com/sighupio/furyctl/internal/x/exec" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ErrOpenVPNNotInstalled = errors.New("openvpn is not installed") diff --git a/internal/apis/kfd/v1alpha2/kfddistribution/create/distribution.go b/internal/apis/kfd/v1alpha2/kfddistribution/create/distribution.go index 6ac0234b9..5f5f04035 100644 --- a/internal/apis/kfd/v1alpha2/kfddistribution/create/distribution.go +++ b/internal/apis/kfd/v1alpha2/kfddistribution/create/distribution.go @@ -15,16 +15,16 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/kfddistribution/v1alpha2/public" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/kubectl" "github.com/sighupio/furyctl/internal/tool/shell" "github.com/sighupio/furyctl/internal/upgrade" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/reducers" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( @@ -106,7 +106,7 @@ func (*Distribution) SupportsLifecycle(lifecycle string) bool { } } -func (d *Distribution) Exec(reducers v1alpha2.Reducers, startFrom string, upgradeState *upgrade.State) error { +func (d *Distribution) Exec(rdcs reducers.Reducers, startFrom string, upgradeState *upgrade.State) error { logrus.Info("Installing Kubernetes Fury Distribution...") mCfg, err := d.prepare() @@ -125,7 +125,7 @@ func (d *Distribution) Exec(reducers v1alpha2.Reducers, startFrom string, upgrad return fmt.Errorf("error running pre-distribution phase: %w", err) } - if err := d.coreDistribution(reducers, startFrom, upgradeState, mCfg); err != nil { + if err := d.coreDistribution(rdcs, startFrom, upgradeState, mCfg); err != nil { return fmt.Errorf("error running core distribution phase: %w", err) } @@ -260,7 +260,7 @@ func (d *Distribution) preDistribution( } func (d *Distribution) coreDistribution( - reducers v1alpha2.Reducers, + rdcs reducers.Reducers, startFrom string, upgradeState *upgrade.State, mCfg template.Config, @@ -269,7 +269,7 @@ func (d *Distribution) coreDistribution( logrus.Info("Applying manifests...") if err := d.runReducers( - reducers, + rdcs, mCfg, LifecyclePreApply, []string{"manifests", "terraform", ".gitignore"}, @@ -286,7 +286,7 @@ func (d *Distribution) coreDistribution( } if err := d.runReducers( - reducers, + rdcs, mCfg, LifecyclePostApply, []string{"manifests", "terraform", ".gitignore"}, @@ -365,12 +365,12 @@ func (d *Distribution) Stop() error { } func (d *Distribution) runReducers( - reducers v1alpha2.Reducers, + rdcs reducers.Reducers, cfg template.Config, lifecycle string, excludes []string, ) error { - r := reducers.ByLifecycle(lifecycle) + r := rdcs.ByLifecycle(lifecycle) if len(r) > 0 { preTfReducersCfg := cfg diff --git a/internal/apis/kfd/v1alpha2/kfddistribution/create/preflight.go b/internal/apis/kfd/v1alpha2/kfddistribution/create/preflight.go index 4ecc48fd8..6544c8976 100644 --- a/internal/apis/kfd/v1alpha2/kfddistribution/create/preflight.go +++ b/internal/apis/kfd/v1alpha2/kfddistribution/create/preflight.go @@ -15,17 +15,17 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/kfddistribution/v1alpha2/public" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/kfddistribution/rules" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/kfddistribution/supported" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/diffs" "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/parser" "github.com/sighupio/furyctl/internal/state" "github.com/sighupio/furyctl/internal/tool/kubectl" execx "github.com/sighupio/furyctl/internal/x/exec" kubex "github.com/sighupio/furyctl/internal/x/kube" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/diffs" + rules "github.com/sighupio/furyctl/pkg/rulesextractor" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ( diff --git a/internal/apis/kfd/v1alpha2/kfddistribution/creator.go b/internal/apis/kfd/v1alpha2/kfddistribution/creator.go index 1a5b48144..fe4a665c8 100644 --- a/internal/apis/kfd/v1alpha2/kfddistribution/creator.go +++ b/internal/apis/kfd/v1alpha2/kfddistribution/creator.go @@ -10,22 +10,20 @@ import ( "path" "strings" - r3diff "github.com/r3labs/diff/v3" "github.com/sirupsen/logrus" "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/kfddistribution/v1alpha2/public" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2" commcreate "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/common/create" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/kfddistribution/create" - distrorules "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/kfddistribution/rules" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/distribution" - "github.com/sighupio/furyctl/internal/rules" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/upgrade" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/reducers" + distrorules "github.com/sighupio/furyctl/pkg/rulesextractor" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( @@ -150,7 +148,7 @@ func (*ClusterCreator) GetPhasePath(phase string) (string, error) { func (c *ClusterCreator) Create(startFrom string, _, _ int) error { upgr := upgrade.New(c.paths, string(c.furyctlConf.Kind)) - distributionPhase := upgrade.NewReducerOperatorPhaseDecorator[v1alpha2.Reducers]( + distributionPhase := upgrade.NewReducerOperatorPhaseDecorator[reducers.Reducers]( c.upgradeStateStore, create.NewDistribution( c.paths, @@ -198,7 +196,7 @@ func (c *ClusterCreator) Create(startFrom string, _, _ int) error { } } - reducers := c.buildReducers( + rdcs := reducers.Build( status.Diffs, r, cluster.OperationPhaseDistribution, @@ -211,9 +209,9 @@ func (c *ClusterCreator) Create(startFrom string, _, _ int) error { status.Diffs, ) - if len(reducers) > 0 { + if len(rdcs) > 0 { logrus.Infof("Differences found from previous cluster configuration, "+ - "handling the following changes:\n%s", reducers.ToString()) + "handling the following changes:\n%s", rdcs.ToString()) } if distribution.HasFeature(c.kfdManifest, distribution.FeatureClusterUpgrade) { @@ -225,7 +223,7 @@ func (c *ClusterCreator) Create(startFrom string, _, _ int) error { c.upgrade, c.force, upgr, - reducers, + rdcs, status.Diffs, c.externalUpgradesPath, false, @@ -238,7 +236,7 @@ func (c *ClusterCreator) Create(startFrom string, _, _ int) error { switch c.phase { case cluster.OperationPhaseDistribution: - if len(reducers) > 0 && len(unsafeReducers) > 0 { + if len(rdcs) > 0 && len(unsafeReducers) > 0 { confirm, err := cluster.AskConfirmation(cluster.IsForceEnabledForFeature(c.force, cluster.ForceFeatureMigrations)) if err != nil { return fmt.Errorf("error while asking for confirmation: %w", err) @@ -257,7 +255,7 @@ func (c *ClusterCreator) Create(startFrom string, _, _ int) error { }, } - if err := distributionPhase.Exec(reducers, StartFromFlagNotSet, &upgradeState); err != nil { + if err := distributionPhase.Exec(rdcs, StartFromFlagNotSet, &upgradeState); err != nil { return fmt.Errorf("error while executing distribution phase: %w", err) } @@ -273,7 +271,7 @@ func (c *ClusterCreator) Create(startFrom string, _, _ int) error { case cluster.OperationPhaseAll: if err := c.allPhases( startFrom, - reducers, + rdcs, unsafeReducers, distributionPhase, pluginsPhase, @@ -309,9 +307,9 @@ func (c *ClusterCreator) Create(startFrom string, _, _ int) error { func (c *ClusterCreator) allPhases( startFrom string, - reducers v1alpha2.Reducers, - unsafeReducers []rules.Rule, - distributionPhase upgrade.ReducersOperatorPhase[v1alpha2.Reducers], + rdcs reducers.Reducers, + unsafeReducers []distrorules.Rule, + distributionPhase upgrade.ReducersOperatorPhase[reducers.Reducers], pluginsPhase *commcreate.Plugins, upgr *upgrade.Upgrade, ) error { @@ -346,7 +344,7 @@ func (c *ClusterCreator) allPhases( } if startFrom != cluster.OperationPhasePlugins { - if len(reducers) > 0 && len(unsafeReducers) > 0 { + if len(rdcs) > 0 && len(unsafeReducers) > 0 { confirm, err := cluster.AskConfirmation(cluster.IsForceEnabledForFeature(c.force, cluster.ForceFeatureMigrations)) if err != nil { return fmt.Errorf("error while asking for confirmation: %w", err) @@ -357,7 +355,7 @@ func (c *ClusterCreator) allPhases( } } - if err := distributionPhase.Exec(reducers, c.getDistributionSubPhase(startFrom), upgradeState); err != nil { + if err := distributionPhase.Exec(rdcs, c.getDistributionSubPhase(startFrom), upgradeState); err != nil { return fmt.Errorf("error while executing distribution phase: %w", err) } } @@ -393,41 +391,6 @@ func (*ClusterCreator) getDistributionSubPhase(startFrom string) string { } } -func (*ClusterCreator) buildReducers( - statusDiffs r3diff.Changelog, - rulesExtractor rules.Extractor, - phase string, -) v1alpha2.Reducers { - reducersRules := rulesExtractor.GetReducers(phase) - - filteredReducers := rulesExtractor.ReducerRulesByDiffs(reducersRules, statusDiffs) - - reducers := make(v1alpha2.Reducers, len(filteredReducers)) - - if len(filteredReducers) > 0 { - for _, reducer := range filteredReducers { - if reducer.Reducers != nil { - if reducer.Description != nil { - logrus.Infof("%s", *reducer.Description) - } - - for _, red := range *reducer.Reducers { - reducers = append(reducers, v1alpha2.NewBaseReducer( - red.Key, - red.From, - red.To, - red.Lifecycle, - reducer.Path, - ), - ) - } - } - } - } - - return reducers -} - func (c *ClusterCreator) RenderConfig() (map[string]any, error) { specMap := map[string]any{} diff --git a/internal/apis/kfd/v1alpha2/kfddistribution/delete/distribution.go b/internal/apis/kfd/v1alpha2/kfddistribution/delete/distribution.go index e9b0f176b..35a8a43bf 100644 --- a/internal/apis/kfd/v1alpha2/kfddistribution/delete/distribution.go +++ b/internal/apis/kfd/v1alpha2/kfddistribution/delete/distribution.go @@ -15,12 +15,12 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/kfddistribution/v1alpha2/public" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/kubectl" "github.com/sighupio/furyctl/internal/tool/shell" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type Ingress struct { diff --git a/internal/apis/kfd/v1alpha2/onpremises/create/distribution.go b/internal/apis/kfd/v1alpha2/onpremises/create/distribution.go index 61c0def93..6a4faa56d 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/create/distribution.go +++ b/internal/apis/kfd/v1alpha2/onpremises/create/distribution.go @@ -13,16 +13,16 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/onpremises/v1alpha2/public" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/kubectl" "github.com/sighupio/furyctl/internal/tool/shell" "github.com/sighupio/furyctl/internal/upgrade" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/reducers" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( @@ -48,7 +48,7 @@ func (d *Distribution) Self() *cluster.OperationPhase { return d.OperationPhase } -func (d *Distribution) Exec(reducers v1alpha2.Reducers, startFrom string, upgradeState *upgrade.State) error { +func (d *Distribution) Exec(rdcs reducers.Reducers, startFrom string, upgradeState *upgrade.State) error { logrus.Info("Installing Kubernetes Fury Distribution...") mCfg, err := d.prepare() @@ -66,7 +66,7 @@ func (d *Distribution) Exec(reducers v1alpha2.Reducers, startFrom string, upgrad return fmt.Errorf("error running pre-distribution phase: %w", err) } - if err := d.coreDistribution(startFrom, upgradeState, reducers, mCfg); err != nil { + if err := d.coreDistribution(startFrom, upgradeState, rdcs, mCfg); err != nil { return fmt.Errorf("error running core distribution phase: %w", err) } @@ -181,14 +181,14 @@ func (d *Distribution) preDistribution( func (d *Distribution) coreDistribution( startFrom string, upgradeState *upgrade.State, - reducers v1alpha2.Reducers, + rcds reducers.Reducers, mCfg template.Config, ) error { if startFrom != cluster.OperationSubPhasePostDistribution { logrus.Info("Applying manifests...") if err := d.runReducers( - reducers, + rcds, mCfg, LifecyclePreApply, []string{"manifests", "terraform", ".gitignore"}, @@ -209,7 +209,7 @@ func (d *Distribution) coreDistribution( } if err := d.runReducers( - reducers, + rcds, mCfg, LifecyclePostApply, []string{"manifests", "terraform", ".gitignore"}, @@ -238,12 +238,12 @@ func (d *Distribution) postDistribution( } func (d *Distribution) runReducers( - reducers v1alpha2.Reducers, + rdcs reducers.Reducers, cfg template.Config, lifecycle string, excludes []string, ) error { - r := reducers.ByLifecycle(lifecycle) + r := rdcs.ByLifecycle(lifecycle) if len(r) > 0 { preTfReducersCfg := cfg diff --git a/internal/apis/kfd/v1alpha2/onpremises/create/kubernetes.go b/internal/apis/kfd/v1alpha2/onpremises/create/kubernetes.go index 76ae03d1a..6315adf18 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/create/kubernetes.go +++ b/internal/apis/kfd/v1alpha2/onpremises/create/kubernetes.go @@ -13,11 +13,11 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/onpremises/v1alpha2/public" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/ansible" "github.com/sighupio/furyctl/internal/upgrade" execx "github.com/sighupio/furyctl/internal/x/exec" kubex "github.com/sighupio/furyctl/internal/x/kube" + "github.com/sighupio/furyctl/pkg/template" ) const FromSecondsToHalfMinuteRetries = 30 diff --git a/internal/apis/kfd/v1alpha2/onpremises/create/preflight.go b/internal/apis/kfd/v1alpha2/onpremises/create/preflight.go index 814c78e6f..56018243a 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/create/preflight.go +++ b/internal/apis/kfd/v1alpha2/onpremises/create/preflight.go @@ -14,17 +14,17 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/onpremises/v1alpha2/public" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/onpremises/rules" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/onpremises/supported" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/diffs" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/ansible" "github.com/sighupio/furyctl/internal/tool/kubectl" execx "github.com/sighupio/furyctl/internal/x/exec" kubex "github.com/sighupio/furyctl/internal/x/kube" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/diffs" + rules "github.com/sighupio/furyctl/pkg/rulesextractor" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ( diff --git a/internal/apis/kfd/v1alpha2/onpremises/creator.go b/internal/apis/kfd/v1alpha2/onpremises/creator.go index 0ab46f4ef..92248245b 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/creator.go +++ b/internal/apis/kfd/v1alpha2/onpremises/creator.go @@ -10,22 +10,20 @@ import ( "path" "strings" - r3diff "github.com/r3labs/diff/v3" "github.com/sirupsen/logrus" "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/onpremises/v1alpha2/public" - "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2" commcreate "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/common/create" "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/onpremises/create" - premrules "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/onpremises/rules" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/distribution" - "github.com/sighupio/furyctl/internal/rules" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/upgrade" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/reducers" + premrules "github.com/sighupio/furyctl/pkg/rulesextractor" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( @@ -183,7 +181,7 @@ func (c *ClusterCreator) Create(startFrom string, _, podRunningCheckTimeout int) upgr, ) - distributionPhase := upgrade.NewReducerOperatorPhaseDecorator[v1alpha2.Reducers]( + distributionPhase := upgrade.NewReducerOperatorPhaseDecorator[reducers.Reducers]( c.upgradeStateStore, create.NewDistribution( c.furyctlConf, @@ -231,7 +229,7 @@ func (c *ClusterCreator) Create(startFrom string, _, podRunningCheckTimeout int) } } - reducers := c.buildReducers( + rdcs := reducers.Build( status.Diffs, r, cluster.OperationPhaseDistribution, @@ -244,9 +242,9 @@ func (c *ClusterCreator) Create(startFrom string, _, podRunningCheckTimeout int) status.Diffs, ) - if len(reducers) > 0 { + if len(rdcs) > 0 { logrus.Infof("Differences found from previous cluster configuration, "+ - "handling the following changes:\n%s", reducers.ToString()) + "handling the following changes:\n%s", rdcs.ToString()) } if distribution.HasFeature(c.kfdManifest, distribution.FeatureClusterUpgrade) { @@ -258,7 +256,7 @@ func (c *ClusterCreator) Create(startFrom string, _, podRunningCheckTimeout int) c.upgrade, c.force, upgr, - reducers, + rdcs, status.Diffs, c.externalUpgradesPath, c.skipNodesUpgrade, @@ -284,7 +282,7 @@ func (c *ClusterCreator) Create(startFrom string, _, podRunningCheckTimeout int) } case cluster.OperationPhaseDistribution: - if len(reducers) > 0 && len(unsafeReducers) > 0 { + if len(rdcs) > 0 && len(unsafeReducers) > 0 { confirm, err := cluster.AskConfirmation(cluster.IsForceEnabledForFeature(c.force, cluster.ForceFeatureMigrations)) if err != nil { return fmt.Errorf("error while asking for confirmation: %w", err) @@ -303,7 +301,7 @@ func (c *ClusterCreator) Create(startFrom string, _, podRunningCheckTimeout int) }, } - if err := distributionPhase.Exec(reducers, StartFromFlagNotSet, &upgradeState); err != nil { + if err := distributionPhase.Exec(rdcs, StartFromFlagNotSet, &upgradeState); err != nil { return fmt.Errorf("error while executing distribution phase: %w", err) } @@ -323,7 +321,7 @@ func (c *ClusterCreator) Create(startFrom string, _, podRunningCheckTimeout int) distributionPhase, pluginsPhase, upgr, - reducers, + rdcs, unsafeReducers, ); err != nil { return fmt.Errorf("error while executing cluster creation: %w", err) @@ -357,11 +355,11 @@ func (c *ClusterCreator) Create(startFrom string, _, podRunningCheckTimeout int) func (c *ClusterCreator) allPhases( startFrom string, kubernetesPhase upgrade.OperatorPhase, - distributionPhase upgrade.ReducersOperatorPhase[v1alpha2.Reducers], + distributionPhase upgrade.ReducersOperatorPhase[reducers.Reducers], pluginsPhase *commcreate.Plugins, upgr *upgrade.Upgrade, - reducers v1alpha2.Reducers, - unsafeReducers []rules.Rule, + rdcs reducers.Reducers, + unsafeReducers []premrules.Rule, ) error { upgradeState := &upgrade.State{} @@ -407,7 +405,7 @@ func (c *ClusterCreator) allPhases( } if startFrom != cluster.OperationPhasePlugins { - if len(reducers) > 0 && len(unsafeReducers) > 0 { + if len(rdcs) > 0 && len(unsafeReducers) > 0 { confirm, err := cluster.AskConfirmation(cluster.IsForceEnabledForFeature(c.force, cluster.ForceFeatureMigrations)) if err != nil { return fmt.Errorf("error while asking for confirmation: %w", err) @@ -418,7 +416,7 @@ func (c *ClusterCreator) allPhases( } } - if err := distributionPhase.Exec(reducers, c.getDistributionSubPhase(startFrom), upgradeState); err != nil { + if err := distributionPhase.Exec(rdcs, c.getDistributionSubPhase(startFrom), upgradeState); err != nil { return fmt.Errorf("error while executing distribution phase: %w", err) } } @@ -469,43 +467,6 @@ func (*ClusterCreator) getDistributionSubPhase(startFrom string) string { } } -func (*ClusterCreator) buildReducers( - statusDiffs r3diff.Changelog, - rulesExtractor rules.Extractor, - phase string, -) v1alpha2.Reducers { - reducersRules := rulesExtractor.GetReducers(phase) - - filteredReducers := rulesExtractor.ReducerRulesByDiffs(reducersRules, statusDiffs) - - reducers := make(v1alpha2.Reducers, len(filteredReducers)) - - if len(filteredReducers) > 0 { - for _, reducer := range filteredReducers { - if reducer.Reducers != nil { - if reducer.Description != nil { - logrus.Infof("%s", *reducer.Description) - } - - for _, red := range *reducer.Reducers { - reducers = append( - reducers, - v1alpha2.NewBaseReducer( - red.Key, - red.From, - red.To, - red.Lifecycle, - reducer.Path, - ), - ) - } - } - } - } - - return reducers -} - func (c *ClusterCreator) RenderConfig() (map[string]any, error) { specMap := map[string]any{} diff --git a/internal/apis/kfd/v1alpha2/onpremises/delete/distribution.go b/internal/apis/kfd/v1alpha2/onpremises/delete/distribution.go index dbfe4a70f..a9aed776f 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/delete/distribution.go +++ b/internal/apis/kfd/v1alpha2/onpremises/delete/distribution.go @@ -16,12 +16,12 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/onpremises/v1alpha2/public" "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/state" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/kubectl" "github.com/sighupio/furyctl/internal/tool/shell" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type Distribution struct { diff --git a/internal/apis/kfd/v1alpha2/onpremises/delete/kubernetes.go b/internal/apis/kfd/v1alpha2/onpremises/delete/kubernetes.go index d8a705859..872da4935 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/delete/kubernetes.go +++ b/internal/apis/kfd/v1alpha2/onpremises/delete/kubernetes.go @@ -14,9 +14,9 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/onpremises/v1alpha2/public" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/ansible" execx "github.com/sighupio/furyctl/internal/x/exec" + "github.com/sighupio/furyctl/pkg/template" ) type Kubernetes struct { diff --git a/internal/apis/kfd/v1alpha2/onpremises/delete/preflight.go b/internal/apis/kfd/v1alpha2/onpremises/delete/preflight.go index 0e77563f6..46cdcee5b 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/delete/preflight.go +++ b/internal/apis/kfd/v1alpha2/onpremises/delete/preflight.go @@ -14,11 +14,11 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/onpremises/v1alpha2/public" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/ansible" "github.com/sighupio/furyctl/internal/tool/kubectl" execx "github.com/sighupio/furyctl/internal/x/exec" kubex "github.com/sighupio/furyctl/internal/x/kube" + "github.com/sighupio/furyctl/pkg/template" ) type PreFlight struct { diff --git a/internal/apis/kfd/v1alpha2/onpremises/kubeconfig_getter.go b/internal/apis/kfd/v1alpha2/onpremises/kubeconfig_getter.go index d118de618..481fd6de5 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/kubeconfig_getter.go +++ b/internal/apis/kfd/v1alpha2/onpremises/kubeconfig_getter.go @@ -16,10 +16,10 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/fury-distribution/pkg/apis/onpremises/v1alpha2/public" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/ansible" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" + "github.com/sighupio/furyctl/pkg/template" ) var ErrKubeconfigNotSet = errors.New("KUBECONFIG env variable is not set") diff --git a/internal/cluster/creator.go b/internal/cluster/creator.go index 82eb84f68..ccf99ea19 100644 --- a/internal/cluster/creator.go +++ b/internal/cluster/creator.go @@ -10,7 +10,7 @@ import ( "strings" "github.com/sighupio/fury-distribution/pkg/apis/config" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( diff --git a/internal/cluster/deleter.go b/internal/cluster/deleter.go index ea5936387..b6761611d 100644 --- a/internal/cluster/deleter.go +++ b/internal/cluster/deleter.go @@ -9,7 +9,7 @@ import ( "strings" "github.com/sighupio/fury-distribution/pkg/apis/config" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( diff --git a/internal/cluster/kubeconfig_getter.go b/internal/cluster/kubeconfig_getter.go index f1ba27af0..b86984a07 100644 --- a/internal/cluster/kubeconfig_getter.go +++ b/internal/cluster/kubeconfig_getter.go @@ -9,7 +9,7 @@ import ( "strings" "github.com/sighupio/fury-distribution/pkg/apis/config" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( diff --git a/internal/cluster/phase.go b/internal/cluster/phase.go index eb273b2f0..3167b2adb 100644 --- a/internal/cluster/phase.go +++ b/internal/cluster/phase.go @@ -17,11 +17,11 @@ import ( "github.com/sirupsen/logrus" "github.com/sighupio/fury-distribution/pkg/apis/config" - "github.com/sighupio/furyctl/internal/merge" - "github.com/sighupio/furyctl/internal/template" iox "github.com/sighupio/furyctl/internal/x/io" slicesx "github.com/sighupio/furyctl/internal/x/slices" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/merge" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( diff --git a/internal/config/validate.go b/internal/config/validate.go index 7a388d2cb..8604d1b76 100644 --- a/internal/config/validate.go +++ b/internal/config/validate.go @@ -16,11 +16,12 @@ import ( "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/schema/santhosh" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + dist "github.com/sighupio/furyctl/pkg/distribution" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) func Create( - res distribution.DownloadResult, + res dist.DownloadResult, furyctlPath string, cmdEvent analytics.Event, tracker *analytics.Tracker, @@ -124,7 +125,7 @@ func loadFromFile(path string) (config.Furyctl, error) { } if err := config.NewValidator().Struct(conf); err != nil { - return config.Furyctl{}, fmt.Errorf("%w: %v", distribution.ErrValidateConfig, err) + return config.Furyctl{}, fmt.Errorf("%w: %v", dist.ErrValidateConfig, err) } return conf, err diff --git a/internal/distribution/iac.go b/internal/distribution/iac.go index 1ceb47b02..05e34e98b 100644 --- a/internal/distribution/iac.go +++ b/internal/distribution/iac.go @@ -13,10 +13,10 @@ import ( "github.com/sirupsen/logrus" - "github.com/sighupio/furyctl/internal/merge" - "github.com/sighupio/furyctl/internal/template" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/merge" + "github.com/sighupio/furyctl/pkg/template" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const ( diff --git a/internal/legacy/furyfile.go b/internal/legacy/furyfile.go index 15c1690c4..4963f97fd 100644 --- a/internal/legacy/furyfile.go +++ b/internal/legacy/furyfile.go @@ -11,7 +11,7 @@ import ( "github.com/sirupsen/logrus" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ErrFuryFileUnmarshal = errors.New("error unmarshaling furyfile") diff --git a/internal/state/store.go b/internal/state/store.go index dc2aec883..a973506ee 100644 --- a/internal/state/store.go +++ b/internal/state/store.go @@ -16,7 +16,7 @@ import ( execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" kubex "github.com/sighupio/furyctl/internal/x/kube" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type Storer interface { diff --git a/internal/tool/furyagent/config.go b/internal/tool/furyagent/config.go index 660687b70..5ae84010d 100644 --- a/internal/tool/furyagent/config.go +++ b/internal/tool/furyagent/config.go @@ -5,7 +5,7 @@ package furyagent import ( - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type Storage struct { diff --git a/internal/upgrade/store.go b/internal/upgrade/store.go index 54cd49fcb..1dffb4ee9 100644 --- a/internal/upgrade/store.go +++ b/internal/upgrade/store.go @@ -17,7 +17,7 @@ import ( execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" kubex "github.com/sighupio/furyctl/internal/x/kube" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type PhaseStatus string diff --git a/internal/x/kube/configmap.go b/internal/x/kube/configmap.go index 437ced9a3..41c71cde1 100644 --- a/internal/x/kube/configmap.go +++ b/internal/x/kube/configmap.go @@ -7,7 +7,7 @@ package kubex import ( "fmt" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) func CreateConfigMap(data []byte, name, key, namespace string) ([]byte, error) { diff --git a/internal/x/kube/configmap_test.go b/internal/x/kube/configmap_test.go index d363c8ca4..5be067a92 100644 --- a/internal/x/kube/configmap_test.go +++ b/internal/x/kube/configmap_test.go @@ -8,7 +8,7 @@ import ( "testing" kubex "github.com/sighupio/furyctl/internal/x/kube" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) func TestCreateConfigMap(t *testing.T) { diff --git a/internal/x/kube/secret.go b/internal/x/kube/secret.go index c58b4d914..d45ec76dc 100644 --- a/internal/x/kube/secret.go +++ b/internal/x/kube/secret.go @@ -8,7 +8,7 @@ import ( "errors" "fmt" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ErrCannotCreateSecret = errors.New("cannot create secret") diff --git a/internal/x/kube/secret_test.go b/internal/x/kube/secret_test.go index 6fc61390a..8249fe7ae 100644 --- a/internal/x/kube/secret_test.go +++ b/internal/x/kube/secret_test.go @@ -8,7 +8,7 @@ import ( "testing" kubex "github.com/sighupio/furyctl/internal/x/kube" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) func TestCreateSecret(t *testing.T) { diff --git a/internal/dependencies/download.go b/pkg/dependencies/download.go similarity index 94% rename from internal/dependencies/download.go rename to pkg/dependencies/download.go index f10e4b76f..314791d21 100644 --- a/internal/dependencies/download.go +++ b/pkg/dependencies/download.go @@ -25,7 +25,8 @@ import ( "github.com/sighupio/furyctl/internal/tool" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" - netx "github.com/sighupio/furyctl/internal/x/net" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" ) const downloadsTimeout = 5 * time.Minute @@ -250,7 +251,7 @@ func (dd *Downloader) DownloadModules(kfd config.KFD, gitPrefix string) error { } if err := dd.client.Download(src, dst); err != nil { - errs = append(errs, fmt.Errorf("%w '%s': %v", distribution.ErrDownloadingFolder, src, err)) + errs = append(errs, fmt.Errorf("%w '%s': %v", dist.ErrDownloadingFolder, src, err)) if _, err := os.Stat(dst); err == nil { if err := os.RemoveAll(dst); err != nil { @@ -323,7 +324,7 @@ func (dd *Downloader) DownloadInstallers(installers config.KFDKubernetes, gitPre } if err := dd.client.Download(src, dst); err != nil { - return fmt.Errorf("%w '%s': %v", distribution.ErrDownloadingFolder, src, err) + return fmt.Errorf("%w '%s': %v", dist.ErrDownloadingFolder, src, err) } err := os.RemoveAll(filepath.Join(dst, ".git")) @@ -381,20 +382,20 @@ func (dd *Downloader) DownloadTools(kfd config.KFD) ([]string, error) { dst := filepath.Join(dd.binPath, name, toolCfg.Version) if err := dd.client.Download(tfc.SrcPath(), dst); err != nil { - errCh <- fmt.Errorf("%w '%s': %w", distribution.ErrDownloadingFolder, tfc.SrcPath(), err) + errCh <- fmt.Errorf("%w '%s': %w", dist.ErrDownloadingFolder, tfc.SrcPath(), err) return } if err := tfc.Rename(dst); err != nil { - errCh <- fmt.Errorf("%w '%s': %w", distribution.ErrRenamingFile, tfc.SrcPath(), err) + errCh <- fmt.Errorf("%w '%s': %w", dist.ErrRenamingFile, tfc.SrcPath(), err) return } if _, err := os.Stat(filepath.Join(dst, name)); err == nil { if err := os.Chmod(filepath.Join(dst, name), iox.FullPermAccess); err != nil { - errCh <- fmt.Errorf("%w '%s': %w", distribution.ErrChangingFilePermissions, filepath.Join(dst, name), err) + errCh <- fmt.Errorf("%w '%s': %w", dist.ErrChangingFilePermissions, filepath.Join(dst, name), err) return } diff --git a/internal/dependencies/validate.go b/pkg/dependencies/validate.go similarity index 91% rename from internal/dependencies/validate.go rename to pkg/dependencies/validate.go index 3f1bf08c2..2f7efb8d5 100644 --- a/internal/dependencies/validate.go +++ b/pkg/dependencies/validate.go @@ -10,8 +10,8 @@ import ( "github.com/sighupio/furyctl/internal/dependencies/envvars" "github.com/sighupio/furyctl/internal/dependencies/tools" - "github.com/sighupio/furyctl/internal/distribution" execx "github.com/sighupio/furyctl/internal/x/exec" + dist "github.com/sighupio/furyctl/pkg/distribution" ) var ( @@ -39,7 +39,7 @@ func (v *Validator) ValidateBaseReqs() error { return nil } -func (v *Validator) Validate(res distribution.DownloadResult) error { +func (v *Validator) Validate(res dist.DownloadResult) error { if _, errs := v.toolsValidator.Validate( res.DistroManifest, res.MinimalConf, diff --git a/internal/diffs/checker.go b/pkg/diffs/checker.go similarity index 98% rename from internal/diffs/checker.go rename to pkg/diffs/checker.go index 62ed3db6d..43dccdc05 100644 --- a/internal/diffs/checker.go +++ b/pkg/diffs/checker.go @@ -12,7 +12,7 @@ import ( r3diff "github.com/r3labs/diff/v3" - "github.com/sighupio/furyctl/internal/rules" + rules "github.com/sighupio/furyctl/pkg/rulesextractor" ) var ( diff --git a/internal/diffs/checker_test.go b/pkg/diffs/checker_test.go similarity index 98% rename from internal/diffs/checker_test.go rename to pkg/diffs/checker_test.go index 801cb0956..e3b8bbdd1 100644 --- a/internal/diffs/checker_test.go +++ b/pkg/diffs/checker_test.go @@ -13,7 +13,7 @@ import ( diffx "github.com/r3labs/diff/v3" - "github.com/sighupio/furyctl/internal/diffs" + "github.com/sighupio/furyctl/pkg/diffs" ) func TestBaseChecker_GenerateDiff(t *testing.T) { diff --git a/internal/distribution/download.go b/pkg/distribution/download.go similarity index 96% rename from internal/distribution/download.go rename to pkg/distribution/download.go index 3a8e843f0..3b2926d6c 100644 --- a/internal/distribution/download.go +++ b/pkg/distribution/download.go @@ -18,10 +18,11 @@ import ( "github.com/sighupio/fury-distribution/pkg/apis/config" "github.com/sighupio/furyctl/configs" + idist "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" iox "github.com/sighupio/furyctl/internal/x/io" - netx "github.com/sighupio/furyctl/internal/x/net" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + netx "github.com/sighupio/furyctl/pkg/x/net" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) const DefaultBaseURL = "git::%s/fury-distribution?ref=%s&depth=1" @@ -86,7 +87,7 @@ func (d *Downloader) Download( return DownloadResult{}, fmt.Errorf("%w: %w", ErrYamlUnmarshalFile, err) } - compatChecker, err := NewCompatibilityChecker(minimalConf.Spec.DistributionVersion, minimalConf.Kind) + compatChecker, err := idist.NewCompatibilityChecker(minimalConf.Spec.DistributionVersion, minimalConf.Kind) if err != nil { return DownloadResult{}, fmt.Errorf("%w: %w", ErrCannotDownloadDistribution, err) } diff --git a/internal/distribution/download_test.go b/pkg/distribution/download_test.go similarity index 91% rename from internal/distribution/download_test.go rename to pkg/distribution/download_test.go index 4c05fba52..f18380059 100644 --- a/internal/distribution/download_test.go +++ b/pkg/distribution/download_test.go @@ -11,9 +11,9 @@ import ( "path/filepath" "testing" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" - netx "github.com/sighupio/furyctl/internal/x/net" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" ) func Test_Downloader_Download(t *testing.T) { @@ -52,7 +52,7 @@ func Test_Downloader_Download(t *testing.T) { t.Fatal(err) } - d := distribution.NewDownloader(netx.NewGoGetterClient(), git.ProtocolSSH, "") + d := dist.NewDownloader(netx.NewGoGetterClient(), git.ProtocolSSH, "") res, err := d.Download( absDistroPath, diff --git a/internal/merge/merge.go b/pkg/merge/merge.go similarity index 100% rename from internal/merge/merge.go rename to pkg/merge/merge.go diff --git a/internal/merge/merge_test.go b/pkg/merge/merge_test.go similarity index 97% rename from internal/merge/merge_test.go rename to pkg/merge/merge_test.go index ff8966b9e..04f1a4136 100644 --- a/internal/merge/merge_test.go +++ b/pkg/merge/merge_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/sighupio/furyctl/internal/merge" + "github.com/sighupio/furyctl/pkg/merge" ) func Test_NewMerger(t *testing.T) { diff --git a/internal/merge/model.go b/pkg/merge/model.go similarity index 97% rename from internal/merge/model.go rename to pkg/merge/model.go index f01c65b43..4491fec27 100644 --- a/internal/merge/model.go +++ b/pkg/merge/model.go @@ -9,7 +9,7 @@ import ( "fmt" "strings" - mapx "github.com/sighupio/furyctl/internal/x/map" + mapx "github.com/sighupio/furyctl/pkg/x/map" ) var ( diff --git a/internal/merge/model_test.go b/pkg/merge/model_test.go similarity index 98% rename from internal/merge/model_test.go rename to pkg/merge/model_test.go index b6c155c70..7b172769a 100644 --- a/internal/merge/model_test.go +++ b/pkg/merge/model_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/sighupio/furyctl/internal/merge" + "github.com/sighupio/furyctl/pkg/merge" ) func TestNewDefaultModel(t *testing.T) { diff --git a/pkg/reducers/builder.go b/pkg/reducers/builder.go new file mode 100644 index 000000000..e32336cf5 --- /dev/null +++ b/pkg/reducers/builder.go @@ -0,0 +1,46 @@ +// Copyright (c) 2017-present SIGHUP s.r.l All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package reducers + +import ( + r3diff "github.com/r3labs/diff/v3" + "github.com/sirupsen/logrus" + + rules "github.com/sighupio/furyctl/pkg/rulesextractor" +) + +func Build( + statusDiffs r3diff.Changelog, + rulesExtractor rules.Extractor, + phase string, +) Reducers { + reducersRules := rulesExtractor.GetReducers(phase) + + filteredReducers := rulesExtractor.ReducerRulesByDiffs(reducersRules, statusDiffs) + + rdcs := make(Reducers, len(filteredReducers)) + + if len(filteredReducers) > 0 { + for i, reducer := range filteredReducers { + if reducer.Reducers != nil { + if reducer.Description != nil { + logrus.Infof("%s", *reducer.Description) + } + + for _, red := range *reducer.Reducers { + rdcs[i] = NewBaseReducer( + red.Key, + red.From, + red.To, + red.Lifecycle, + reducer.Path, + ) + } + } + } + } + + return rdcs +} diff --git a/internal/apis/kfd/v1alpha2/reducer.go b/pkg/reducers/reducer.go similarity index 99% rename from internal/apis/kfd/v1alpha2/reducer.go rename to pkg/reducers/reducer.go index dd3550157..37024f7aa 100644 --- a/internal/apis/kfd/v1alpha2/reducer.go +++ b/pkg/reducers/reducer.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package v1alpha2 +package reducers import "fmt" diff --git a/internal/apis/kfd/v1alpha2/ekscluster/rules/extractor.go b/pkg/rulesextractor/ekscluster.go similarity index 63% rename from internal/apis/kfd/v1alpha2/ekscluster/rules/extractor.go rename to pkg/rulesextractor/ekscluster.go index 2c75fa97f..57364c47d 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/rules/extractor.go +++ b/pkg/rulesextractor/ekscluster.go @@ -2,24 +2,21 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package rules +package rulesextractor import ( - "errors" "fmt" "path/filepath" "github.com/r3labs/diff/v3" - "github.com/sighupio/furyctl/internal/rules" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/internal/cluster" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) -var ErrReadingRulesFile = errors.New("error while reading rules file") - type EKSExtractor struct { - *rules.BaseExtractor - Spec rules.Spec + *BaseExtractor + Spec Spec } func NewEKSClusterRulesExtractor(distributionPath string) (*EKSExtractor, error) { @@ -27,34 +24,34 @@ func NewEKSClusterRulesExtractor(distributionPath string) (*EKSExtractor, error) rulesPath := filepath.Join(distributionPath, "rules", "ekscluster-kfd-v1alpha2.yaml") - spec, err := yamlx.FromFileV3[rules.Spec](rulesPath) + spec, err := yamlx.FromFileV3[Spec](rulesPath) if err != nil { return &builder, fmt.Errorf("%w: %s", ErrReadingRulesFile, err) } builder.Spec = spec - builder.BaseExtractor = rules.NewBaseExtractor(spec) + builder.BaseExtractor = NewBaseExtractor(spec) return &builder, nil } func (r *EKSExtractor) GetImmutables(phase string) []string { switch phase { - case "infrastructure": + case cluster.OperationPhaseInfrastructure: if r.Spec.Infrastructure == nil { return []string{} } return r.BaseExtractor.ExtractImmutablesFromRules(*r.Spec.Infrastructure) - case "kubernetes": + case cluster.OperationPhaseKubernetes: if r.Spec.Kubernetes == nil { return []string{} } return r.BaseExtractor.ExtractImmutablesFromRules(*r.Spec.Kubernetes) - case "distribution": + case cluster.OperationPhaseDistribution: if r.Spec.Distribution == nil { return []string{} } @@ -66,42 +63,42 @@ func (r *EKSExtractor) GetImmutables(phase string) []string { } } -func (r *EKSExtractor) GetReducers(phase string) []rules.Rule { +func (r *EKSExtractor) GetReducers(phase string) []Rule { switch phase { - case "infrastructure": + case cluster.OperationPhaseInfrastructure: if r.Spec.Infrastructure == nil { - return []rules.Rule{} + return []Rule{} } return r.BaseExtractor.ExtractReducerRules(*r.Spec.Infrastructure) - case "kubernetes": + case cluster.OperationPhaseKubernetes: if r.Spec.Kubernetes == nil { - return []rules.Rule{} + return []Rule{} } return r.BaseExtractor.ExtractReducerRules(*r.Spec.Kubernetes) - case "distribution": + case cluster.OperationPhaseDistribution: if r.Spec.Distribution == nil { - return []rules.Rule{} + return []Rule{} } return r.BaseExtractor.ExtractReducerRules(*r.Spec.Distribution) default: - return []rules.Rule{} + return []Rule{} } } -func (r *EKSExtractor) ReducerRulesByDiffs(rls []rules.Rule, ds diff.Changelog) []rules.Rule { +func (r *EKSExtractor) ReducerRulesByDiffs(rls []Rule, ds diff.Changelog) []Rule { return r.BaseExtractor.ReducerRulesByDiffs(rls, ds) } -func (r *EKSExtractor) UnsupportedReducerRulesByDiffs(rls []rules.Rule, ds diff.Changelog) []rules.Rule { +func (r *EKSExtractor) UnsupportedReducerRulesByDiffs(rls []Rule, ds diff.Changelog) []Rule { return r.BaseExtractor.UnsupportedReducerRulesByDiffs(rls, ds) } -func (r *EKSExtractor) UnsafeReducerRulesByDiffs(rls []rules.Rule, ds diff.Changelog) []rules.Rule { +func (r *EKSExtractor) UnsafeReducerRulesByDiffs(rls []Rule, ds diff.Changelog) []Rule { return r.BaseExtractor.UnsafeReducerRulesByDiffs(rls, ds) } diff --git a/internal/apis/kfd/v1alpha2/ekscluster/rules/extractor_test.go b/pkg/rulesextractor/ekscluster_test.go similarity index 93% rename from internal/apis/kfd/v1alpha2/ekscluster/rules/extractor_test.go rename to pkg/rulesextractor/ekscluster_test.go index 2ee0924c6..cb002a84b 100644 --- a/internal/apis/kfd/v1alpha2/ekscluster/rules/extractor_test.go +++ b/pkg/rulesextractor/ekscluster_test.go @@ -4,14 +4,14 @@ //go:build unit -package rules_test +package rulesextractor_test import ( "reflect" "testing" - eksrules "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/ekscluster/rules" - "github.com/sighupio/furyctl/internal/rules" + eksrules "github.com/sighupio/furyctl/pkg/rulesextractor" + rules "github.com/sighupio/furyctl/pkg/rulesextractor" ) func TestEKSBuilder_GetImmutables(t *testing.T) { diff --git a/internal/rules/extractor.go b/pkg/rulesextractor/extractor.go similarity index 99% rename from internal/rules/extractor.go rename to pkg/rulesextractor/extractor.go index bd8d5eecb..7c5410888 100644 --- a/internal/rules/extractor.go +++ b/pkg/rulesextractor/extractor.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package rules +package rulesextractor import ( "regexp" diff --git a/internal/rules/extractor_test.go b/pkg/rulesextractor/extractor_test.go similarity index 99% rename from internal/rules/extractor_test.go rename to pkg/rulesextractor/extractor_test.go index cdb931d75..54134e89b 100644 --- a/internal/rules/extractor_test.go +++ b/pkg/rulesextractor/extractor_test.go @@ -4,7 +4,7 @@ //go:build unit -package rules_test +package rulesextractor_test import ( "reflect" @@ -12,7 +12,7 @@ import ( "github.com/r3labs/diff/v3" - "github.com/sighupio/furyctl/internal/rules" + rules "github.com/sighupio/furyctl/pkg/rulesextractor" ) func TestNewBaseExtractor(t *testing.T) { diff --git a/internal/apis/kfd/v1alpha2/kfddistribution/rules/extractor.go b/pkg/rulesextractor/kfddistribution.go similarity index 65% rename from internal/apis/kfd/v1alpha2/kfddistribution/rules/extractor.go rename to pkg/rulesextractor/kfddistribution.go index 29dad407c..e248d4ed0 100644 --- a/internal/apis/kfd/v1alpha2/kfddistribution/rules/extractor.go +++ b/pkg/rulesextractor/kfddistribution.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package rules +package rulesextractor import ( "errors" @@ -11,15 +11,15 @@ import ( "github.com/r3labs/diff/v3" - "github.com/sighupio/furyctl/internal/rules" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/internal/cluster" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ErrReadingRulesFile = errors.New("error while reading rules file") type DistroExtractor struct { - *rules.BaseExtractor - Spec rules.Spec + *BaseExtractor + Spec Spec } func NewDistroClusterRulesExtractor(distributionPath string) (*DistroExtractor, error) { @@ -27,7 +27,7 @@ func NewDistroClusterRulesExtractor(distributionPath string) (*DistroExtractor, rulesPath := filepath.Join(distributionPath, "rules", "kfddistribution-kfd-v1alpha2.yaml") - spec, err := yamlx.FromFileV3[rules.Spec](rulesPath) + spec, err := yamlx.FromFileV3[Spec](rulesPath) if err != nil { return &builder, fmt.Errorf("%w: %s", ErrReadingRulesFile, err) } @@ -39,7 +39,7 @@ func NewDistroClusterRulesExtractor(distributionPath string) (*DistroExtractor, func (r *DistroExtractor) GetImmutables(phase string) []string { switch phase { - case "distribution": + case cluster.OperationPhaseDistribution: if r.Spec.Distribution == nil { return []string{} } @@ -51,28 +51,28 @@ func (r *DistroExtractor) GetImmutables(phase string) []string { } } -func (r *DistroExtractor) GetReducers(phase string) []rules.Rule { +func (r *DistroExtractor) GetReducers(phase string) []Rule { switch phase { - case "distribution": + case cluster.OperationPhaseDistribution: if r.Spec.Distribution == nil { - return []rules.Rule{} + return []Rule{} } return r.BaseExtractor.ExtractReducerRules(*r.Spec.Distribution) default: - return []rules.Rule{} + return []Rule{} } } -func (r *DistroExtractor) ReducerRulesByDiffs(rls []rules.Rule, ds diff.Changelog) []rules.Rule { +func (r *DistroExtractor) ReducerRulesByDiffs(rls []Rule, ds diff.Changelog) []Rule { return r.BaseExtractor.ReducerRulesByDiffs(rls, ds) } -func (r *DistroExtractor) UnsupportedReducerRulesByDiffs(rls []rules.Rule, ds diff.Changelog) []rules.Rule { +func (r *DistroExtractor) UnsupportedReducerRulesByDiffs(rls []Rule, ds diff.Changelog) []Rule { return r.BaseExtractor.UnsupportedReducerRulesByDiffs(rls, ds) } -func (r *DistroExtractor) UnsafeReducerRulesByDiffs(rls []rules.Rule, ds diff.Changelog) []rules.Rule { +func (r *DistroExtractor) UnsafeReducerRulesByDiffs(rls []Rule, ds diff.Changelog) []Rule { return r.BaseExtractor.UnsafeReducerRulesByDiffs(rls, ds) } diff --git a/internal/apis/kfd/v1alpha2/kfddistribution/rules/extractor_test.go b/pkg/rulesextractor/kfddistribution_test.go similarity index 80% rename from internal/apis/kfd/v1alpha2/kfddistribution/rules/extractor_test.go rename to pkg/rulesextractor/kfddistribution_test.go index 2079de563..1b96f16cf 100644 --- a/internal/apis/kfd/v1alpha2/kfddistribution/rules/extractor_test.go +++ b/pkg/rulesextractor/kfddistribution_test.go @@ -4,17 +4,17 @@ //go:build unit -package rules_test +package rulesextractor_test import ( "reflect" "testing" - distrorules "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/kfddistribution/rules" - "github.com/sighupio/furyctl/internal/rules" + rules "github.com/sighupio/furyctl/pkg/rulesextractor" + rules_extractor "github.com/sighupio/furyctl/pkg/rulesextractor" ) -func TestEKSBuilder_GetImmutables(t *testing.T) { +func TestKFDBuilder_GetImmutables(t *testing.T) { t.Parallel() testCases := []struct { @@ -54,7 +54,7 @@ func TestEKSBuilder_GetImmutables(t *testing.T) { t.Run(tC.desc, func(t *testing.T) { t.Parallel() - builder := distrorules.DistroExtractor{ + builder := rules_extractor.DistroExtractor{ Spec: *tC.Spec, } diff --git a/internal/apis/kfd/v1alpha2/onpremises/rules/extractor.go b/pkg/rulesextractor/onpremises.go similarity index 63% rename from internal/apis/kfd/v1alpha2/onpremises/rules/extractor.go rename to pkg/rulesextractor/onpremises.go index ffe0c8866..6a657586c 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/rules/extractor.go +++ b/pkg/rulesextractor/onpremises.go @@ -2,24 +2,21 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package rules +package rulesextractor import ( - "errors" "fmt" "path/filepath" "github.com/r3labs/diff/v3" - "github.com/sighupio/furyctl/internal/rules" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/internal/cluster" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) -var ErrReadingRulesFile = errors.New("error while reading rules file") - type OnPremExtractor struct { - *rules.BaseExtractor - Spec rules.Spec + *BaseExtractor + Spec Spec } func NewOnPremClusterRulesExtractor(distributionPath string) (*OnPremExtractor, error) { @@ -27,7 +24,7 @@ func NewOnPremClusterRulesExtractor(distributionPath string) (*OnPremExtractor, rulesPath := filepath.Join(distributionPath, "rules", "onpremises-kfd-v1alpha2.yaml") - spec, err := yamlx.FromFileV3[rules.Spec](rulesPath) + spec, err := yamlx.FromFileV3[Spec](rulesPath) if err != nil { return &builder, fmt.Errorf("%w: %s", ErrReadingRulesFile, err) } @@ -39,14 +36,14 @@ func NewOnPremClusterRulesExtractor(distributionPath string) (*OnPremExtractor, func (r *OnPremExtractor) GetImmutables(phase string) []string { switch phase { - case "kubernetes": + case cluster.OperationPhaseKubernetes: if r.Spec.Kubernetes == nil { return []string{} } return r.BaseExtractor.ExtractImmutablesFromRules(*r.Spec.Kubernetes) - case "distribution": + case cluster.OperationPhaseDistribution: if r.Spec.Distribution == nil { return []string{} } @@ -58,35 +55,35 @@ func (r *OnPremExtractor) GetImmutables(phase string) []string { } } -func (r *OnPremExtractor) GetReducers(phase string) []rules.Rule { +func (r *OnPremExtractor) GetReducers(phase string) []Rule { switch phase { - case "kubernetes": + case cluster.OperationPhaseKubernetes: if r.Spec.Kubernetes == nil { - return []rules.Rule{} + return []Rule{} } return r.BaseExtractor.ExtractReducerRules(*r.Spec.Kubernetes) - case "distribution": + case cluster.OperationPhaseDistribution: if r.Spec.Distribution == nil { - return []rules.Rule{} + return []Rule{} } return r.BaseExtractor.ExtractReducerRules(*r.Spec.Distribution) default: - return []rules.Rule{} + return []Rule{} } } -func (r *OnPremExtractor) ReducerRulesByDiffs(rls []rules.Rule, ds diff.Changelog) []rules.Rule { +func (r *OnPremExtractor) ReducerRulesByDiffs(rls []Rule, ds diff.Changelog) []Rule { return r.BaseExtractor.ReducerRulesByDiffs(rls, ds) } -func (r *OnPremExtractor) UnsupportedReducerRulesByDiffs(rls []rules.Rule, ds diff.Changelog) []rules.Rule { +func (r *OnPremExtractor) UnsupportedReducerRulesByDiffs(rls []Rule, ds diff.Changelog) []Rule { return r.BaseExtractor.UnsupportedReducerRulesByDiffs(rls, ds) } -func (r *OnPremExtractor) UnsafeReducerRulesByDiffs(rls []rules.Rule, ds diff.Changelog) []rules.Rule { +func (r *OnPremExtractor) UnsafeReducerRulesByDiffs(rls []Rule, ds diff.Changelog) []Rule { return r.BaseExtractor.UnsafeReducerRulesByDiffs(rls, ds) } diff --git a/internal/apis/kfd/v1alpha2/onpremises/rules/extractor_test.go b/pkg/rulesextractor/onpremises_test.go similarity index 88% rename from internal/apis/kfd/v1alpha2/onpremises/rules/extractor_test.go rename to pkg/rulesextractor/onpremises_test.go index e9c8d0ffd..a32d38593 100644 --- a/internal/apis/kfd/v1alpha2/onpremises/rules/extractor_test.go +++ b/pkg/rulesextractor/onpremises_test.go @@ -4,17 +4,17 @@ //go:build unit -package rules_test +package rulesextractor_test import ( "reflect" "testing" - onpremrules "github.com/sighupio/furyctl/internal/apis/kfd/v1alpha2/onpremises/rules" - "github.com/sighupio/furyctl/internal/rules" + onpremrules "github.com/sighupio/furyctl/pkg/rulesextractor" + rules "github.com/sighupio/furyctl/pkg/rulesextractor" ) -func TestEKSBuilder_GetImmutables(t *testing.T) { +func TestOnPremisesBuilder_GetImmutables(t *testing.T) { t.Parallel() testCases := []struct { diff --git a/internal/template/config.go b/pkg/template/config.go similarity index 97% rename from internal/template/config.go rename to pkg/template/config.go index e42726ef4..d17fa9120 100644 --- a/internal/template/config.go +++ b/pkg/template/config.go @@ -9,8 +9,8 @@ import ( "fmt" "reflect" - "github.com/sighupio/furyctl/internal/merge" - mapx "github.com/sighupio/furyctl/internal/x/map" + "github.com/sighupio/furyctl/pkg/merge" + mapx "github.com/sighupio/furyctl/pkg/x/map" ) var ( diff --git a/internal/template/config_test.go b/pkg/template/config_test.go similarity index 97% rename from internal/template/config_test.go rename to pkg/template/config_test.go index ed5f32fa5..c0bfa5a2d 100644 --- a/internal/template/config_test.go +++ b/pkg/template/config_test.go @@ -9,8 +9,8 @@ import ( "reflect" "testing" - "github.com/sighupio/furyctl/internal/merge" - "github.com/sighupio/furyctl/internal/template" + "github.com/sighupio/furyctl/pkg/merge" + "github.com/sighupio/furyctl/pkg/template" ) func TestNewConfig(t *testing.T) { diff --git a/internal/template/funcmap.go b/pkg/template/funcmap.go similarity index 100% rename from internal/template/funcmap.go rename to pkg/template/funcmap.go diff --git a/internal/template/funcmap_test.go b/pkg/template/funcmap_test.go similarity index 97% rename from internal/template/funcmap_test.go rename to pkg/template/funcmap_test.go index b96a1cdd2..2e72fa3f0 100644 --- a/internal/template/funcmap_test.go +++ b/pkg/template/funcmap_test.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/stretchr/testify/assert" - "github.com/sighupio/furyctl/internal/template" + "github.com/sighupio/furyctl/pkg/template" ) func TestNewFuncMap(t *testing.T) { diff --git a/internal/template/generator.go b/pkg/template/generator.go similarity index 100% rename from internal/template/generator.go rename to pkg/template/generator.go diff --git a/internal/template/generator_test.go b/pkg/template/generator_test.go similarity index 98% rename from internal/template/generator_test.go rename to pkg/template/generator_test.go index 872c9dce2..e661a60db 100644 --- a/internal/template/generator_test.go +++ b/pkg/template/generator_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" - "github.com/sighupio/furyctl/internal/template" + "github.com/sighupio/furyctl/pkg/template" ) type Meta struct { diff --git a/internal/template/mapper/mapper.go b/pkg/template/mapper/mapper.go similarity index 100% rename from internal/template/mapper/mapper.go rename to pkg/template/mapper/mapper.go diff --git a/internal/template/mapper/mapper_test.go b/pkg/template/mapper/mapper_test.go similarity index 99% rename from internal/template/mapper/mapper_test.go rename to pkg/template/mapper/mapper_test.go index e52e92746..82c597821 100644 --- a/internal/template/mapper/mapper_test.go +++ b/pkg/template/mapper/mapper_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/sighupio/furyctl/internal/template/mapper" + "github.com/sighupio/furyctl/pkg/template/mapper" ) func TestNewMapper(t *testing.T) { diff --git a/internal/template/model.go b/pkg/template/model.go similarity index 97% rename from internal/template/model.go rename to pkg/template/model.go index 2ef2394b5..428a5ba8e 100644 --- a/internal/template/model.go +++ b/pkg/template/model.go @@ -14,9 +14,9 @@ import ( "gopkg.in/yaml.v2" - "github.com/sighupio/furyctl/internal/template/mapper" iox "github.com/sighupio/furyctl/internal/x/io" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + "github.com/sighupio/furyctl/pkg/template/mapper" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) var ( diff --git a/internal/template/model_test.go b/pkg/template/model_test.go similarity index 95% rename from internal/template/model_test.go rename to pkg/template/model_test.go index fddec929d..745d41274 100644 --- a/internal/template/model_test.go +++ b/pkg/template/model_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" - "github.com/sighupio/furyctl/internal/template" + "github.com/sighupio/furyctl/pkg/template" ) func TestNewTemplateModel(t *testing.T) { diff --git a/internal/template/node.go b/pkg/template/node.go similarity index 100% rename from internal/template/node.go rename to pkg/template/node.go diff --git a/internal/template/node_test.go b/pkg/template/node_test.go similarity index 99% rename from internal/template/node_test.go rename to pkg/template/node_test.go index 8c73ae077..fb54adb78 100644 --- a/internal/template/node_test.go +++ b/pkg/template/node_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/assert" - template2 "github.com/sighupio/furyctl/internal/template" + template2 "github.com/sighupio/furyctl/pkg/template" ) func TestNewNode(t *testing.T) { diff --git a/internal/x/map/build.go b/pkg/x/map/build.go similarity index 100% rename from internal/x/map/build.go rename to pkg/x/map/build.go diff --git a/internal/x/map/build_test.go b/pkg/x/map/build_test.go similarity index 97% rename from internal/x/map/build_test.go rename to pkg/x/map/build_test.go index c38264e55..6fd7919e2 100644 --- a/internal/x/map/build_test.go +++ b/pkg/x/map/build_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - mapx "github.com/sighupio/furyctl/internal/x/map" + mapx "github.com/sighupio/furyctl/pkg/x/map" ) func TestFromStruct(t *testing.T) { diff --git a/internal/x/net/client.go b/pkg/x/net/client.go similarity index 100% rename from internal/x/net/client.go rename to pkg/x/net/client.go diff --git a/internal/x/net/client_test.go b/pkg/x/net/client_test.go similarity index 99% rename from internal/x/net/client_test.go rename to pkg/x/net/client_test.go index 896fc16ae..01101b3bb 100644 --- a/internal/x/net/client_test.go +++ b/pkg/x/net/client_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/sighupio/furyctl/internal/test" - netx "github.com/sighupio/furyctl/internal/x/net" + netx "github.com/sighupio/furyctl/pkg/x/net" ) const ( diff --git a/internal/x/net/hashicorp.go b/pkg/x/net/hashicorp.go similarity index 100% rename from internal/x/net/hashicorp.go rename to pkg/x/net/hashicorp.go diff --git a/internal/x/net/hashicorp_test.go b/pkg/x/net/hashicorp_test.go similarity index 96% rename from internal/x/net/hashicorp_test.go rename to pkg/x/net/hashicorp_test.go index 916d7fd76..6a2aaa733 100644 --- a/internal/x/net/hashicorp_test.go +++ b/pkg/x/net/hashicorp_test.go @@ -11,7 +11,7 @@ import ( "path/filepath" "testing" - netx "github.com/sighupio/furyctl/internal/x/net" + netx "github.com/sighupio/furyctl/pkg/x/net" ) func Test_GoGetterClient_Download(t *testing.T) { diff --git a/internal/x/yaml/yaml.go b/pkg/x/yaml/yaml.go similarity index 100% rename from internal/x/yaml/yaml.go rename to pkg/x/yaml/yaml.go diff --git a/internal/x/yaml/yaml_test.go b/pkg/x/yaml/yaml_test.go similarity index 96% rename from internal/x/yaml/yaml_test.go rename to pkg/x/yaml/yaml_test.go index 053a4b3b2..4c4888789 100644 --- a/internal/x/yaml/yaml_test.go +++ b/pkg/x/yaml/yaml_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/assert" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type TestYaml struct { diff --git a/test/expensive/onpremises/furyctl_test.go b/test/expensive/onpremises/furyctl_test.go index 03f8564d2..2c3257840 100644 --- a/test/expensive/onpremises/furyctl_test.go +++ b/test/expensive/onpremises/furyctl_test.go @@ -22,11 +22,11 @@ import ( "github.com/onsi/gomega/gexec" "github.com/sighupio/furyctl/internal/cluster" - "github.com/sighupio/furyctl/internal/template" "github.com/sighupio/furyctl/internal/tool/furyagent" "github.com/sighupio/furyctl/internal/tool/terraform" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" + "github.com/sighupio/furyctl/pkg/template" . "github.com/sighupio/furyctl/test/utils" ) diff --git a/test/utils/testutils.go b/test/utils/testutils.go index 136bd8df6..e2816e149 100644 --- a/test/utils/testutils.go +++ b/test/utils/testutils.go @@ -24,14 +24,14 @@ import ( "github.com/sighupio/furyctl/internal/cluster" "github.com/sighupio/furyctl/internal/dependencies/tools" - "github.com/sighupio/furyctl/internal/distribution" "github.com/sighupio/furyctl/internal/git" "github.com/sighupio/furyctl/internal/tool" execx "github.com/sighupio/furyctl/internal/x/exec" iox "github.com/sighupio/furyctl/internal/x/io" - netx "github.com/sighupio/furyctl/internal/x/net" osx "github.com/sighupio/furyctl/internal/x/os" - yamlx "github.com/sighupio/furyctl/internal/x/yaml" + dist "github.com/sighupio/furyctl/pkg/distribution" + netx "github.com/sighupio/furyctl/pkg/x/net" + yamlx "github.com/sighupio/furyctl/pkg/x/yaml" ) type Conf struct { @@ -148,8 +148,8 @@ func CompileFuryctl(outputPath string) func() { } } -func DownloadFuryDistribution(outDir, furyctlConfPath string) distribution.DownloadResult { - distrodl := distribution.NewCachingDownloader(netx.NewGoGetterClient(), outDir, git.ProtocolSSH, "") +func DownloadFuryDistribution(outDir, furyctlConfPath string) dist.DownloadResult { + distrodl := dist.NewCachingDownloader(netx.NewGoGetterClient(), outDir, git.ProtocolSSH, "") return Must1(distrodl.Download("", furyctlConfPath)) } @@ -169,15 +169,15 @@ func Download(toolName, version string) string { dst := filepath.Join(binPath, toolName, version) if err := client.Download(tfc.SrcPath(), dst); err != nil { - panic(fmt.Errorf("%w '%s': %v", distribution.ErrDownloadingFolder, tfc.SrcPath(), err)) + panic(fmt.Errorf("%w '%s': %v", dist.ErrDownloadingFolder, tfc.SrcPath(), err)) } if err := tfc.Rename(dst); err != nil { - panic(fmt.Errorf("%w '%s': %v", distribution.ErrRenamingFile, tfc.SrcPath(), err)) + panic(fmt.Errorf("%w '%s': %v", dist.ErrRenamingFile, tfc.SrcPath(), err)) } if err := os.Chmod(filepath.Join(dst, toolName), iox.FullPermAccess); err != nil { - panic(fmt.Errorf("%w '%s': %v", distribution.ErrChangingFilePermissions, tfc.SrcPath(), err)) + panic(fmt.Errorf("%w '%s': %v", dist.ErrChangingFilePermissions, tfc.SrcPath(), err)) } return path.Join(dst, toolName)