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

Properly use custom kubeconfig for all clientsets #1110

Merged
merged 1 commit into from
Aug 9, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions kubectl-minio/cmd/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ func GetKubeClient(path string) (*kubernetes.Clientset, error) {
}

// GetKubeExtensionClient provides k8s client for CRDs
func GetKubeExtensionClient() (*apiextension.Clientset, error) {
func GetKubeExtensionClient(path string) (*apiextension.Clientset, error) {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
if path != "" {
loadingRules.ExplicitPath = path
}
configOverrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)

Expand All @@ -107,8 +110,11 @@ func GetKubeExtensionClient() (*apiextension.Clientset, error) {
}

// GetKubeDynamicClient provides k8s client for CRDs
func GetKubeDynamicClient() (dynamic.Interface, error) {
func GetKubeDynamicClient(path string) (dynamic.Interface, error) {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
if path != "" {
loadingRules.ExplicitPath = path
}
configOverrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)

Expand All @@ -121,8 +127,11 @@ func GetKubeDynamicClient() (dynamic.Interface, error) {
}

// GetKubeOperatorClient provides k8s client for operator
func GetKubeOperatorClient() (*operatorv1.Clientset, error) {
func GetKubeOperatorClient(path string) (*operatorv1.Clientset, error) {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
if path != "" {
loadingRules.ExplicitPath = path
}
configOverrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)

Expand Down
4 changes: 2 additions & 2 deletions kubectl-minio/cmd/tenant-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ func (c *createCmd) validate(args []string) error {
// run initializes local config and installs MinIO Operator to Kubernetes cluster.
func (c *createCmd) run(args []string) error {
// Create operator and kube client
operatorClient, err := helpers.GetKubeOperatorClient()
path, _ := rootCmd.Flags().GetString(kubeconfig)
operatorClient, err := helpers.GetKubeOperatorClient(path)
if err != nil {
return err
}
path, _ := rootCmd.Flags().GetString(kubeconfig)
kubeClient, err := helpers.GetKubeClient(path)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions kubectl-minio/cmd/tenant-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func (d *tenantDeleteCmd) validate(args []string) error {

// run initializes local config and installs MinIO Operator to Kubernetes cluster.
func (d *tenantDeleteCmd) run(args []string) error {
oclient, err := helpers.GetKubeOperatorClient()
path, _ := rootCmd.Flags().GetString(kubeconfig)
oclient, err := helpers.GetKubeOperatorClient(path)
if err != nil {
return err
}
path, _ := rootCmd.Flags().GetString(kubeconfig)
kclient, err := helpers.GetKubeClient(path)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion kubectl-minio/cmd/tenant-expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func (v *expandCmd) validate(args []string) error {
// run initializes local config and installs MinIO Operator to Kubernetes cluster.
func (v *expandCmd) run() error {
// Create operator client
client, err := helpers.GetKubeOperatorClient()
path, _ := rootCmd.Flags().GetString(kubeconfig)
client, err := helpers.GetKubeOperatorClient(path)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion kubectl-minio/cmd/tenant-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func (d *infoCmd) validate(args []string) error {
// run initializes local config and installs MinIO Operator to Kubernetes cluster.
func (d *infoCmd) run(args []string) error {
// Create operator client
oclient, err := helpers.GetKubeOperatorClient()
path, _ := rootCmd.Flags().GetString(kubeconfig)
oclient, err := helpers.GetKubeOperatorClient(path)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion kubectl-minio/cmd/tenant-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (d *listCmd) validate(args []string) error {
// run initializes local config and installs MinIO Operator to Kubernetes cluster.
func (d *listCmd) run(args []string) error {
// Create operator client
oclient, err := helpers.GetKubeOperatorClient()
path, _ := rootCmd.Flags().GetString(kubeconfig)
oclient, err := helpers.GetKubeOperatorClient(path)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions kubectl-minio/cmd/tenant-report.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ func (d *reportCmd) validate(args []string) error {
func (d *reportCmd) run(args []string) error {
// Create operator client
ctx := context.Background()
oclient, err := helpers.GetKubeOperatorClient()

path, _ := rootCmd.Flags().GetString(kubeconfig)
oclient, err := helpers.GetKubeOperatorClient(path)
if err != nil {
return err
}
client, err := helpers.GetKubeClient("")
client, err := helpers.GetKubeClient(path)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion kubectl-minio/cmd/tenant-upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func (u *upgradeCmd) validate(args []string) error {
// run initializes local config and installs MinIO Operator to Kubernetes cluster.
func (u *upgradeCmd) run() error {
// Create operator client
client, err := helpers.GetKubeOperatorClient()

path, _ := rootCmd.Flags().GetString(kubeconfig)
client, err := helpers.GetKubeOperatorClient(path)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion kubectl-minio/cmd/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func newTenantCmd(out io.Writer, errOut io.Writer) *cobra.Command {
Short: "Manage MinIO tenant(s)",
Long: tenantDesc,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
client, err := helpers.GetKubeExtensionClient()
path, _ := rootCmd.Flags().GetString(kubeconfig)
client, err := helpers.GetKubeExtensionClient(path)
if err != nil {
return err
}
Expand Down