From af9e46dfec640bb93e767662ba660a072795f637 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Wed, 29 Apr 2020 06:17:00 -0500 Subject: [PATCH] Refactor CurrentContextEntryPoint function Currently it takes ClusterType as first parameter, however this parameter can be retrieved via appropriate function CurrentContextClusterType in the same module. Change-Id: I205fd7d00bf1745cada88d8fd972dac1dbe0fddf --- pkg/bootstrap/isogen/command.go | 2 +- pkg/cluster/initinfra/infra.go | 2 +- pkg/config/config.go | 9 +++++++-- pkg/config/config_test.go | 5 ++--- pkg/remote/management.go | 8 +------- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pkg/bootstrap/isogen/command.go b/pkg/bootstrap/isogen/command.go index c471e545e..ee784fc90 100644 --- a/pkg/bootstrap/isogen/command.go +++ b/pkg/bootstrap/isogen/command.go @@ -54,7 +54,7 @@ func GenerateBootstrapIso(settings *environment.AirshipCTLSettings) error { // TODO (dukov) replace with the appropriate function once it's available // in document module - root, err := globalConf.CurrentContextEntryPoint(config.Ephemeral, config.BootstrapPhase) + root, err := globalConf.CurrentContextEntryPoint(config.BootstrapPhase) if err != nil { return err } diff --git a/pkg/cluster/initinfra/infra.go b/pkg/cluster/initinfra/infra.go index 6f4fb2819..fcac70a47 100644 --- a/pkg/cluster/initinfra/infra.go +++ b/pkg/cluster/initinfra/infra.go @@ -69,7 +69,7 @@ func (infra *Infra) Deploy() error { return err } - kustomizePath, err := globalConf.CurrentContextEntryPoint(infra.ClusterType, config.InitinfraPhase) + kustomizePath, err := globalConf.CurrentContextEntryPoint(config.InitinfraPhase) if err != nil { return err } diff --git a/pkg/config/config.go b/pkg/config/config.go index 56ea80eef..bf9bba74a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -650,8 +650,13 @@ func (c *Config) CurrentContextManifest() (*Manifest, error) { // CurrentContextEntryPoint returns path to build bundle based on clusterType and phase // example CurrentContextEntryPoint("ephemeral", "initinfra") -func (c *Config) CurrentContextEntryPoint(clusterType string, phase string) (string, error) { - err := ValidClusterType(clusterType) +func (c *Config) CurrentContextEntryPoint(phase string) (string, error) { + clusterType, err := c.CurrentContextClusterType() + if err != nil { + return "", err + } + + err = ValidClusterType(clusterType) if err != nil { return "", err } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index b4241dbe9..1f3acf779 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -491,9 +491,8 @@ func TestCurrentContextEntryPoint(t *testing.T) { defer cleanup(t) clusterName := "def" - clusterType := "ephemeral" - entryPoint, err := conf.CurrentContextEntryPoint(clusterType, defaultString) + entryPoint, err := conf.CurrentContextEntryPoint(defaultString) require.Error(t, err) assert.Equal(t, "", entryPoint) @@ -501,7 +500,7 @@ func TestCurrentContextEntryPoint(t *testing.T) { conf.Contexts[currentContextName].Manifest = defaultString conf.Contexts[currentContextName].KubeContext().Cluster = clusterName - entryPoint, err = conf.CurrentContextEntryPoint(clusterType, defaultString) + entryPoint, err = conf.CurrentContextEntryPoint(defaultString) require.NoError(t, err) assert.Nil(t, nil, entryPoint) } diff --git a/pkg/remote/management.go b/pkg/remote/management.go index 8c67cc9bc..358f2b3c2 100644 --- a/pkg/remote/management.go +++ b/pkg/remote/management.go @@ -114,18 +114,12 @@ func ByName(name string) HostSelector { // NewManager provides a manager that exposes the capability to perform remote direct functionality and other // out-of-band management on multiple hosts. func NewManager(settings *environment.AirshipCTLSettings, phase string, hosts ...HostSelector) (*Manager, error) { - configContext, err := settings.Config.GetCurrentContext() - if err != nil { - return nil, err - } - managementCfg, err := settings.Config.CurrentContextManagementConfig() if err != nil { return nil, err } - clusterType := configContext.ClusterType() - entrypoint, err := settings.Config.CurrentContextEntryPoint(clusterType, phase) + entrypoint, err := settings.Config.CurrentContextEntryPoint(phase) if err != nil { return nil, err }