Remove getters/setters of AirshipCTLSettings
This change removes the getters and setters for the following attributes of pkg/environment.AirshipCTLSettings: * airshipConfigPath * kubeConfigPath * config The above attributes have been exported to account for the removal of these methods. Change-Id: I4e7d38bf6771f7521179a2fe2990475b936b5d95
This commit is contained in:
parent
a4001d255f
commit
5efc26d9f0
@ -9,9 +9,10 @@ import (
|
||||
)
|
||||
|
||||
func TestNewClusterCommandReturn(t *testing.T) {
|
||||
fakeRootSettings := &environment.AirshipCTLSettings{}
|
||||
fakeRootSettings.SetAirshipConfigPath("../../testdata/k8s/config.yaml")
|
||||
fakeRootSettings.SetKubeConfigPath("../../testdata/k8s/kubeconfig.yaml")
|
||||
fakeRootSettings := &environment.AirshipCTLSettings{
|
||||
AirshipConfigPath: "../../testdata/k8s/config.yaml",
|
||||
KubeConfigPath: "../../testdata/k8s/kubeconfig.yaml",
|
||||
}
|
||||
fakeRootSettings.InitConfig()
|
||||
|
||||
tests := []*testutil.CmdTest{
|
||||
|
@ -46,7 +46,7 @@ func NewCmdConfigGetAuthInfo(rootSettings *environment.AirshipCTLSettings) *cobr
|
||||
if len(args) == 1 {
|
||||
o.Name = args[0]
|
||||
}
|
||||
return config.RunGetAuthInfo(o, cmd.OutOrStdout(), rootSettings.Config())
|
||||
return config.RunGetAuthInfo(o, cmd.OutOrStdout(), rootSettings.Config)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -36,17 +36,16 @@ const (
|
||||
)
|
||||
|
||||
func TestGetAuthInfoCmd(t *testing.T) {
|
||||
conf := &config.Config{
|
||||
AuthInfos: map[string]*config.AuthInfo{
|
||||
fooAuthInfo: getTestAuthInfo(),
|
||||
barAuthInfo: getTestAuthInfo(),
|
||||
bazAuthInfo: getTestAuthInfo(),
|
||||
settings := &environment.AirshipCTLSettings{
|
||||
Config: &config.Config{
|
||||
AuthInfos: map[string]*config.AuthInfo{
|
||||
fooAuthInfo: getTestAuthInfo(),
|
||||
barAuthInfo: getTestAuthInfo(),
|
||||
bazAuthInfo: getTestAuthInfo(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(conf)
|
||||
|
||||
cmdTests := []*testutil.CmdTest{
|
||||
{
|
||||
Name: "get-credentials",
|
||||
@ -80,8 +79,7 @@ func TestGetAuthInfoCmd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNoAuthInfosGetAuthInfoCmd(t *testing.T) {
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(&config.Config{})
|
||||
settings := &environment.AirshipCTLSettings{Config: new(config.Config)}
|
||||
cmdTest := &testutil.CmdTest{
|
||||
Name: "no-credentials",
|
||||
CmdLine: "",
|
||||
|
@ -53,7 +53,7 @@ func NewCmdConfigGetCluster(rootSettings *environment.AirshipCTLSettings) *cobra
|
||||
return err
|
||||
}
|
||||
|
||||
return config.RunGetCluster(o, cmd.OutOrStdout(), rootSettings.Config())
|
||||
return config.RunGetCluster(o, cmd.OutOrStdout(), rootSettings.Config)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -39,32 +39,31 @@ const (
|
||||
)
|
||||
|
||||
func TestGetClusterCmd(t *testing.T) {
|
||||
conf := &config.Config{
|
||||
Clusters: map[string]*config.ClusterPurpose{
|
||||
fooCluster: {
|
||||
ClusterTypes: map[string]*config.Cluster{
|
||||
config.Ephemeral: getNamedTestCluster(fooCluster, config.Ephemeral),
|
||||
config.Target: getNamedTestCluster(fooCluster, config.Target),
|
||||
settings := &environment.AirshipCTLSettings{
|
||||
Config: &config.Config{
|
||||
Clusters: map[string]*config.ClusterPurpose{
|
||||
fooCluster: {
|
||||
ClusterTypes: map[string]*config.Cluster{
|
||||
config.Ephemeral: getNamedTestCluster(fooCluster, config.Ephemeral),
|
||||
config.Target: getNamedTestCluster(fooCluster, config.Target),
|
||||
},
|
||||
},
|
||||
},
|
||||
barCluster: {
|
||||
ClusterTypes: map[string]*config.Cluster{
|
||||
config.Ephemeral: getNamedTestCluster(barCluster, config.Ephemeral),
|
||||
config.Target: getNamedTestCluster(barCluster, config.Target),
|
||||
barCluster: {
|
||||
ClusterTypes: map[string]*config.Cluster{
|
||||
config.Ephemeral: getNamedTestCluster(barCluster, config.Ephemeral),
|
||||
config.Target: getNamedTestCluster(barCluster, config.Target),
|
||||
},
|
||||
},
|
||||
},
|
||||
bazCluster: {
|
||||
ClusterTypes: map[string]*config.Cluster{
|
||||
config.Ephemeral: getNamedTestCluster(bazCluster, config.Ephemeral),
|
||||
config.Target: getNamedTestCluster(bazCluster, config.Target),
|
||||
bazCluster: {
|
||||
ClusterTypes: map[string]*config.Cluster{
|
||||
config.Ephemeral: getNamedTestCluster(bazCluster, config.Ephemeral),
|
||||
config.Target: getNamedTestCluster(bazCluster, config.Target),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(conf)
|
||||
|
||||
cmdTests := []*testutil.CmdTest{
|
||||
{
|
||||
Name: "get-ephemeral",
|
||||
@ -121,8 +120,7 @@ func TestGetClusterCmd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNoClustersGetClusterCmd(t *testing.T) {
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(&config.Config{})
|
||||
settings := &environment.AirshipCTLSettings{Config: new(config.Config)}
|
||||
cmdTest := &testutil.CmdTest{
|
||||
Name: "no-clusters",
|
||||
CmdLine: "",
|
||||
|
@ -54,7 +54,7 @@ func NewCmdConfigGetContext(rootSettings *environment.AirshipCTLSettings) *cobra
|
||||
if len(args) == 1 {
|
||||
o.Name = args[0]
|
||||
}
|
||||
return config.RunGetContext(o, cmd.OutOrStdout(), rootSettings.Config())
|
||||
return config.RunGetContext(o, cmd.OutOrStdout(), rootSettings.Config)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -38,18 +38,17 @@ const (
|
||||
)
|
||||
|
||||
func TestGetContextCmd(t *testing.T) {
|
||||
conf := &config.Config{
|
||||
Contexts: map[string]*config.Context{
|
||||
fooContext: getNamedTestContext(fooContext),
|
||||
barContext: getNamedTestContext(barContext),
|
||||
bazContext: getNamedTestContext(bazContext),
|
||||
settings := &environment.AirshipCTLSettings{
|
||||
Config: &config.Config{
|
||||
Contexts: map[string]*config.Context{
|
||||
fooContext: getNamedTestContext(fooContext),
|
||||
barContext: getNamedTestContext(barContext),
|
||||
bazContext: getNamedTestContext(bazContext),
|
||||
},
|
||||
CurrentContext: bazContext,
|
||||
},
|
||||
CurrentContext: bazContext,
|
||||
}
|
||||
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(conf)
|
||||
|
||||
cmdTests := []*testutil.CmdTest{
|
||||
{
|
||||
Name: "get-context",
|
||||
@ -88,8 +87,7 @@ found in the configuration.`, missingContext),
|
||||
}
|
||||
|
||||
func TestNoContextsGetContextCmd(t *testing.T) {
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(&config.Config{})
|
||||
settings := &environment.AirshipCTLSettings{Config: new(config.Config)}
|
||||
cmdTest := &testutil.CmdTest{
|
||||
Name: "no-contexts",
|
||||
CmdLine: "",
|
||||
|
@ -32,14 +32,7 @@ func NewCmdConfigInit(rootSettings *environment.AirshipCTLSettings) *cobra.Comma
|
||||
Use: "init",
|
||||
Short: configInitLong,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c := rootSettings.Config()
|
||||
|
||||
err := c.PersistConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return rootSettings.Config.PersistConfig()
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ func NewCmdConfigSetAuthInfo(rootSettings *environment.AirshipCTLSettings) *cobr
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
o.Name = args[0]
|
||||
modified, err := config.RunSetAuthInfo(o, rootSettings.Config(), true)
|
||||
modified, err := config.RunSetAuthInfo(o, rootSettings.Config, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -88,12 +88,11 @@ func initInputConfig(t *testing.T) (given *config.Config, cleanup func(*testing.
|
||||
}
|
||||
|
||||
func (test setAuthInfoTest) run(t *testing.T) {
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(test.inputConfig)
|
||||
settings := &environment.AirshipCTLSettings{Config: test.inputConfig}
|
||||
test.cmdTest.Cmd = cmd.NewCmdConfigSetAuthInfo(settings)
|
||||
testutil.RunTest(t, test.cmdTest)
|
||||
|
||||
afterRunConf := settings.Config()
|
||||
afterRunConf := settings.Config
|
||||
// Find the AuthInfo Created or Modified
|
||||
afterRunAuthInfo, err := afterRunConf.GetAuthInfo(test.userName)
|
||||
require.NoError(t, err)
|
||||
|
@ -66,7 +66,7 @@ func NewCmdConfigSetCluster(rootSettings *environment.AirshipCTLSettings) *cobra
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
o.Name = args[0]
|
||||
modified, err := config.RunSetCluster(o, rootSettings.Config(), true)
|
||||
modified, err := config.RunSetCluster(o, rootSettings.Config, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -201,10 +201,7 @@ func TestModifyCluster(t *testing.T) {
|
||||
}
|
||||
|
||||
func (test setClusterTest) run(t *testing.T) {
|
||||
// Get the Environment
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(test.givenConfig)
|
||||
|
||||
settings := &environment.AirshipCTLSettings{Config: test.givenConfig}
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
|
||||
cmd := cmd.NewCmdConfigSetCluster(settings)
|
||||
@ -219,7 +216,7 @@ func (test setClusterTest) run(t *testing.T) {
|
||||
require.NoErrorf(t, err, "unexpected error executing command: %v, args: %v, flags: %v", err, test.args, test.flags)
|
||||
|
||||
// Loads the Config File that was updated
|
||||
afterRunConf := settings.Config()
|
||||
afterRunConf := settings.Config
|
||||
// Get ClusterType
|
||||
tctypeFlag := cmd.Flag(config.FlagClusterType)
|
||||
require.NotNil(t, tctypeFlag)
|
||||
|
@ -70,7 +70,7 @@ func NewCmdConfigSetContext(rootSettings *environment.AirshipCTLSettings) *cobra
|
||||
return nil
|
||||
}
|
||||
|
||||
modified, err := config.RunSetContext(o, rootSettings.Config(), true)
|
||||
modified, err := config.RunSetContext(o, rootSettings.Config, true)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -127,13 +127,12 @@ func TestSetContext(t *testing.T) {
|
||||
|
||||
func (test setContextTest) run(t *testing.T) {
|
||||
// Get the Environment
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(test.givenConfig)
|
||||
settings := &environment.AirshipCTLSettings{Config: test.givenConfig}
|
||||
|
||||
test.cmdTest.Cmd = cmd.NewCmdConfigSetContext(settings)
|
||||
testutil.RunTest(t, test.cmdTest)
|
||||
|
||||
afterRunConf := settings.Config()
|
||||
afterRunConf := settings.Config
|
||||
|
||||
// Find the Context Created or Modified
|
||||
afterRunContext, err := afterRunConf.GetContext(test.contextName)
|
||||
|
@ -44,7 +44,7 @@ func NewCmdConfigUseContext(rootSettings *environment.AirshipCTLSettings) *cobra
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
contextName := args[0]
|
||||
err := config.RunUseContext(contextName, rootSettings.Config())
|
||||
err := config.RunUseContext(contextName, rootSettings.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -26,11 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func TestConfigUseContext(t *testing.T) {
|
||||
conf := testutil.DummyConfig()
|
||||
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(conf)
|
||||
|
||||
settings := &environment.AirshipCTLSettings{Config: testutil.DummyConfig()}
|
||||
cmdTests := []*testutil.CmdTest{
|
||||
{
|
||||
Name: "config-use-context",
|
||||
|
@ -13,27 +13,26 @@ import (
|
||||
)
|
||||
|
||||
func getDummyAirshipSettings(t *testing.T) *environment.AirshipCTLSettings {
|
||||
settings := new(environment.AirshipCTLSettings)
|
||||
conf := testutil.DummyConfig()
|
||||
mfst := conf.Manifests["dummy_manifest"]
|
||||
settings := &environment.AirshipCTLSettings{Config: testutil.DummyConfig()}
|
||||
|
||||
err := fixtures.Init()
|
||||
require.NoError(t, err)
|
||||
|
||||
fx := fixtures.Basic().One()
|
||||
|
||||
mfst.Repositories = map[string]*config.Repository{"primary": {
|
||||
URLString: fx.DotGit().Root(),
|
||||
CheckoutOptions: &config.RepoCheckout{
|
||||
Branch: "master",
|
||||
ForceCheckout: false,
|
||||
mfst := settings.Config.Manifests["dummy_manifest"]
|
||||
mfst.Repositories = map[string]*config.Repository{
|
||||
"primary": {
|
||||
URLString: fx.DotGit().Root(),
|
||||
CheckoutOptions: &config.RepoCheckout{
|
||||
Branch: "master",
|
||||
ForceCheckout: false,
|
||||
},
|
||||
Auth: &config.RepoAuth{
|
||||
Type: "http-basic",
|
||||
},
|
||||
},
|
||||
Auth: &config.RepoAuth{
|
||||
Type: "http-basic",
|
||||
},
|
||||
},
|
||||
}
|
||||
settings.SetConfig(conf)
|
||||
return settings
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ func TestFlagLoading(t *testing.T) {
|
||||
err = rootCmd.Execute()
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, settings.AirshipConfigPath(), tt.expected)
|
||||
assert.Equal(t, settings.AirshipConfigPath, tt.expected)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ const (
|
||||
func GenerateBootstrapIso(settings *environment.AirshipCTLSettings) error {
|
||||
ctx := context.Background()
|
||||
|
||||
globalConf := settings.Config()
|
||||
globalConf := settings.Config
|
||||
if err := globalConf.EnsureComplete(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func (infra *Infra) Deploy() error {
|
||||
ao.SetPrune(document.InitInfraSelector)
|
||||
}
|
||||
|
||||
globalConf := infra.RootSettings.Config()
|
||||
globalConf := infra.RootSettings.Config
|
||||
if err = globalConf.EnsureComplete(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -86,10 +86,9 @@ func TestDeploy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// MakeNewFakeRootSettings takes kubeconfig path and directory path to fixture dir as argument.
|
||||
// makeNewFakeRootSettings takes kubeconfig path and directory path to fixture dir as argument.
|
||||
func makeNewFakeRootSettings(t *testing.T, kp string, dir string) *environment.AirshipCTLSettings {
|
||||
t.Helper()
|
||||
rs := &environment.AirshipCTLSettings{}
|
||||
|
||||
akp, err := filepath.Abs(kp)
|
||||
require.NoError(t, err)
|
||||
@ -97,9 +96,11 @@ func makeNewFakeRootSettings(t *testing.T, kp string, dir string) *environment.A
|
||||
adir, err := filepath.Abs(dir)
|
||||
require.NoError(t, err)
|
||||
|
||||
rs.SetAirshipConfigPath(adir)
|
||||
rs.SetKubeConfigPath(akp)
|
||||
settings := &environment.AirshipCTLSettings{
|
||||
AirshipConfigPath: adir,
|
||||
KubeConfigPath: akp,
|
||||
}
|
||||
|
||||
rs.InitConfig()
|
||||
return rs
|
||||
settings.InitConfig()
|
||||
return settings
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func (s *Settings) Pull() error {
|
||||
|
||||
func (s *Settings) cloneRepositories() error {
|
||||
// Clone main repository
|
||||
currentManifest, err := s.Config().CurrentContextManifest()
|
||||
currentManifest, err := s.Config.CurrentContextManifest()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -20,12 +20,11 @@ import (
|
||||
)
|
||||
|
||||
func getDummyPullSettings() *Settings {
|
||||
mockPullSettings := &Settings{
|
||||
AirshipCTLSettings: new(environment.AirshipCTLSettings),
|
||||
return &Settings{
|
||||
AirshipCTLSettings: &environment.AirshipCTLSettings{
|
||||
Config: testutil.DummyConfig(),
|
||||
},
|
||||
}
|
||||
mockConf := testutil.DummyConfig()
|
||||
mockPullSettings.AirshipCTLSettings.SetConfig(mockConf)
|
||||
return mockPullSettings
|
||||
}
|
||||
|
||||
func TestPull(t *testing.T) {
|
||||
@ -34,7 +33,7 @@ func TestPull(t *testing.T) {
|
||||
|
||||
t.Run("cloneRepositories", func(t *testing.T) {
|
||||
dummyPullSettings := getDummyPullSettings()
|
||||
currentManifest, err := dummyPullSettings.Config().CurrentContextManifest()
|
||||
currentManifest, err := dummyPullSettings.Config.CurrentContextManifest()
|
||||
require.NoError(err)
|
||||
|
||||
err = fixtures.Init()
|
||||
@ -75,7 +74,7 @@ func TestPull(t *testing.T) {
|
||||
|
||||
t.Run("Pull", func(t *testing.T) {
|
||||
dummyPullSettings := getDummyPullSettings()
|
||||
conf := dummyPullSettings.AirshipCTLSettings.Config()
|
||||
conf := dummyPullSettings.AirshipCTLSettings.Config
|
||||
|
||||
err := fixtures.Init()
|
||||
require.NoError(err)
|
||||
@ -95,7 +94,7 @@ func TestPull(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
dummyPullSettings.SetConfig(conf)
|
||||
dummyPullSettings.Config = conf
|
||||
|
||||
tmpDir, cleanup := testutil.TempDir(t, "airshipctlPullTest-")
|
||||
defer cleanup(t)
|
||||
|
@ -16,9 +16,9 @@ import (
|
||||
type AirshipCTLSettings struct {
|
||||
// Debug is used for verbose output
|
||||
Debug bool
|
||||
airshipConfigPath string
|
||||
kubeConfigPath string
|
||||
config *config.Config
|
||||
AirshipConfigPath string
|
||||
KubeConfigPath string
|
||||
Config *config.Config
|
||||
}
|
||||
|
||||
// InitFlags adds the default settings flags to cmd
|
||||
@ -34,51 +34,27 @@ func (a *AirshipCTLSettings) InitFlags(cmd *cobra.Command) {
|
||||
|
||||
defaultAirshipConfigPath := filepath.Join(defaultAirshipConfigDir, config.AirshipConfig)
|
||||
flags.StringVar(
|
||||
&a.airshipConfigPath,
|
||||
&a.AirshipConfigPath,
|
||||
config.FlagConfigFilePath,
|
||||
"",
|
||||
`Path to file for airshipctl configuration. (default "`+defaultAirshipConfigPath+`")`)
|
||||
|
||||
defaultKubeConfigPath := filepath.Join(defaultAirshipConfigDir, config.AirshipKubeConfig)
|
||||
flags.StringVar(
|
||||
&a.kubeConfigPath,
|
||||
&a.KubeConfigPath,
|
||||
clientcmd.RecommendedConfigPathFlag,
|
||||
"",
|
||||
`Path to kubeconfig associated with airshipctl configuration. (default "`+defaultKubeConfigPath+`")`)
|
||||
}
|
||||
|
||||
func (a *AirshipCTLSettings) Config() *config.Config {
|
||||
return a.config
|
||||
}
|
||||
|
||||
func (a *AirshipCTLSettings) SetConfig(conf *config.Config) {
|
||||
a.config = conf
|
||||
}
|
||||
|
||||
func (a *AirshipCTLSettings) AirshipConfigPath() string {
|
||||
return a.airshipConfigPath
|
||||
}
|
||||
|
||||
func (a *AirshipCTLSettings) SetAirshipConfigPath(acp string) {
|
||||
a.airshipConfigPath = acp
|
||||
}
|
||||
|
||||
func (a *AirshipCTLSettings) KubeConfigPath() string {
|
||||
return a.kubeConfigPath
|
||||
}
|
||||
|
||||
func (a *AirshipCTLSettings) SetKubeConfigPath(kcp string) {
|
||||
a.kubeConfigPath = kcp
|
||||
}
|
||||
|
||||
// InitConfig - Initializes and loads Config it exists.
|
||||
func (a *AirshipCTLSettings) InitConfig() {
|
||||
a.SetConfig(config.NewConfig())
|
||||
a.Config = config.NewConfig()
|
||||
|
||||
a.initAirshipConfigPath()
|
||||
a.initKubeConfigPath()
|
||||
|
||||
err := a.Config().LoadConfig(a.AirshipConfigPath(), a.KubeConfigPath())
|
||||
err := a.Config.LoadConfig(a.AirshipConfigPath, a.KubeConfigPath)
|
||||
if err != nil {
|
||||
// Should stop airshipctl
|
||||
log.Fatal(err)
|
||||
@ -87,19 +63,19 @@ func (a *AirshipCTLSettings) InitConfig() {
|
||||
|
||||
func (a *AirshipCTLSettings) initAirshipConfigPath() {
|
||||
// The airshipConfigPath may already have been received as a command line argument
|
||||
if a.airshipConfigPath != "" {
|
||||
if a.AirshipConfigPath != "" {
|
||||
return
|
||||
}
|
||||
|
||||
// Otherwise, we can check if we got the path via ENVIRONMENT variable
|
||||
a.airshipConfigPath = os.Getenv(config.AirshipConfigEnv)
|
||||
if a.airshipConfigPath != "" {
|
||||
a.AirshipConfigPath = os.Getenv(config.AirshipConfigEnv)
|
||||
if a.AirshipConfigPath != "" {
|
||||
return
|
||||
}
|
||||
|
||||
// Otherwise, we'll try putting it in the home directory
|
||||
homeDir := userHomeDir()
|
||||
a.airshipConfigPath = filepath.Join(homeDir, config.AirshipConfigDir, config.AirshipConfig)
|
||||
a.AirshipConfigPath = filepath.Join(homeDir, config.AirshipConfigDir, config.AirshipConfig)
|
||||
}
|
||||
|
||||
func (a *AirshipCTLSettings) initKubeConfigPath() {
|
||||
@ -111,19 +87,19 @@ func (a *AirshipCTLSettings) initKubeConfigPath() {
|
||||
// explicitly want airshipctl to use it.
|
||||
|
||||
// The kubeConfigPath may already have been received as a command line argument
|
||||
if a.kubeConfigPath != "" {
|
||||
if a.KubeConfigPath != "" {
|
||||
return
|
||||
}
|
||||
|
||||
// Otherwise, we can check if we got the path via ENVIRONMENT variable
|
||||
a.kubeConfigPath = os.Getenv(config.AirshipKubeConfigEnv)
|
||||
if a.kubeConfigPath != "" {
|
||||
a.KubeConfigPath = os.Getenv(config.AirshipKubeConfigEnv)
|
||||
if a.KubeConfigPath != "" {
|
||||
return
|
||||
}
|
||||
|
||||
// Otherwise, we'll try putting it in the home directory
|
||||
homeDir := userHomeDir()
|
||||
a.kubeConfigPath = filepath.Join(homeDir, config.AirshipConfigDir, config.AirshipKubeConfig)
|
||||
a.KubeConfigPath = filepath.Join(homeDir, config.AirshipConfigDir, config.AirshipKubeConfig)
|
||||
}
|
||||
|
||||
// userHomeDir is a utility function that wraps os.UserHomeDir and returns no
|
||||
|
@ -48,8 +48,8 @@ func TestInitConfig(t *testing.T) {
|
||||
expectedKubeConfig := filepath.Join(testDir, config.AirshipConfigDir, config.AirshipKubeConfig)
|
||||
|
||||
testSettings.InitConfig()
|
||||
assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath())
|
||||
assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath())
|
||||
assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath)
|
||||
assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath)
|
||||
})
|
||||
|
||||
t.Run("PreferEnvToDefault", func(subTest *testing.T) {
|
||||
@ -68,8 +68,8 @@ func TestInitConfig(t *testing.T) {
|
||||
defer os.Unsetenv(config.AirshipKubeConfigEnv)
|
||||
|
||||
testSettings.InitConfig()
|
||||
assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath())
|
||||
assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath())
|
||||
assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath)
|
||||
assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath)
|
||||
})
|
||||
|
||||
t.Run("PreferCmdLineArgToDefault", func(subTest *testing.T) {
|
||||
@ -78,17 +78,18 @@ func TestInitConfig(t *testing.T) {
|
||||
defer cleanup(t)
|
||||
defer setHome(testDir)()
|
||||
|
||||
var testSettings AirshipCTLSettings
|
||||
expectedAirshipConfig := filepath.Join(testDir, "airshipCmdLine")
|
||||
expectedKubeConfig := filepath.Join(testDir, "kubeCmdLine")
|
||||
|
||||
testSettings.SetAirshipConfigPath(expectedAirshipConfig)
|
||||
testSettings.SetKubeConfigPath(expectedKubeConfig)
|
||||
testSettings := AirshipCTLSettings{
|
||||
AirshipConfigPath: expectedAirshipConfig,
|
||||
KubeConfigPath: expectedKubeConfig,
|
||||
}
|
||||
|
||||
// InitConfig should not change any values
|
||||
testSettings.InitConfig()
|
||||
assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath())
|
||||
assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath())
|
||||
assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath)
|
||||
assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath)
|
||||
})
|
||||
|
||||
t.Run("PreferCmdLineArgToEnv", func(subTest *testing.T) {
|
||||
@ -97,7 +98,6 @@ func TestInitConfig(t *testing.T) {
|
||||
defer cleanup(t)
|
||||
defer setHome(testDir)()
|
||||
|
||||
var testSettings AirshipCTLSettings
|
||||
expectedAirshipConfig := filepath.Join(testDir, "airshipCmdLine")
|
||||
expectedKubeConfig := filepath.Join(testDir, "kubeCmdLine")
|
||||
|
||||
@ -111,12 +111,14 @@ func TestInitConfig(t *testing.T) {
|
||||
defer os.Unsetenv(config.AirshipConfigEnv)
|
||||
defer os.Unsetenv(config.AirshipKubeConfigEnv)
|
||||
|
||||
testSettings.SetAirshipConfigPath(expectedAirshipConfig)
|
||||
testSettings.SetKubeConfigPath(expectedKubeConfig)
|
||||
testSettings := AirshipCTLSettings{
|
||||
AirshipConfigPath: expectedAirshipConfig,
|
||||
KubeConfigPath: expectedKubeConfig,
|
||||
}
|
||||
|
||||
testSettings.InitConfig()
|
||||
assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath())
|
||||
assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath())
|
||||
assert.Equal(t, expectedAirshipConfig, testSettings.AirshipConfigPath)
|
||||
assert.Equal(t, expectedKubeConfig, testSettings.KubeConfigPath)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,9 @@ func NewClient(settings *environment.AirshipCTLSettings) (Interface, error) {
|
||||
client := new(Client)
|
||||
var err error
|
||||
|
||||
f := k8sutils.FactoryFromKubeConfigPath(settings.KubeConfigPath())
|
||||
f := k8sutils.FactoryFromKubeConfigPath(settings.KubeConfigPath)
|
||||
|
||||
pathToBufferDir := filepath.Dir(settings.AirshipConfigPath())
|
||||
pathToBufferDir := filepath.Dir(settings.AirshipConfigPath)
|
||||
client.kubectl = kubectl.NewKubectl(f).WithBufferDir(pathToBufferDir)
|
||||
|
||||
client.clientSet, err = f.KubernetesClientSet()
|
||||
|
@ -18,10 +18,8 @@ const (
|
||||
)
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
conf, cleanup := testutil.InitConfig(t)
|
||||
defer cleanup(t)
|
||||
settings.SetConfig(conf)
|
||||
|
||||
akp, err := filepath.Abs(kubeconfigPath)
|
||||
require.NoError(t, err)
|
||||
@ -29,8 +27,11 @@ func TestNewClient(t *testing.T) {
|
||||
adir, err := filepath.Abs(airshipConfigDir)
|
||||
require.NoError(t, err)
|
||||
|
||||
settings.SetAirshipConfigPath(adir)
|
||||
settings.SetKubeConfigPath(akp)
|
||||
settings := &environment.AirshipCTLSettings{
|
||||
Config: conf,
|
||||
AirshipConfigPath: adir,
|
||||
KubeConfigPath: akp,
|
||||
}
|
||||
|
||||
client, err := client.NewClient(settings)
|
||||
assert.NoError(t, err)
|
||||
|
@ -91,7 +91,7 @@ func (a *Adapter) configureClient(remoteURL string) error {
|
||||
|
||||
// initializeAdapter retrieves the remote direct configuration defined in the Airship configuration file.
|
||||
func (a *Adapter) initializeAdapter(settings *environment.AirshipCTLSettings) error {
|
||||
cfg := settings.Config()
|
||||
cfg := settings.Config
|
||||
bootstrapSettings, err := cfg.CurrentContextBootstrapInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -21,12 +21,11 @@ const (
|
||||
|
||||
func initSettings(t *testing.T, rd *config.RemoteDirect, testdata string) *environment.AirshipCTLSettings {
|
||||
t.Helper()
|
||||
settings := &environment.AirshipCTLSettings{}
|
||||
settings.SetConfig(testutil.DummyConfig())
|
||||
bi, err := settings.Config().CurrentContextBootstrapInfo()
|
||||
settings := &environment.AirshipCTLSettings{Config: testutil.DummyConfig()}
|
||||
bi, err := settings.Config.CurrentContextBootstrapInfo()
|
||||
require.NoError(t, err)
|
||||
bi.RemoteDirect = rd
|
||||
cm, err := settings.Config().CurrentContextManifest()
|
||||
cm, err := settings.Config.CurrentContextManifest()
|
||||
require.NoError(t, err)
|
||||
cm.TargetPath = "testdata/" + testdata
|
||||
return settings
|
||||
|
Loading…
Reference in New Issue
Block a user