Merge "Add PhaseEntryPointBasePath to phase helper"

This commit is contained in:
Zuul 2021-01-12 19:40:38 +00:00 committed by Gerrit Code Review
commit 932d92664e
5 changed files with 43 additions and 24 deletions

View File

@ -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

View File

@ -98,7 +98,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).
@ -175,10 +175,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

View File

@ -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

View File

@ -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) {

View File

@ -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
}