Honor kube client flags in install command (#1656)
Flags specifying the kubeconfig or kubecontext to use weren't actually being used by the install command. Fixes #1651 Signed-off-by: Nolan Brubaker <brubakern@vmware.com>pull/1681/head
parent
3124570c7f
commit
aa8c0cd471
|
@ -0,0 +1 @@
|
|||
Respect the --kubecontext and --kubeconfig arugments for `velero install`.
|
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
|
@ -38,6 +39,9 @@ type Factory interface {
|
|||
// KubeClient returns a Kubernetes client. It uses the following priority to specify the cluster
|
||||
// configuration: --kubeconfig flag, KUBECONFIG environment variable, in-cluster configuration.
|
||||
KubeClient() (kubernetes.Interface, error)
|
||||
// DynamicClient returns a Kubernetes dynamic client. It uses the following priority to specify the cluster
|
||||
// configuration: --kubeconfig flag, KUBECONFIG environment variable, in-cluster configuration.
|
||||
DynamicClient() (dynamic.Interface, error)
|
||||
Namespace() string
|
||||
}
|
||||
|
||||
|
@ -103,6 +107,19 @@ func (f *factory) KubeClient() (kubernetes.Interface, error) {
|
|||
return kubeClient, nil
|
||||
}
|
||||
|
||||
func (f *factory) DynamicClient() (dynamic.Interface, error) {
|
||||
clientConfig, err := Config(f.kubeconfig, f.kubecontext, f.baseName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dynamicClient, err := dynamic.NewForConfig(clientConfig)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
return dynamicClient, nil
|
||||
}
|
||||
|
||||
func (f *factory) Namespace() string {
|
||||
return f.namespace
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/client-go/dynamic"
|
||||
|
||||
api "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
"github.com/heptio/velero/pkg/client"
|
||||
|
@ -147,7 +146,7 @@ This is useful as a starting point for more customized installations.
|
|||
Run: func(c *cobra.Command, args []string) {
|
||||
cmd.CheckError(o.Validate(c, args, f))
|
||||
cmd.CheckError(o.Complete(args, f))
|
||||
cmd.CheckError(o.Run(c))
|
||||
cmd.CheckError(o.Run(c, f))
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -159,7 +158,7 @@ This is useful as a starting point for more customized installations.
|
|||
}
|
||||
|
||||
// Run executes a command in the context of the provided arguments.
|
||||
func (o *InstallOptions) Run(c *cobra.Command) error {
|
||||
func (o *InstallOptions) Run(c *cobra.Command, f client.Factory) error {
|
||||
vo, err := o.AsVeleroOptions()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -177,12 +176,7 @@ func (o *InstallOptions) Run(c *cobra.Command) error {
|
|||
if o.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
clientConfig, err := client.Config("", "", fmt.Sprintf("%s-%s", c.Parent().Name(), c.Name()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dynamicClient, err := dynamic.NewForConfig(clientConfig)
|
||||
dynamicClient, err := f.DynamicClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue