diff --git a/pkg/config/config.go b/pkg/config/config.go index e7be0fe9f..5e1cb9e5c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -675,6 +675,15 @@ func (c *Config) CurrentContextEntryPoint(phase string) (string, error) { phase), nil } +// CurrentContextTargetPath returns target path from current context's manifest +func (c *Config) CurrentContextTargetPath() (string, error) { + ccm, err := c.CurrentContextManifest() + if err != nil { + return "", err + } + return ccm.TargetPath, nil +} + func (c *Config) CurrentContextClusterType() (string, error) { context, err := c.GetCurrentContext() if err != nil { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 1f3acf779..cfb0c76b7 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -486,6 +486,25 @@ func TestCurrentContextManifest(t *testing.T) { assert.Equal(t, conf.Manifests[defaultString], manifest) } +func TestCurrentTargetPath(t *testing.T) { + conf, cleanup := testutil.InitConfig(t) + defer cleanup(t) + + clusterName := "def" + + manifest, err := conf.CurrentContextManifest() + require.Error(t, err) + assert.Nil(t, manifest) + + conf.CurrentContext = currentContextName + conf.Contexts[currentContextName].Manifest = defaultString + conf.Contexts[currentContextName].KubeContext().Cluster = clusterName + + targetPath, err := conf.CurrentContextTargetPath() + require.NoError(t, err) + assert.Equal(t, conf.Manifests[defaultString].TargetPath, targetPath) +} + func TestCurrentContextEntryPoint(t *testing.T) { conf, cleanup := testutil.InitConfig(t) defer cleanup(t)