Add CurrentContextCluster Type and Name methods
These are convinience methods, that may be helpful if any of our modules need to have understanding which cluster they are operating against. Change-Id: Ib5d32ac3d4cd3170544bbc4d5bf3044926b52955 Relates-To: #162
This commit is contained in:
parent
f555af3bf6
commit
996fa6f231
@ -646,6 +646,22 @@ func (c *Config) CurrentContextEntryPoint(clusterType string, phase string) (str
|
||||
phase), nil
|
||||
}
|
||||
|
||||
func (c *Config) CurrentContextClusterType() (string, error) {
|
||||
context, err := c.GetCurrentContext()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return context.ClusterType(), nil
|
||||
}
|
||||
|
||||
func (c *Config) CurrentContextClusterName() (string, error) {
|
||||
context, err := c.GetCurrentContext()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return context.ClusterName(), nil
|
||||
}
|
||||
|
||||
// GetAuthInfo returns an instance of authino
|
||||
// Credential or AuthInfo related methods
|
||||
func (c *Config) GetAuthInfo(aiName string) (*AuthInfo, error) {
|
||||
@ -789,6 +805,10 @@ func (c *Context) ClusterType() string {
|
||||
return NewClusterComplexNameFromKubeClusterName(c.NameInKubeconf).Type
|
||||
}
|
||||
|
||||
func (c *Context) ClusterName() string {
|
||||
return NewClusterComplexNameFromKubeClusterName(c.NameInKubeconf).Name
|
||||
}
|
||||
|
||||
// AuthInfo functions
|
||||
func (c *AuthInfo) String() string {
|
||||
kauthinfo := c.KubeAuthInfo()
|
||||
|
@ -547,6 +547,42 @@ func TestCurrentContextEntryPoint(t *testing.T) {
|
||||
assert.Nil(t, nil, entryPoint)
|
||||
}
|
||||
|
||||
func TestCurrentContextClusterType(t *testing.T) {
|
||||
conf, cleanup := testutil.InitConfig(t)
|
||||
defer cleanup(t)
|
||||
|
||||
expectedClusterType := "ephemeral"
|
||||
|
||||
clusterTypeEmpty, err := conf.CurrentContextClusterType()
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "", clusterTypeEmpty)
|
||||
|
||||
conf.CurrentContext = currentContextName
|
||||
conf.Contexts[currentContextName].Manifest = defaultString
|
||||
|
||||
actualClusterType, err := conf.CurrentContextClusterType()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedClusterType, actualClusterType)
|
||||
}
|
||||
|
||||
func TestCurrentContextClusterName(t *testing.T) {
|
||||
conf, cleanup := testutil.InitConfig(t)
|
||||
defer cleanup(t)
|
||||
|
||||
expectedClusterName := "def"
|
||||
|
||||
clusterNameEmpty, err := conf.CurrentContextClusterName()
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "", clusterNameEmpty)
|
||||
|
||||
conf.CurrentContext = currentContextName
|
||||
conf.Contexts[currentContextName].Manifest = defaultString
|
||||
|
||||
actualClusterName, err := conf.CurrentContextClusterName()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedClusterName, actualClusterName)
|
||||
}
|
||||
|
||||
// AuthInfo Related
|
||||
|
||||
func TestGetAuthInfos(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user