diff --git a/go.sum b/go.sum index 8fda70f61..d2baa3f29 100644 --- a/go.sum +++ b/go.sum @@ -850,6 +850,7 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac h1:8R1esu+8QioDxo4E4mX6bFztO+dMTM49DNAaWfO5OeY= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= diff --git a/pkg/clusterctl/client/client.go b/pkg/clusterctl/client/client.go index 470506e20..a250e14c0 100644 --- a/pkg/clusterctl/client/client.go +++ b/pkg/clusterctl/client/client.go @@ -30,6 +30,7 @@ var _ Interface = &Client{} type Interface interface { Init(kubeconfigPath, kubeconfigContext string) error Move(fromKubeconfigPath, fromKubeconfigContext, toKubeconfigPath, toKubeconfigContext, namespace string) error + GetKubeconfig(options GetKubeconfigOptions) (string, error) } // Client Implements interface to Clusterctl @@ -39,6 +40,19 @@ type Client struct { moveOptions clusterctlclient.MoveOptions } +// GetKubeconfigOptions carries all the options to retrieve kubeconfig from parent cluster +type GetKubeconfigOptions struct { + // Path to parent kubeconfig file + ParentKubeconfigPath string + // Specify context within the kubeconfig file. If empty, cluster client + // will use the current context. + ParentKubeconfigContext string + // Namespace is the namespace in which secret is placed. + ManagedClusterNamespace string + // ManagedClusterName is the name of the managed cluster. + ManagedClusterName string +} + // NewClient returns instance of clusterctl client func NewClient(root string, debug bool, options *airshipv1.Clusterctl) (Interface, error) { if debug { @@ -108,3 +122,15 @@ func newClusterctlClient(root string, options *airshipv1.Clusterctl) (clusterctl occf := clusterctlclient.InjectClusterClientFactory(rf.ClusterClientFactory()) return clusterctlclient.New("", ocf, orf, occf) } + +// GetKubeconfig is a wrapper for related cluster-api function +func (c *Client) GetKubeconfig(options GetKubeconfigOptions) (string, error) { + return c.clusterctlClient.GetKubeconfig(clusterctlclient.GetKubeconfigOptions{ + Kubeconfig: clusterctlclient.Kubeconfig{ + Path: options.ParentKubeconfigPath, + Context: options.ParentKubeconfigContext, + }, + Namespace: options.ManagedClusterNamespace, + WorkloadClusterName: options.ManagedClusterName, + }) +}