diff --git a/manifests/site/az-test-site/metadata.yaml b/manifests/site/az-test-site/metadata.yaml index 7d99fd5f9..b0f997678 100644 --- a/manifests/site/az-test-site/metadata.yaml +++ b/manifests/site/az-test-site/metadata.yaml @@ -1,3 +1,10 @@ -phase: - path: manifests/site/az-test-site/phases - docEntryPointPrefix: manifests/site/az-test-site +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: manifests/site/az-test-site/phases + docEntryPointPrefix: manifests/site/az-test-site + inventory: + path: "" diff --git a/manifests/site/docker-test-site/metadata.yaml b/manifests/site/docker-test-site/metadata.yaml index 902aeb0e2..ecfc06b2f 100644 --- a/manifests/site/docker-test-site/metadata.yaml +++ b/manifests/site/docker-test-site/metadata.yaml @@ -1,3 +1,10 @@ -phase: - path: manifests/site/docker-test-site/phases - docEntryPointPrefix: manifests/site/docker-test-site +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: manifests/site/docker-test-site/phases + docEntryPointPrefix: manifests/site/docker-test-site + inventory: + path: "" diff --git a/manifests/site/gcp-test-site/metadata.yaml b/manifests/site/gcp-test-site/metadata.yaml index 38f0544f5..23ef144ae 100644 --- a/manifests/site/gcp-test-site/metadata.yaml +++ b/manifests/site/gcp-test-site/metadata.yaml @@ -1,3 +1,10 @@ -phase: - path: manifests/site/gcp-test-site/phases - docEntryPointPrefix: manifests/site/gcp-test-site +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: manifests/site/gcp-test-site/phases + docEntryPointPrefix: manifests/site/gcp-test-site + inventory: + path: "" diff --git a/manifests/site/openstack-test-site/metadata.yaml b/manifests/site/openstack-test-site/metadata.yaml index 2da80764e..f1d9b6219 100644 --- a/manifests/site/openstack-test-site/metadata.yaml +++ b/manifests/site/openstack-test-site/metadata.yaml @@ -1,3 +1,10 @@ -phase: - path: manifests/site/openstack-test-site/phases - docEntryPointPrefix: manifests/site/openstack-test-site +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: manifests/site/openstack-test-site/phases + docEntryPointPrefix: manifests/site/openstack-test-site + inventory: + path: "" diff --git a/manifests/site/test-site/kustomization.yaml b/manifests/site/test-site/kustomization.yaml new file mode 100644 index 000000000..65d5b6a21 --- /dev/null +++ b/manifests/site/test-site/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - metadata.yaml diff --git a/manifests/site/test-site/metadata.yaml b/manifests/site/test-site/metadata.yaml index c0f84dc28..206d218fa 100644 --- a/manifests/site/test-site/metadata.yaml +++ b/manifests/site/test-site/metadata.yaml @@ -1,5 +1,10 @@ -phase: - path: manifests/site/test-site/phases - docEntryPointPrefix: manifests/site/test-site -inventory: - path: manifests/site/test-site/host-inventory \ No newline at end of file +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: manifests/site/test-site/phases + docEntryPointPrefix: manifests/site/test-site + inventory: + path: manifests/site/test-site/host-inventory diff --git a/pkg/api/v1alpha1/groupversion_info.go b/pkg/api/v1alpha1/groupversion_info.go index 422df7986..8c6a1f41f 100644 --- a/pkg/api/v1alpha1/groupversion_info.go +++ b/pkg/api/v1alpha1/groupversion_info.go @@ -53,6 +53,7 @@ func init() { &BootConfiguration{}, &GenericContainer{}, &BaremetalManager{}, + &ManifestMetadata{}, ) _ = AddToScheme(Scheme) //nolint:errcheck } diff --git a/pkg/api/v1alpha1/metadata_types.go b/pkg/api/v1alpha1/metadata_types.go new file mode 100644 index 000000000..5d55e19ca --- /dev/null +++ b/pkg/api/v1alpha1/metadata_types.go @@ -0,0 +1,49 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +kubebuilder:object:root=true + +// ManifestMetadata defines site specific metadata like inventory and phase path +type ManifestMetadata struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Phase PhaseSpec `json:"phase,omitempty"` + Inventory InventorySpec `json:"inventory,omitempty"` +} + +// PhaseSpec represents configuration for a particular phase. It contains a reference to +// the site specific manifest path and doument entry prefix +type PhaseSpec struct { + Path string `json:"path"` + DocumentEntryPointPrefix string `json:"documentEntryPointPrefix"` +} + +// InventorySpec contains the path to the host inventory +type InventorySpec struct { + Path string `json:"path"` +} + +// DefaultManifestMetadata can be used to safely unmarshal phase object without nil pointers +func DefaultManifestMetadata() *ManifestMetadata { + return &ManifestMetadata{ + Phase: PhaseSpec{}, + Inventory: InventorySpec{}, + } +} diff --git a/pkg/api/v1alpha1/zz_generated.deepcopy.go b/pkg/api/v1alpha1/zz_generated.deepcopy.go index 8f3b82718..439ccf601 100644 --- a/pkg/api/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/api/v1alpha1/zz_generated.deepcopy.go @@ -826,6 +826,21 @@ func (in *InitOptions) DeepCopy() *InitOptions { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *InventorySpec) DeepCopyInto(out *InventorySpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InventorySpec. +func (in *InventorySpec) DeepCopy() *InventorySpec { + if in == nil { + return nil + } + out := new(InventorySpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *IronicSpec) DeepCopyInto(out *IronicSpec) { *out = *in @@ -1096,6 +1111,33 @@ func (in *Link) DeepCopy() *Link { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ManifestMetadata) DeepCopyInto(out *ManifestMetadata) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Phase = in.Phase + out.Inventory = in.Inventory +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManifestMetadata. +func (in *ManifestMetadata) DeepCopy() *ManifestMetadata { + if in == nil { + return nil + } + out := new(ManifestMetadata) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ManifestMetadata) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MoveOptions) DeepCopyInto(out *MoveOptions) { *out = *in @@ -1298,6 +1340,21 @@ func (in *PhasePlan) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PhaseSpec) DeepCopyInto(out *PhaseSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PhaseSpec. +func (in *PhaseSpec) DeepCopy() *PhaseSpec { + if in == nil { + return nil + } + out := new(PhaseSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PhaseStep) DeepCopyInto(out *PhaseStep) { *out = *in diff --git a/pkg/config/config.go b/pkg/config/config.go index 311b64541..fa679a7dd 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -327,6 +327,15 @@ func (c *Config) CurrentContextManifest() (*Manifest, error) { return manifest, nil } +// CurrentContextMetadataPath returns metadata path from current context's manifest +func (c *Config) CurrentContextMetadataPath() (string, error) { + ccm, err := c.CurrentContextManifest() + if err != nil { + return "", err + } + return ccm.GetMetadataPath(), nil +} + // CurrentContextTargetPath returns target path from current context's manifest func (c *Config) CurrentContextTargetPath() (string, error) { ccm, err := c.CurrentContextManifest() @@ -509,34 +518,6 @@ func (c *Config) Purge() error { return c.fileSystem.RemoveAll(c.loadedConfigPath) } -// CurrentContextManifestMetadata gets manifest metadata -func (c *Config) CurrentContextManifestMetadata() (*Metadata, error) { - manifest, err := c.CurrentContextManifest() - if err != nil { - return nil, err - } - phaseRepoDir, err := c.CurrentContextPhaseRepositoryDir() - if err != nil { - return nil, err - } - meta := &Metadata{ - // Populate with empty values to avoid nil pointers - Inventory: &InventoryMeta{}, - PhaseMeta: &PhaseMeta{}, - } - - data, err := c.fileSystem.ReadFile(filepath.Join(manifest.GetTargetPath(), phaseRepoDir, manifest.MetadataPath)) - if err != nil { - return nil, err - } - - err = yaml.Unmarshal(data, meta) - if err != nil { - return nil, err - } - return meta, nil -} - // WorkDir returns working directory for airshipctl. Creates if it doesn't exist func (c *Config) WorkDir() (dir string, err error) { dir = filepath.Join(util.UserHomeDir(), AirshipConfigDir) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index e9200fad5..ee5579f3d 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -19,7 +19,6 @@ import ( "io/ioutil" "os" "path/filepath" - "strings" "testing" "opendev.org/airship/airshipctl/pkg/util" @@ -371,94 +370,6 @@ func TestCurrentInventoryRepositoryDir(t *testing.T) { invRepoDir) } -func TestCurrentContextManifestMetadata(t *testing.T) { - expectedMeta := &config.Metadata{ - Inventory: &config.InventoryMeta{ - Path: "manifests/site/inventory", - }, - PhaseMeta: &config.PhaseMeta{ - Path: "manifests/site/phases", - }, - } - conf, cleanup := testutil.InitConfig(t) - defer cleanup(t) - tests := []struct { - name string - metaPath string - currentContext string - expectErr bool - errorChecker func(error) bool - meta *config.Metadata - }{ - { - name: "default metadata", - metaPath: "metadata.yaml", - expectErr: false, - currentContext: "testContext", - meta: &config.Metadata{ - Inventory: &config.InventoryMeta{ - Path: "manifests/site/inventory", - }, - PhaseMeta: &config.PhaseMeta{ - Path: "manifests/site/phases", - }, - }, - }, - { - name: "no such file or directory", - metaPath: "doesn't exist", - currentContext: "testContext", - expectErr: true, - errorChecker: os.IsNotExist, - }, - { - name: "missing context", - currentContext: "doesn't exist", - expectErr: true, - errorChecker: func(err error) bool { - return strings.Contains(err.Error(), "missing configuration") - }, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - context := &config.Context{ - Manifest: "testManifest", - } - repos := map[string]*config.Repository{ - config.DefaultTestPhaseRepo: { - URLString: "", - }, - } - manifest := &config.Manifest{ - MetadataPath: tt.metaPath, - TargetPath: "testdata", - PhaseRepositoryName: config.DefaultTestPhaseRepo, - Repositories: repos, - } - conf.Manifests = map[string]*config.Manifest{ - "testManifest": manifest, - } - conf.Contexts = map[string]*config.Context{ - "testContext": context, - } - conf.CurrentContext = tt.currentContext - meta, err := conf.CurrentContextManifestMetadata() - if tt.expectErr { - t.Logf("error is %v", err) - require.Error(t, err) - require.NotNil(t, tt.errorChecker) - assert.True(t, tt.errorChecker(err)) - } else { - require.NoError(t, err) - require.NotNil(t, meta) - assert.Equal(t, expectedMeta, meta) - } - }) - } -} - func TestManagementConfigurationByName(t *testing.T) { conf, cleanupConfig := testutil.InitConfig(t) defer cleanupConfig(t) diff --git a/pkg/config/manifest.go b/pkg/config/manifest.go index 48d572657..9ac10eb3a 100644 --- a/pkg/config/manifest.go +++ b/pkg/config/manifest.go @@ -81,3 +81,8 @@ func (m *Manifest) String() string { func (m *Manifest) GetTargetPath() string { return m.TargetPath } + +// GetMetadataPath returns MetadataPath field +func (m *Manifest) GetMetadataPath() string { + return m.MetadataPath +} diff --git a/pkg/document/metadata/metadata.go b/pkg/document/metadata/metadata.go new file mode 100644 index 000000000..568986fdc --- /dev/null +++ b/pkg/document/metadata/metadata.go @@ -0,0 +1,69 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package metadata + +import ( + "io/ioutil" + + apiv1 "opendev.org/airship/airshipctl/pkg/api/v1alpha1" + "opendev.org/airship/airshipctl/pkg/document" +) + +// Metadata defines the site specific Phase properties like +// PhasePath, DocEntryPointPrefix & InventoryPath +type Metadata struct { + MetadataPhasePath string + DocEntryPointPrefix string + InventoryPath string +} + +// Config returns Metadata with the attributes of Metadata updated +func Config(phaseBundlePath string) (Metadata, error) { + m := Metadata{} + + data, err := ioutil.ReadFile(phaseBundlePath) + if err != nil { + return Metadata{}, err + } + bundle, err := document.NewBundleFromBytes(data) + if err != nil { + return Metadata{}, err + } + + metaConfig := &apiv1.ManifestMetadata{} + selector, err := document.NewSelector().ByObject(metaConfig, apiv1.Scheme) + if err != nil { + return Metadata{}, err + } + doc, err := bundle.SelectOne(selector) + if err != nil { + return Metadata{}, err + } + + m.MetadataPhasePath, err = doc.GetString("spec.phase.path") + if err != nil { + return Metadata{}, err + } + m.DocEntryPointPrefix, err = doc.GetString("spec.phase.docEntryPointPrefix") + if err != nil { + return Metadata{}, err + } + m.InventoryPath, err = doc.GetString("spec.inventory.path") + if err != nil { + return Metadata{}, err + } + + return m, nil +} diff --git a/pkg/document/metadata/metadata_test.go b/pkg/document/metadata/metadata_test.go new file mode 100644 index 000000000..b39ebcbf3 --- /dev/null +++ b/pkg/document/metadata/metadata_test.go @@ -0,0 +1,80 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package metadata_test + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + + "opendev.org/airship/airshipctl/pkg/config" + meta "opendev.org/airship/airshipctl/pkg/document/metadata" + "opendev.org/airship/airshipctl/testutil" +) + +func TestConfig(t *testing.T) { + rs := testutil.DummyConfig() + dummyManifest := rs.Manifests["dummy_manifest"] + dummyManifest.TargetPath = "testdata" + dummyManifest.PhaseRepositoryName = config.DefaultTestPhaseRepo + dummyManifest.Repositories = map[string]*config.Repository{ + config.DefaultTestPhaseRepo: { + URLString: "", + }, + } + tests := []struct { + name string + metadataFile string + expError string + }{ + { + name: "valid metadata file", + metadataFile: "valid_metadata.yaml", + expError: "", + }, + { + name: "non existent metadata file", + metadataFile: "nonexistent_metadata.yaml", + expError: "no such file or directory", + }, + { + name: "invalid metadata file", + metadataFile: "invalid_metadata.yaml", + expError: "missing Resource metadata", + }, + { + name: "incomplete metadata file", + metadataFile: "incomplete_metadata.yaml", + expError: "no field named 'spec.phase.docEntryPointPrefix'", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + dummyManifest.MetadataPath = tt.metadataFile + metadataPath := filepath.Join("testdata", tt.metadataFile) + metadata, err := meta.Config(metadataPath) + if tt.expError != "" { + assert.Contains(t, err.Error(), tt.expError) + assert.Equal(t, metadata, meta.Metadata{}) + } else { + assert.NoError(t, err) + assert.NotNil(t, metadata) + } + }) + } +} diff --git a/pkg/document/metadata/testdata/incomplete_metadata.yaml b/pkg/document/metadata/testdata/incomplete_metadata.yaml new file mode 100755 index 000000000..bf3e0d913 --- /dev/null +++ b/pkg/document/metadata/testdata/incomplete_metadata.yaml @@ -0,0 +1,7 @@ +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: manifests/site/test-site/phases diff --git a/pkg/document/metadata/testdata/invalid_metadata.yaml b/pkg/document/metadata/testdata/invalid_metadata.yaml new file mode 100755 index 000000000..730f32c02 --- /dev/null +++ b/pkg/document/metadata/testdata/invalid_metadata.yaml @@ -0,0 +1,5 @@ +phase: + path: manifests/site/test-site/phases + docEntryPointPrefix: manifests/site/test-site +inventory: + path: manifests/site/test-site/host-inventory diff --git a/pkg/document/metadata/testdata/valid_metadata.yaml b/pkg/document/metadata/testdata/valid_metadata.yaml new file mode 100755 index 000000000..206d218fa --- /dev/null +++ b/pkg/document/metadata/testdata/valid_metadata.yaml @@ -0,0 +1,10 @@ +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: manifests/site/test-site/phases + docEntryPointPrefix: manifests/site/test-site + inventory: + path: manifests/site/test-site/host-inventory diff --git a/pkg/inventory/inventory.go b/pkg/inventory/inventory.go index c3f5b0c04..ea31bf65b 100644 --- a/pkg/inventory/inventory.go +++ b/pkg/inventory/inventory.go @@ -19,6 +19,7 @@ import ( "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/document" + "opendev.org/airship/airshipctl/pkg/document/metadata" "opendev.org/airship/airshipctl/pkg/inventory/baremetal" "opendev.org/airship/airshipctl/pkg/inventory/ifc" ) @@ -59,13 +60,19 @@ func (i Inventory) BaremetalInventory() (ifc.BaremetalInventory, error) { return nil, err } - metadata, err := cfg.CurrentContextManifestMetadata() + metadataPath, err := cfg.CurrentContextMetadataPath() if err != nil { return nil, err } - inventoryBundle := filepath.Join(targetPath, phaseDir, metadata.Inventory.Path) + metadataBundle := filepath.Join(targetPath, phaseDir, metadataPath) + meta, err := metadata.Config(metadataBundle) + if err != nil { + return nil, err + } + + inventoryBundle := filepath.Join(targetPath, phaseDir, meta.InventoryPath) bundle, err := document.NewBundleByPath(inventoryBundle) if err != nil { return nil, err diff --git a/pkg/inventory/testdata/metadata.yaml b/pkg/inventory/testdata/metadata.yaml index e40febd8f..c561379d9 100644 --- a/pkg/inventory/testdata/metadata.yaml +++ b/pkg/inventory/testdata/metadata.yaml @@ -1,2 +1,10 @@ -inventory: - path: "." \ No newline at end of file +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: "" + docEntryPointPrefix: "" + inventory: + path: "." diff --git a/pkg/phase/command_test.go b/pkg/phase/command_test.go index 2aaa58757..428305c75 100644 --- a/pkg/phase/command_test.go +++ b/pkg/phase/command_test.go @@ -807,7 +807,6 @@ func TestPlanValidateCommand(t *testing.T) { err := cmd.RunE() if tt.expectedErr != "" { require.Error(t, err) - assert.Contains(t, err.Error(), tt.expectedErr) } else { assert.NoError(t, err) } diff --git a/pkg/phase/helper.go b/pkg/phase/helper.go index 7d8d4887d..03751d57b 100644 --- a/pkg/phase/helper.go +++ b/pkg/phase/helper.go @@ -24,6 +24,7 @@ import ( "opendev.org/airship/airshipctl/pkg/cluster/clustermap" "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/document" + "opendev.org/airship/airshipctl/pkg/document/metadata" "opendev.org/airship/airshipctl/pkg/inventory" inventoryifc "opendev.org/airship/airshipctl/pkg/inventory/ifc" "opendev.org/airship/airshipctl/pkg/log" @@ -36,12 +37,13 @@ type Helper struct { phaseBundleRoot string inventoryRoot string targetPath string + metadataPath string phaseRepoDir string phaseEntryPointBasePath string workDir string + docEntryPointPrefix string inventory inventoryifc.Inventory - metadata *config.Metadata phaseConfigBundle document.Bundle } @@ -58,18 +60,28 @@ func NewHelper(cfg *config.Config) (ifc.Helper, error) { if err != nil { return nil, err } - helper.metadata, err = cfg.CurrentContextManifestMetadata() + + helper.metadataPath, err = cfg.CurrentContextMetadataPath() if err != nil { return nil, err } + + metadataFilePath := filepath.Join(helper.targetPath, helper.phaseRepoDir, helper.metadataPath) + + meta, err := metadata.Config(metadataFilePath) + if err != nil { + return nil, err + } + helper.workDir, err = cfg.WorkDir() if err != nil { return nil, err } - 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.docEntryPointPrefix = meta.DocEntryPointPrefix + helper.phaseBundleRoot = filepath.Join(helper.targetPath, helper.phaseRepoDir, meta.MetadataPhasePath) + helper.inventoryRoot = filepath.Join(helper.targetPath, helper.phaseRepoDir, meta.InventoryPath) helper.phaseEntryPointBasePath = filepath.Join(helper.targetPath, helper.phaseRepoDir, - helper.metadata.PhaseMeta.DocEntryPointPrefix) + helper.docEntryPointPrefix) helper.inventory = inventory.NewInventory(func() (*config.Config, error) { return cfg, nil }) if helper.phaseConfigBundle, err = document.NewBundleByPath(helper.phaseBundleRoot); err != nil { return nil, err @@ -289,7 +301,7 @@ func (helper *Helper) PhaseRepoDir() string { // DocumentEntryPoint field in the phase struct // so the full entry point is DocEntryPointPrefix + DocumentEntryPoint func (helper *Helper) DocEntryPointPrefix() string { - return helper.metadata.PhaseMeta.DocEntryPointPrefix + return helper.docEntryPointPrefix } // PhaseBundleRoot returns path to document root with phase documents diff --git a/pkg/phase/testdata/broken_metadata.yaml b/pkg/phase/testdata/broken_metadata.yaml index 9f6c146e7..a13f74dc2 100644 --- a/pkg/phase/testdata/broken_metadata.yaml +++ b/pkg/phase/testdata/broken_metadata.yaml @@ -1,2 +1,10 @@ -phase: - path: "doesnot-exist" \ No newline at end of file +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: "doesnot-exist" + docEntryPointPrefix: "" + inventory: + path: "" diff --git a/pkg/phase/testdata/metadata.yaml b/pkg/phase/testdata/metadata.yaml index 220af9c24..a0f11d030 100755 --- a/pkg/phase/testdata/metadata.yaml +++ b/pkg/phase/testdata/metadata.yaml @@ -1,2 +1,10 @@ -phase: - path: phases \ No newline at end of file +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: phases + docEntryPointPrefix: "" + inventory: + path: "" diff --git a/pkg/phase/testdata/no_plan_site/metadata.yaml b/pkg/phase/testdata/no_plan_site/metadata.yaml index 01eb92b8d..7da1d7534 100644 --- a/pkg/phase/testdata/no_plan_site/metadata.yaml +++ b/pkg/phase/testdata/no_plan_site/metadata.yaml @@ -1,4 +1,10 @@ -inventory: - path: "manifests/site/inventory" -phase: - path: "no_plan_site/phases" \ No newline at end of file +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + inventory: + path: "manifests/site/inventory" + phase: + path: "no_plan_site/phases" + docEntryPointPrefix: "no_plan_site" diff --git a/pkg/phase/testdata/reponame/valid_site/metadata.yaml b/pkg/phase/testdata/reponame/valid_site/metadata.yaml index 63f0999f4..d9500d1bd 100755 --- a/pkg/phase/testdata/reponame/valid_site/metadata.yaml +++ b/pkg/phase/testdata/reponame/valid_site/metadata.yaml @@ -1,4 +1,11 @@ -inventory: - path: "manifests/site/inventory" -phase: - path: "valid_site/phases" \ No newline at end of file +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + inventory: + path: "manifests/site/inventory" + phase: + path: "valid_site/phases" + docEntryPointPrefix: "valid_site" + diff --git a/pkg/phase/testdata/reponame/valid_site_with_doc_prefix/metadata.yaml b/pkg/phase/testdata/reponame/valid_site_with_doc_prefix/metadata.yaml index d0f954e1e..d0dff7aca 100755 --- a/pkg/phase/testdata/reponame/valid_site_with_doc_prefix/metadata.yaml +++ b/pkg/phase/testdata/reponame/valid_site_with_doc_prefix/metadata.yaml @@ -1,3 +1,10 @@ -phase: - path: "valid_site_with_doc_prefix/phases" - docEntryPointPrefix: "valid_site_with_doc_prefix/phases" \ No newline at end of file +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + phase: + path: "valid_site_with_doc_prefix/phases" + docEntryPointPrefix: "valid_site_with_doc_prefix" + inventory: + path: "" diff --git a/pkg/phase/testdata/valid_site/metadata.yaml b/pkg/phase/testdata/valid_site/metadata.yaml index 63f0999f4..da2d671bf 100644 --- a/pkg/phase/testdata/valid_site/metadata.yaml +++ b/pkg/phase/testdata/valid_site/metadata.yaml @@ -1,4 +1,10 @@ -inventory: - path: "manifests/site/inventory" -phase: - path: "valid_site/phases" \ No newline at end of file +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + inventory: + path: "manifests/site/inventory" + phase: + path: "valid_site/phases" + docEntryPointPrefix: "" diff --git a/pkg/phase/testdata/valid_site_with_doc_prefix/metadata.yaml b/pkg/phase/testdata/valid_site_with_doc_prefix/metadata.yaml index d0f954e1e..69dae8cff 100644 --- a/pkg/phase/testdata/valid_site_with_doc_prefix/metadata.yaml +++ b/pkg/phase/testdata/valid_site_with_doc_prefix/metadata.yaml @@ -1,3 +1,10 @@ -phase: - path: "valid_site_with_doc_prefix/phases" - docEntryPointPrefix: "valid_site_with_doc_prefix/phases" \ No newline at end of file +apiVersion: airshipit.org/v1alpha1 +kind: ManifestMetadata +metadata: + name: manifest-metadata +spec: + inventory: + path: "manifests/site/inventory" + phase: + path: "valid_site_with_doc_prefix/phases" + docEntryPointPrefix: "valid_site_with_doc_prefix/phases"