Merge "Add docEntryPointPrefix field to the metadata.yaml"
This commit is contained in:
commit
16c349526f
@ -1,2 +1,3 @@
|
|||||||
phase:
|
phase:
|
||||||
path: manifests/phases
|
path: manifests/phases
|
||||||
|
docEntryPointPrefix: manifests/site/test-site
|
||||||
|
@ -7,7 +7,7 @@ config:
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: ImageConfiguration
|
kind: ImageConfiguration
|
||||||
name: isogen
|
name: isogen
|
||||||
documentEntryPoint: manifests/site/test-site/ephemeral/bootstrap
|
documentEntryPoint: ephemeral/bootstrap
|
||||||
---
|
---
|
||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: Phase
|
kind: Phase
|
||||||
@ -19,7 +19,7 @@ config:
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: KubernetesApply
|
kind: KubernetesApply
|
||||||
name: kubernetes-apply
|
name: kubernetes-apply
|
||||||
documentEntryPoint: manifests/site/test-site/ephemeral/initinfra
|
documentEntryPoint: ephemeral/initinfra
|
||||||
---
|
---
|
||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: Phase
|
kind: Phase
|
||||||
@ -31,7 +31,7 @@ config:
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: KubernetesApply
|
kind: KubernetesApply
|
||||||
name: kubernetes-apply
|
name: kubernetes-apply
|
||||||
documentEntryPoint: manifests/site/test-site/ephemeral/controlplane
|
documentEntryPoint: ephemeral/controlplane
|
||||||
---
|
---
|
||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: Phase
|
kind: Phase
|
||||||
@ -44,7 +44,7 @@ config:
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: KubernetesApply
|
kind: KubernetesApply
|
||||||
name: kubernetes-apply
|
name: kubernetes-apply
|
||||||
documentEntryPoint: manifests/site/test-site/target/initinfra
|
documentEntryPoint: target/initinfra
|
||||||
---
|
---
|
||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: Phase
|
kind: Phase
|
||||||
@ -57,7 +57,7 @@ config:
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: KubernetesApply
|
kind: KubernetesApply
|
||||||
name: kubernetes-apply
|
name: kubernetes-apply
|
||||||
documentEntryPoint: manifests/site/test-site/target/workers
|
documentEntryPoint: target/workers
|
||||||
---
|
---
|
||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: Phase
|
kind: Phase
|
||||||
@ -102,4 +102,4 @@ config:
|
|||||||
apiVersion: airshipit.org/v1alpha1
|
apiVersion: airshipit.org/v1alpha1
|
||||||
kind: KubernetesApply
|
kind: KubernetesApply
|
||||||
name: kubernetes-apply
|
name: kubernetes-apply
|
||||||
documentEntryPoint: manifests/site/test-site/target/workload
|
documentEntryPoint: target/workload
|
||||||
|
@ -50,10 +50,23 @@ type InventoryMeta struct {
|
|||||||
Path string `json:"path,omitempty"`
|
Path string `json:"path,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PhaseMeta holds phase metadata, right now it is only path, but maybe extended further
|
// PhaseMeta holds phase metadata
|
||||||
// path is a kustomize entrypoint against which we will build bundle with phase objects
|
|
||||||
type PhaseMeta struct {
|
type PhaseMeta struct {
|
||||||
|
// path is a kustomize entrypoint against which we will build bundle with phase objects
|
||||||
Path string `json:"path,omitempty"`
|
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
|
// Manifest functions
|
||||||
|
@ -155,7 +155,8 @@ func (p *phase) DocumentRoot() (string, error) {
|
|||||||
|
|
||||||
targetPath := p.helper.TargetPath()
|
targetPath := p.helper.TargetPath()
|
||||||
phaseRepoDir := p.helper.PhaseRepoDir()
|
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
|
// Details returns description of the phase
|
||||||
|
@ -174,6 +174,7 @@ func TestDocumentRoot(t *testing.T) {
|
|||||||
expectedRoot string
|
expectedRoot string
|
||||||
phaseID ifc.ID
|
phaseID ifc.ID
|
||||||
expectedErr error
|
expectedErr error
|
||||||
|
metadataPath string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Success entrypoint exists",
|
name: "Success entrypoint exists",
|
||||||
@ -185,11 +186,20 @@ func TestDocumentRoot(t *testing.T) {
|
|||||||
phaseID: ifc.ID{Name: "some_phase"},
|
phaseID: ifc.ID{Name: "some_phase"},
|
||||||
expectedErr: phase.ErrDocumentEntrypointNotDefined{PhaseName: "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 {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
cfg := testConfig(t)
|
cfg := testConfig(t)
|
||||||
|
if tt.metadataPath != "" {
|
||||||
|
cfg.Manifests["dummy_manifest"].MetadataPath = tt.metadataPath
|
||||||
|
}
|
||||||
helper, err := phase.NewHelper(cfg)
|
helper, err := phase.NewHelper(cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, helper)
|
require.NotNil(t, helper)
|
||||||
|
@ -207,6 +207,13 @@ func (helper *Helper) PhaseRepoDir() string {
|
|||||||
return helper.phaseRepoDir
|
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
|
// PhaseRoot returns path to document root with phase documents
|
||||||
func (helper *Helper) PhaseRoot() string {
|
func (helper *Helper) PhaseRoot() string {
|
||||||
return helper.phaseRoot
|
return helper.phaseRoot
|
||||||
|
@ -426,6 +426,33 @@ func TestHelperPhaseRoot(t *testing.T) {
|
|||||||
assert.Equal(t, expectedPhaseRoot, helper.PhaseRoot())
|
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) {
|
func TestHelperWorkdir(t *testing.T) {
|
||||||
helper, err := phase.NewHelper(testConfig(t))
|
helper, err := phase.NewHelper(testConfig(t))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
type Helper interface {
|
type Helper interface {
|
||||||
TargetPath() string
|
TargetPath() string
|
||||||
PhaseRepoDir() string
|
PhaseRepoDir() string
|
||||||
|
DocEntryPointPrefix() string
|
||||||
WorkDir() (string, error)
|
WorkDir() (string, error)
|
||||||
Phase(phaseID ID) (*v1alpha1.Phase, error)
|
Phase(phaseID ID) (*v1alpha1.Phase, error)
|
||||||
Plan() (*v1alpha1.PhasePlan, error)
|
Plan() (*v1alpha1.PhasePlan, error)
|
||||||
|
3
pkg/phase/testdata/valid_site_with_doc_prefix/metadata.yaml
vendored
Normal file
3
pkg/phase/testdata/valid_site_with_doc_prefix/metadata.yaml
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
phase:
|
||||||
|
path: "valid_site_with_doc_prefix/phases"
|
||||||
|
docEntryPointPrefix: "valid_site_with_doc_prefix/phases"
|
2
pkg/phase/testdata/valid_site_with_doc_prefix/phases/kustomization.yaml
vendored
Normal file
2
pkg/phase/testdata/valid_site_with_doc_prefix/phases/kustomization.yaml
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
resources:
|
||||||
|
- sample.yaml
|
6
pkg/phase/testdata/valid_site_with_doc_prefix/phases/sample.yaml
vendored
Normal file
6
pkg/phase/testdata/valid_site_with_doc_prefix/phases/sample.yaml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
apiVersion: airshipit.org/v1alpha1
|
||||||
|
kind: Phase
|
||||||
|
metadata:
|
||||||
|
name: sample
|
||||||
|
config:
|
||||||
|
documentEntryPoint: entrypoint
|
Loading…
x
Reference in New Issue
Block a user