diff --git a/pkg/clusterctl/cmd/command.go b/pkg/clusterctl/cmd/command.go index 0ec1f9534..a3b653f2c 100644 --- a/pkg/clusterctl/cmd/command.go +++ b/pkg/clusterctl/cmd/command.go @@ -94,7 +94,7 @@ func getBundle(conf *config.Config) (document.Bundle, error) { if err != nil { return nil, err } - return document.NewBundleByPath(helper.PhaseRoot()) + return document.NewBundleByPath(helper.PhaseBundleRoot()) } // Move runs clusterctl move diff --git a/pkg/phase/client.go b/pkg/phase/client.go index 3d67b10cf..ea823e513 100644 --- a/pkg/phase/client.go +++ b/pkg/phase/client.go @@ -95,7 +95,7 @@ func (p *phase) Executor() (ifc.Executor, error) { return nil, err } kubeconf := kubeconfig.NewBuilder(). - WithBundle(p.helper.PhaseRoot()). + WithBundle(p.helper.PhaseBundleRoot()). WithClusterMap(cMap). WithClusterName(p.apiObj.ClusterName). WithPath(p.kubeconfig). @@ -172,10 +172,8 @@ func (p *phase) DocumentRoot() (string, error) { } } - targetPath := p.helper.TargetPath() - phaseRepoDir := p.helper.PhaseRepoDir() - docEntryPointPrefix := p.helper.DocEntryPointPrefix() - return filepath.Join(targetPath, phaseRepoDir, docEntryPointPrefix, relativePath), nil + phaseEntryPointBasePath := p.helper.PhaseEntryPointBasePath() + return filepath.Join(phaseEntryPointBasePath, relativePath), nil } // Details returns description of the phase diff --git a/pkg/phase/helper.go b/pkg/phase/helper.go index aca4712ce..fd0bffedf 100644 --- a/pkg/phase/helper.go +++ b/pkg/phase/helper.go @@ -31,11 +31,12 @@ import ( // Helper provides functions built around phase bundle to filter and build documents type Helper struct { - phaseRoot string - inventoryRoot string - targetPath string - phaseRepoDir string - metadata *config.Metadata + phaseBundleRoot string + inventoryRoot string + targetPath string + phaseRepoDir string + phaseEntryPointBasePath string + metadata *config.Metadata } // NewHelper constructs metadata interface based on config @@ -55,14 +56,16 @@ func NewHelper(cfg *config.Config) (ifc.Helper, error) { if err != nil { return nil, err } - helper.phaseRoot = filepath.Join(helper.targetPath, helper.phaseRepoDir, helper.metadata.PhaseMeta.Path) + helper.phaseBundleRoot = filepath.Join(helper.targetPath, helper.phaseRepoDir, helper.metadata.PhaseMeta.Path) helper.inventoryRoot = filepath.Join(helper.targetPath, helper.phaseRepoDir, helper.metadata.Inventory.Path) + helper.phaseEntryPointBasePath = filepath.Join(helper.targetPath, helper.phaseRepoDir, + helper.metadata.PhaseMeta.DocEntryPointPrefix) return helper, nil } // Phase returns a phase APIObject based on phase selector func (helper *Helper) Phase(phaseID ifc.ID) (*v1alpha1.Phase, error) { - bundle, err := document.NewBundleByPath(helper.phaseRoot) + bundle, err := document.NewBundleByPath(helper.phaseBundleRoot) if err != nil { return nil, err } @@ -90,7 +93,7 @@ func (helper *Helper) Phase(phaseID ifc.ID) (*v1alpha1.Phase, error) { // Plan returns plan associated with a manifest func (helper *Helper) Plan() (*v1alpha1.PhasePlan, error) { - bundle, err := document.NewBundleByPath(helper.phaseRoot) + bundle, err := document.NewBundleByPath(helper.phaseBundleRoot) if err != nil { return nil, err } @@ -114,7 +117,7 @@ func (helper *Helper) Plan() (*v1alpha1.PhasePlan, error) { // ListPhases returns all phases associated with manifest func (helper *Helper) ListPhases() ([]*v1alpha1.Phase, error) { - bundle, err := document.NewBundleByPath(helper.phaseRoot) + bundle, err := document.NewBundleByPath(helper.phaseBundleRoot) if err != nil { return nil, err } @@ -143,7 +146,7 @@ func (helper *Helper) ListPhases() ([]*v1alpha1.Phase, error) { // ClusterMapAPIobj associated with the the manifest func (helper *Helper) ClusterMapAPIobj() (*v1alpha1.ClusterMap, error) { - bundle, err := document.NewBundleByPath(helper.phaseRoot) + bundle, err := document.NewBundleByPath(helper.phaseBundleRoot) if err != nil { return nil, err } @@ -176,7 +179,7 @@ func (helper *Helper) ClusterMap() (clustermap.ClusterMap, error) { // ExecutorDoc returns executor document associated with phase func (helper *Helper) ExecutorDoc(phaseID ifc.ID) (document.Document, error) { - bundle, err := document.NewBundleByPath(helper.phaseRoot) + bundle, err := document.NewBundleByPath(helper.phaseBundleRoot) if err != nil { return nil, err } @@ -218,9 +221,14 @@ func (helper *Helper) DocEntryPointPrefix() string { return helper.metadata.PhaseMeta.DocEntryPointPrefix } -// PhaseRoot returns path to document root with phase documents -func (helper *Helper) PhaseRoot() string { - return helper.phaseRoot +// PhaseBundleRoot returns path to document root with phase documents +func (helper *Helper) PhaseBundleRoot() string { + return helper.phaseBundleRoot +} + +// PhaseEntryPointBasePath returns path to current site directory +func (helper *Helper) PhaseEntryPointBasePath() string { + return helper.phaseEntryPointBasePath } // WorkDir return manifest root diff --git a/pkg/phase/helper_test.go b/pkg/phase/helper_test.go index c5d9212b3..b5027f04a 100644 --- a/pkg/phase/helper_test.go +++ b/pkg/phase/helper_test.go @@ -426,12 +426,24 @@ func TestHelperTargetPath(t *testing.T) { assert.Equal(t, "testdata", helper.TargetPath()) } -func TestHelperPhaseRoot(t *testing.T) { +func TestHelperPhaseBundleRoot(t *testing.T) { helper, err := phase.NewHelper(testConfig(t)) require.NoError(t, err) require.NotNil(t, helper) - expectedPhaseRoot := filepath.Join("testdata", "valid_site", "phases") - assert.Equal(t, expectedPhaseRoot, helper.PhaseRoot()) + expectedPhaseBundleRoot := filepath.Join("testdata", "valid_site", "phases") + assert.Equal(t, expectedPhaseBundleRoot, helper.PhaseBundleRoot()) +} + +func TestHelperPhaseEntryPointBasePath(t *testing.T) { + cfg := testConfig(t) + cfg.Manifests["dummy_manifest"].TargetPath = "testdata" + cfg.Manifests["dummy_manifest"].Repositories["primary"].URLString = "http://dummy.org/reponame.git" + cfg.Manifests["dummy_manifest"].MetadataPath = "../valid_site_with_doc_prefix/metadata.yaml" + helper, err := phase.NewHelper(cfg) + require.NoError(t, err) + require.NotNil(t, helper) + expectedPhaseEntryPointBasePath := filepath.Join("testdata", "reponame", "valid_site_with_doc_prefix", "phases") + assert.Equal(t, expectedPhaseEntryPointBasePath, helper.PhaseEntryPointBasePath()) } func TestHelperPhaseRepoDir(t *testing.T) { diff --git a/pkg/phase/ifc/helper.go b/pkg/phase/ifc/helper.go index b9b15a1df..8431048c6 100644 --- a/pkg/phase/ifc/helper.go +++ b/pkg/phase/ifc/helper.go @@ -32,5 +32,6 @@ type Helper interface { ClusterMapAPIobj() (*v1alpha1.ClusterMap, error) ClusterMap() (clustermap.ClusterMap, error) ExecutorDoc(phaseID ID) (document.Document, error) - PhaseRoot() string + PhaseBundleRoot() string + PhaseEntryPointBasePath() string }