diff --git a/manifests/metadata.yaml b/manifests/metadata.yaml index be05d7ad1..fd45c77dc 100644 --- a/manifests/metadata.yaml +++ b/manifests/metadata.yaml @@ -1,2 +1,3 @@ phase: path: manifests/phases + docEntryPointPrefix: manifests/site/test-site diff --git a/manifests/phases/phases.yaml b/manifests/phases/phases.yaml index a97c6e329..8b96d2be2 100644 --- a/manifests/phases/phases.yaml +++ b/manifests/phases/phases.yaml @@ -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 diff --git a/pkg/config/manifest.go b/pkg/config/manifest.go index d4576a6d1..e9260a455 100644 --- a/pkg/config/manifest.go +++ b/pkg/config/manifest.go @@ -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 diff --git a/pkg/phase/client.go b/pkg/phase/client.go index ca798ea84..cc7656896 100644 --- a/pkg/phase/client.go +++ b/pkg/phase/client.go @@ -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 diff --git a/pkg/phase/client_test.go b/pkg/phase/client_test.go index 1253dea1c..698aeec24 100644 --- a/pkg/phase/client_test.go +++ b/pkg/phase/client_test.go @@ -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) diff --git a/pkg/phase/helper.go b/pkg/phase/helper.go index da3868fc9..b530fa580 100644 --- a/pkg/phase/helper.go +++ b/pkg/phase/helper.go @@ -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 diff --git a/pkg/phase/helper_test.go b/pkg/phase/helper_test.go index 92f735522..23dd03efd 100644 --- a/pkg/phase/helper_test.go +++ b/pkg/phase/helper_test.go @@ -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) diff --git a/pkg/phase/ifc/helper.go b/pkg/phase/ifc/helper.go index 136c5bbea..b9b15a1df 100644 --- a/pkg/phase/ifc/helper.go +++ b/pkg/phase/ifc/helper.go @@ -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) diff --git a/pkg/phase/testdata/valid_site_with_doc_prefix/metadata.yaml b/pkg/phase/testdata/valid_site_with_doc_prefix/metadata.yaml new file mode 100644 index 000000000..d0f954e1e --- /dev/null +++ b/pkg/phase/testdata/valid_site_with_doc_prefix/metadata.yaml @@ -0,0 +1,3 @@ +phase: + path: "valid_site_with_doc_prefix/phases" + docEntryPointPrefix: "valid_site_with_doc_prefix/phases" \ No newline at end of file diff --git a/pkg/phase/testdata/valid_site_with_doc_prefix/phases/kustomization.yaml b/pkg/phase/testdata/valid_site_with_doc_prefix/phases/kustomization.yaml new file mode 100644 index 000000000..80d1746c1 --- /dev/null +++ b/pkg/phase/testdata/valid_site_with_doc_prefix/phases/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - sample.yaml diff --git a/pkg/phase/testdata/valid_site_with_doc_prefix/phases/sample.yaml b/pkg/phase/testdata/valid_site_with_doc_prefix/phases/sample.yaml new file mode 100644 index 000000000..abe9b0007 --- /dev/null +++ b/pkg/phase/testdata/valid_site_with_doc_prefix/phases/sample.yaml @@ -0,0 +1,6 @@ +apiVersion: airshipit.org/v1alpha1 +kind: Phase +metadata: + name: sample +config: + documentEntryPoint: entrypoint \ No newline at end of file