Merge "Use provider.URL() instead of root"
This commit is contained in:
commit
1b81d85279
@ -24,11 +24,6 @@ import (
|
|||||||
"opendev.org/airship/airshipctl/pkg/log"
|
"opendev.org/airship/airshipctl/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
// path to file on in memory file system
|
|
||||||
dummyComponentPath = "/dummy/path/v0.3.2/components.yaml"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ Interface = &Client{}
|
var _ Interface = &Client{}
|
||||||
|
|
||||||
// Interface is abstraction to Clusterctl
|
// Interface is abstraction to Clusterctl
|
||||||
@ -79,14 +74,14 @@ func (c *Client) Init(kubeconfigPath, kubeconfigContext string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newConfig returns clusterctl config client
|
// newConfig returns clusterctl config client
|
||||||
func newConfig(options *airshipv1.Clusterctl) (clusterctlconfig.Client, error) {
|
func newConfig(options *airshipv1.Clusterctl, root string) (clusterctlconfig.Client, error) {
|
||||||
for _, provider := range options.Providers {
|
for _, provider := range options.Providers {
|
||||||
// this is a workaround as cluserctl validates if URL is empty, even though it is not
|
// this is a workaround as cluserctl validates if URL is empty, even though it is not
|
||||||
// used anywhere outside repository factory which we override
|
// used anywhere outside repository factory which we override
|
||||||
// TODO (kkalynovskyi) we need to create issue for this in clusterctl, and remove URL
|
// TODO (kkalynovskyi) we need to create issue for this in clusterctl, and remove URL
|
||||||
// validation and move it to be an error during repository interface initialization
|
// validation and move it to be an error during repository interface initialization
|
||||||
if !provider.IsClusterctlRepository {
|
if !provider.IsClusterctlRepository {
|
||||||
provider.URL = dummyComponentPath
|
provider.URL = root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader, err := implementations.NewAirshipReader(options)
|
reader, err := implementations.NewAirshipReader(options)
|
||||||
@ -97,12 +92,11 @@ func newConfig(options *airshipv1.Clusterctl) (clusterctlconfig.Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newClusterctlClient(root string, options *airshipv1.Clusterctl) (clusterctlclient.Client, error) {
|
func newClusterctlClient(root string, options *airshipv1.Clusterctl) (clusterctlclient.Client, error) {
|
||||||
cconf, err := newConfig(options)
|
cconf, err := newConfig(options, root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rf := RepositoryFactory{
|
rf := RepositoryFactory{
|
||||||
root: root,
|
|
||||||
Options: options,
|
Options: options,
|
||||||
ConfigClient: cconf,
|
ConfigClient: cconf,
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ func TestNewConfig(t *testing.T) {
|
|||||||
name: "multiple repos with airship",
|
name: "multiple repos with airship",
|
||||||
presentProvider: "airship-repo",
|
presentProvider: "airship-repo",
|
||||||
presentType: "InfrastructureProvider",
|
presentType: "InfrastructureProvider",
|
||||||
expectedURL: dummyComponentPath,
|
expectedURL: testDataDir,
|
||||||
conf: &airshipv1.Clusterctl{
|
conf: &airshipv1.Clusterctl{
|
||||||
|
|
||||||
Providers: []*airshipv1.Provider{
|
Providers: []*airshipv1.Provider{
|
||||||
@ -107,7 +107,7 @@ func TestNewConfig(t *testing.T) {
|
|||||||
provName := tt.presentProvider
|
provName := tt.presentProvider
|
||||||
provType := tt.presentType
|
provType := tt.presentType
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := newConfig(conf)
|
got, err := newConfig(conf, testDataDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
providerClient := got.Providers()
|
providerClient := got.Providers()
|
||||||
provider, err := providerClient.Get(provName, clusterctlv1.ProviderType(provType))
|
provider, err := providerClient.Get(provName, clusterctlv1.ProviderType(provType))
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
|
|
||||||
// RepositoryFactory returns an injection factory to work with clusterctl client
|
// RepositoryFactory returns an injection factory to work with clusterctl client
|
||||||
type RepositoryFactory struct {
|
type RepositoryFactory struct {
|
||||||
root string
|
|
||||||
Options *airshipv1.Clusterctl
|
Options *airshipv1.Clusterctl
|
||||||
ConfigClient config.Client
|
ConfigClient config.Client
|
||||||
}
|
}
|
||||||
@ -72,7 +71,7 @@ func (f RepositoryFactory) repoFactory(provider config.Provider) (repository.Cli
|
|||||||
return nil, ErrProviderRepoNotFound{ProviderName: name, ProviderType: string(repoType)}
|
return nil, ErrProviderRepoNotFound{ProviderName: name, ProviderType: string(repoType)}
|
||||||
}
|
}
|
||||||
// construct a repository for this provider using root and version map
|
// construct a repository for this provider using root and version map
|
||||||
repo, err := implementations.NewRepository(f.root, versions)
|
repo, err := implementations.NewRepository(provider.URL(), versions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func testOptions(t *testing.T, input string) *airshipv1.Clusterctl {
|
|||||||
|
|
||||||
func testNewConfig(t *testing.T, o *airshipv1.Clusterctl) clusterctlconfig.Client {
|
func testNewConfig(t *testing.T, o *airshipv1.Clusterctl) clusterctlconfig.Client {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
configClient, err := newConfig(o)
|
configClient, err := newConfig(o, testDataDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, configClient)
|
require.NotNil(t, configClient)
|
||||||
return configClient
|
return configClient
|
||||||
@ -80,7 +80,6 @@ func TestFactory(t *testing.T) {
|
|||||||
o := testOptions(t, testConfigFactory)
|
o := testOptions(t, testConfigFactory)
|
||||||
configClient := testNewConfig(t, o)
|
configClient := testNewConfig(t, o)
|
||||||
factory := RepositoryFactory{
|
factory := RepositoryFactory{
|
||||||
root: testDataDir,
|
|
||||||
Options: o,
|
Options: o,
|
||||||
ConfigClient: configClient,
|
ConfigClient: configClient,
|
||||||
}
|
}
|
||||||
@ -134,7 +133,7 @@ func TestFactory(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
sort.Strings(expectedVersions)
|
sort.Strings(expectedVersions)
|
||||||
sort.Strings(versions)
|
sort.Strings(versions)
|
||||||
assert.Equal(t, dummyComponentPath, repo.URL())
|
assert.Equal(t, testDataDir, repo.URL())
|
||||||
assert.Equal(t, expectedVersions, versions)
|
assert.Equal(t, expectedVersions, versions)
|
||||||
components := repo.Components()
|
components := repo.Components()
|
||||||
require.NotNil(t, components)
|
require.NotNil(t, components)
|
||||||
@ -163,7 +162,6 @@ func TestClientRepositoryFactory(t *testing.T) {
|
|||||||
o := testOptions(t, testConfigFactory)
|
o := testOptions(t, testConfigFactory)
|
||||||
configClient := testNewConfig(t, o)
|
configClient := testNewConfig(t, o)
|
||||||
factory := RepositoryFactory{
|
factory := RepositoryFactory{
|
||||||
root: testDataDir,
|
|
||||||
Options: o,
|
Options: o,
|
||||||
ConfigClient: configClient,
|
ConfigClient: configClient,
|
||||||
}
|
}
|
||||||
@ -180,7 +178,6 @@ func TestRepoFactoryFunction(t *testing.T) {
|
|||||||
configClient := testNewConfig(t, o)
|
configClient := testNewConfig(t, o)
|
||||||
|
|
||||||
factory := RepositoryFactory{
|
factory := RepositoryFactory{
|
||||||
root: testDataDir,
|
|
||||||
Options: o,
|
Options: o,
|
||||||
ConfigClient: configClient,
|
ConfigClient: configClient,
|
||||||
}
|
}
|
||||||
@ -203,7 +200,6 @@ func TestClusterctlRepoFactoryFunction(t *testing.T) {
|
|||||||
o := testOptions(t, testConfigFactory)
|
o := testOptions(t, testConfigFactory)
|
||||||
configClient := testNewConfig(t, o)
|
configClient := testNewConfig(t, o)
|
||||||
factory := RepositoryFactory{
|
factory := RepositoryFactory{
|
||||||
root: testDataDir,
|
|
||||||
Options: o,
|
Options: o,
|
||||||
ConfigClient: configClient,
|
ConfigClient: configClient,
|
||||||
}
|
}
|
||||||
@ -231,7 +227,6 @@ func TestRepositoryFactoryErrors(t *testing.T) {
|
|||||||
configClient := testNewConfig(t, o)
|
configClient := testNewConfig(t, o)
|
||||||
require.NotNil(t, configClient)
|
require.NotNil(t, configClient)
|
||||||
factory := RepositoryFactory{
|
factory := RepositoryFactory{
|
||||||
root: testDataDir,
|
|
||||||
Options: o,
|
Options: o,
|
||||||
ConfigClient: configClient,
|
ConfigClient: configClient,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user