Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --context for karmadactl init #1748

Merged
merged 1 commit into from May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/karmadactl/cmdinit/cmdinit.go
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/cmdinit/karmada/deploy.go
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/karmadactl/cmdinit/kubernetes/deploy.go
Expand Up @@ -61,6 +61,7 @@ type CommandInitOption struct {
KarmadaAggregatedAPIServerReplicas int32
Namespace string
KubeConfig string
Context string
StorageClassesName string
KarmadaDataPath string
CRDs string
Expand Down Expand Up @@ -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
}
Expand Down
21 changes: 13 additions & 8 deletions pkg/karmadactl/cmdinit/utils/kubeclient.go
Expand Up @@ -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()
Comment on lines -17 to -21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these deletions have any impact?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should no impacts. They all have default value.

// QPS indicates the maximum QPS to the master from this client.
// If it's zero, the created RESTClient will use DefaultQPS: 5
QPS float32
// Maximum burst for throttle.
// If it's zero, the created RESTClient will use DefaultBurst: 10.
Burst int

// AcceptContentTypes specifies the types the client will accept and is optional.
// If not set, ContentType will be used to define the Accept header
AcceptContentTypes string
// ContentType specifies the wire format used to communicate with the server.
// This value will be set as the Accept header on requests made to the server, and
// as the default content type on any object sent to the server. If not set,
// "application/json" is used.
ContentType string
// GroupVersion is the API version to talk to. Must be provided when initializing
// a RESTClient directly. When initializing a Client, will be set with the default
// code version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason why we set them explicitly? @prodanlabs


return config, err
return restConfig, err
}

// NewClientSet Kubernetes ClientSet
Expand Down