Add docEntryPointPrefix field to the metadata.yaml

* The phase.docEntryPointPrefix field in the metadata.yaml
   allows you to define a common part of the documentEntryPoint
   for all phases in the phase bundle.

   For example, let metadata.yaml be
   ---
   phase:
     path: manifests/phases
     docEntryPointPrefix: manifests/site/test-site

   and a phase be
   ---
   apiVersion: airshipit.org/v1alpha1
   kind: Phase
   metadata:
     name: initinfra-ephemeral
     clusterName: ephemeral-cluster
   config:
     executorRef:
       apiVersion: airshipit.org/v1alpha1
       kind: KubernetesApply
       name: kubernetes-apply
   documentEntryPoint: ephemeral/initinfra

   Then the documentEntryPoint for executor will be prepended with
   docEntryPointPrefix and the path to the executor bundle will be
   manifests/site/test-site/ephemeral/initinfra

Change-Id: I29ec14378790d95b66c3ff1fe6120bb200f91a50
Relates-To: #356
This commit is contained in:
Vladimir Kozhukalov 2020-10-09 10:53:02 +03:00
parent d812b6c165
commit a608d4c56d
11 changed files with 80 additions and 9 deletions

View File

@ -1,2 +1,3 @@
phase:
path: manifests/phases
docEntryPointPrefix: manifests/site/test-site

View File

@ -7,7 +7,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: ImageConfiguration
name: isogen
documentEntryPoint: manifests/site/test-site/ephemeral/bootstrap
documentEntryPoint: ephemeral/bootstrap
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -19,7 +19,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: manifests/site/test-site/ephemeral/initinfra
documentEntryPoint: ephemeral/initinfra
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -31,7 +31,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: manifests/site/test-site/ephemeral/controlplane
documentEntryPoint: ephemeral/controlplane
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -44,7 +44,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: manifests/site/test-site/target/initinfra
documentEntryPoint: target/initinfra
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -57,7 +57,7 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: manifests/site/test-site/target/workers
documentEntryPoint: target/workers
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
@ -102,4 +102,4 @@ config:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: manifests/site/test-site/target/workload
documentEntryPoint: target/workload

View File

@ -50,10 +50,23 @@ type InventoryMeta struct {
Path string `json:"path,omitempty"`
}
// PhaseMeta holds phase metadata, right now it is only path, but maybe extended further
// path is a kustomize entrypoint against which we will build bundle with phase objects
// PhaseMeta holds phase metadata
type PhaseMeta struct {
// path is a kustomize entrypoint against which we will build bundle with phase objects
Path string `json:"path,omitempty"`
// docEntryPointPrefix is the path prefix for documentEntryPoint field in the phase config
// If it is defined in the manifest metadata then it will be prepended
// to the documentEntryPoint defined in the phase itself. So in this case the full path will be
// targetPath + phaseRepoDir + docEntryPointPrefix + documentEntryPoint
// E.g. let
// targetPath (defined in airship config file) be /tmp
// phaseRepoDir (this is the last part of the repo url given in the airship config file) be reponame
// docEntryPointPrefix (defined in metadata) be foo/bar and
// documentEntryPoint (defined in a phase) be baz/xyz
// then the full path to the document bundle will be /tmp/reponame/foo/bar/baz/xyz
// If docEntryPointPrefix is empty or not given at all, then the full path will be
// targetPath + phaseRepoDir + documentEntryPoint (in our case /tmp/reponame/baz/xyz)
DocEntryPointPrefix string `json:"docEntryPointPrefix,omitempty"`
}
// Manifest functions

View File

@ -155,7 +155,8 @@ func (p *phase) DocumentRoot() (string, error) {
targetPath := p.helper.TargetPath()
phaseRepoDir := p.helper.PhaseRepoDir()
return filepath.Join(targetPath, phaseRepoDir, relativePath), nil
docEntryPointPrefix := p.helper.DocEntryPointPrefix()
return filepath.Join(targetPath, phaseRepoDir, docEntryPointPrefix, relativePath), nil
}
// Details returns description of the phase

View File

@ -174,6 +174,7 @@ func TestDocumentRoot(t *testing.T) {
expectedRoot string
phaseID ifc.ID
expectedErr error
metadataPath string
}{
{
name: "Success entrypoint exists",
@ -185,11 +186,20 @@ func TestDocumentRoot(t *testing.T) {
phaseID: ifc.ID{Name: "some_phase"},
expectedErr: phase.ErrDocumentEntrypointNotDefined{PhaseName: "some_phase"},
},
{
name: "Success entrypoint with doc prefix path",
expectedRoot: "testdata/valid_site_with_doc_prefix/phases/entrypoint",
phaseID: ifc.ID{Name: "sample"},
metadataPath: "valid_site_with_doc_prefix/metadata.yaml",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
cfg := testConfig(t)
if tt.metadataPath != "" {
cfg.Manifests["dummy_manifest"].MetadataPath = tt.metadataPath
}
helper, err := phase.NewHelper(cfg)
require.NoError(t, err)
require.NotNil(t, helper)

View File

@ -207,6 +207,13 @@ func (helper *Helper) PhaseRepoDir() string {
return helper.phaseRepoDir
}
// DocEntryPointPrefix returns the prefix which if not empty is prepended to the
// DocumentEntryPoint field in the phase struct
// so the full entry point is DocEntryPointPrefix + DocumentEntryPoint
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

View File

@ -426,6 +426,33 @@ func TestHelperPhaseRoot(t *testing.T) {
assert.Equal(t, expectedPhaseRoot, helper.PhaseRoot())
}
func TestHelperPhaseRepoDir(t *testing.T) {
cfg := testConfig(t)
cfg.Manifests["dummy_manifest"].Repositories["primary"].URLString = "http://dummy.org/reponame.git"
cfg.Manifests["dummy_manifest"].MetadataPath = "../valid_site/metadata.yaml"
helper, err := phase.NewHelper(cfg)
require.NoError(t, err)
require.NotNil(t, helper)
assert.Equal(t, "reponame", helper.PhaseRepoDir())
}
func TestHelperDocEntryPointPrefix(t *testing.T) {
cfg := testConfig(t)
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)
assert.Equal(t, "valid_site_with_doc_prefix/phases", helper.DocEntryPointPrefix())
}
func TestHelperEmptyDocEntryPointPrefix(t *testing.T) {
cfg := testConfig(t)
helper, err := phase.NewHelper(cfg)
require.NoError(t, err)
require.NotNil(t, helper)
assert.Equal(t, "", helper.DocEntryPointPrefix())
}
func TestHelperWorkdir(t *testing.T) {
helper, err := phase.NewHelper(testConfig(t))
require.NoError(t, err)

View File

@ -24,6 +24,7 @@ import (
type Helper interface {
TargetPath() string
PhaseRepoDir() string
DocEntryPointPrefix() string
WorkDir() (string, error)
Phase(phaseID ID) (*v1alpha1.Phase, error)
Plan() (*v1alpha1.PhasePlan, error)

View File

@ -0,0 +1,3 @@
phase:
path: "valid_site_with_doc_prefix/phases"
docEntryPointPrefix: "valid_site_with_doc_prefix/phases"

View File

@ -0,0 +1,2 @@
resources:
- sample.yaml

View File

@ -0,0 +1,6 @@
apiVersion: airshipit.org/v1alpha1
kind: Phase
metadata:
name: sample
config:
documentEntryPoint: entrypoint