Merge pull request #1748 from lonelyCZ/pr-add-context
Add --context for karmadactl init
This commit is contained in:
commit
97d6d64dfd
|
@ -53,6 +53,7 @@ func NewCmdInit(cmdOut io.Writer, parentCommand string) *cobra.Command {
|
|||
flags.StringVarP(&opts.Namespace, "namespace", "n", "karmada-system", "Kubernetes namespace")
|
||||
flags.StringVar(&opts.StorageClassesName, "storage-classes-name", "", "Kubernetes StorageClasses Name")
|
||||
flags.StringVar(&opts.KubeConfig, "kubeconfig", "", "absolute path to the kubeconfig file")
|
||||
flags.StringVar(&opts.Context, "context", "", "The name of the kubeconfig context to use")
|
||||
// etcd
|
||||
flags.StringVarP(&opts.EtcdStorageMode, "etcd-storage-mode", "", "emptyDir",
|
||||
"etcd data storage mode(emptyDir,hostPath,PVC). value is PVC, specify --storage-classes-name")
|
||||
|
|
|
@ -33,7 +33,7 @@ const (
|
|||
|
||||
// InitKarmadaResources Initialize karmada resource
|
||||
func InitKarmadaResources(dir, caBase64, systemNamespace string) error {
|
||||
restConfig, err := utils.RestConfig(filepath.Join(dir, options.KarmadaKubeConfigName))
|
||||
restConfig, err := utils.RestConfig("", filepath.Join(dir, options.KarmadaKubeConfigName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ type CommandInitOption struct {
|
|||
KarmadaAggregatedAPIServerReplicas int32
|
||||
Namespace string
|
||||
KubeConfig string
|
||||
Context string
|
||||
StorageClassesName string
|
||||
KarmadaDataPath string
|
||||
CRDs string
|
||||
|
@ -105,7 +106,7 @@ func (i *CommandInitOption) Complete() error {
|
|||
}
|
||||
}
|
||||
|
||||
restConfig, err := utils.RestConfig(i.KubeConfig)
|
||||
restConfig, err := utils.RestConfig(i.Context, i.KubeConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -9,18 +9,23 @@ import (
|
|||
)
|
||||
|
||||
// RestConfig Kubernetes kubeconfig
|
||||
func RestConfig(kubeconfigPath string) (*rest.Config, error) {
|
||||
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
|
||||
func RestConfig(context, kubeconfigPath string) (*rest.Config, error) {
|
||||
pathOptions := clientcmd.NewDefaultPathOptions()
|
||||
|
||||
loadingRules := *pathOptions.LoadingRules
|
||||
loadingRules.Precedence = pathOptions.GetLoadingPrecedence()
|
||||
loadingRules.ExplicitPath = kubeconfigPath
|
||||
overrides := &clientcmd.ConfigOverrides{
|
||||
CurrentContext: context,
|
||||
}
|
||||
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&loadingRules, overrides)
|
||||
|
||||
restConfig, err := clientConfig.ClientConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.QPS = float32(5.000000)
|
||||
config.Burst = 10
|
||||
config.ContentType = "application/json"
|
||||
config.AcceptContentTypes = "application/json"
|
||||
config.UserAgent = rest.DefaultKubernetesUserAgent()
|
||||
|
||||
return config, err
|
||||
return restConfig, err
|
||||
}
|
||||
|
||||
// NewClientSet Kubernetes ClientSet
|
||||
|
|
Loading…
Reference in New Issue