Merge "Extend clusterctl client interface with GetKubeconfig function"

This commit is contained in:
Zuul 2020-11-02 19:00:33 +00:00 committed by Gerrit Code Review
commit 6a4e23b6a8
2 changed files with 27 additions and 0 deletions

1
go.sum
View File

@ -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=

View File

@ -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,
})
}