Merge "Add repository metadata"
This commit is contained in:
@@ -1079,6 +1079,20 @@ func (c *Config) Purge() error {
|
||||
return os.Remove(c.loadedConfigPath)
|
||||
}
|
||||
|
||||
// CurrentContextManifestMetadata gets manifest metadata
|
||||
func (c *Config) CurrentContextManifestMetadata() (*Metadata, error) {
|
||||
manifest, err := c.CurrentContextManifest()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
meta := &Metadata{}
|
||||
err = util.ReadYAMLFile(manifest.MetadataPath, meta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return meta, nil
|
||||
}
|
||||
|
||||
// DecodeAuthInfo returns authInfo with credentials decoded
|
||||
func DecodeAuthInfo(authinfo *clientcmdapi.AuthInfo) (*clientcmdapi.AuthInfo, error) {
|
||||
password := authinfo.Password
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -551,6 +552,87 @@ func TestCurrentContextClusterName(t *testing.T) {
|
||||
assert.Equal(t, expectedClusterName, actualClusterName)
|
||||
}
|
||||
|
||||
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: "testdata/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: "does not 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",
|
||||
}
|
||||
manifest := &config.Manifest{
|
||||
MetadataPath: tt.metaPath,
|
||||
TargetPath: ".",
|
||||
}
|
||||
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 TestNewClusterComplexNameFromKubeClusterName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
@@ -74,4 +74,6 @@ const (
|
||||
DefaultTargetPath = "/tmp/default"
|
||||
// DefaultSubPath holds default sub path
|
||||
DefaultSubPath = "manifest/default"
|
||||
// DefaultManifestMetadataFile default path to manifest metadata file
|
||||
DefaultManifestMetadataFile = "manifests/site/test-site/metadata.yaml"
|
||||
)
|
||||
|
||||
@@ -35,6 +35,8 @@ type Manifest struct {
|
||||
// you would expect that at treasuremap/manifests you would have ephemeral/initinfra and
|
||||
// ephemera/target directories, containing kustomize.yaml.
|
||||
SubPath string `json:"subPath"`
|
||||
// MetadataPath path to a metadata file relative to TargetPath
|
||||
MetadataPath string `json:"metadataPath"`
|
||||
}
|
||||
|
||||
// Repository is a tuple that holds the information for the remote sources of manifest yaml documents.
|
||||
@@ -84,6 +86,25 @@ type RepoCheckout struct {
|
||||
ForceCheckout bool `json:"force"`
|
||||
}
|
||||
|
||||
// Metadata holds entrypoints for phases, inventory and clusterctl
|
||||
type Metadata struct {
|
||||
Inventory *InventoryMeta `json:"inventory,omitempty"`
|
||||
PhaseMeta *PhaseMeta `json:"phase,omitempty"`
|
||||
}
|
||||
|
||||
// InventoryMeta holds inventory metadata, this is to be extended in the future
|
||||
// when we have more information how to handle non-baremetal inventories
|
||||
// path is a kustomize entrypoint against which we will build bundle containing bmh hosts
|
||||
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
|
||||
type PhaseMeta struct {
|
||||
Path string `json:"path,omitempty"`
|
||||
}
|
||||
|
||||
// Manifest functions
|
||||
func (m *Manifest) String() string {
|
||||
yamlData, err := yaml.Marshal(&m)
|
||||
|
||||
1
pkg/config/testdata/config-string.yaml
vendored
1
pkg/config/testdata/config-string.yaml
vendored
@@ -32,6 +32,7 @@ managementConfiguration:
|
||||
type: redfish
|
||||
manifests:
|
||||
dummy_manifest:
|
||||
metadataPath: manifests/site/test-site/metadata.yaml
|
||||
primaryRepositoryName: primary
|
||||
repositories:
|
||||
primary:
|
||||
|
||||
1
pkg/config/testdata/manifest-string.yaml
vendored
1
pkg/config/testdata/manifest-string.yaml
vendored
@@ -1,3 +1,4 @@
|
||||
metadataPath: manifests/site/test-site/metadata.yaml
|
||||
primaryRepositoryName: primary
|
||||
repositories:
|
||||
primary:
|
||||
|
||||
4
pkg/config/testdata/metadata.yaml
vendored
Normal file
4
pkg/config/testdata/metadata.yaml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
inventory:
|
||||
path: "manifests/site/inventory"
|
||||
phase:
|
||||
path: "manifests/site/phases"
|
||||
@@ -93,6 +93,7 @@ func NewManifest() *Manifest {
|
||||
TargetPath: DefaultTargetPath,
|
||||
SubPath: DefaultSubPath,
|
||||
Repositories: map[string]*Repository{DefaultTestPrimaryRepo: NewRepository()},
|
||||
MetadataPath: DefaultManifestMetadataFile,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user