Skip to content

Commit

Permalink
Properly use custom kubeconfig for all clientsets (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
neoaggelos authored Aug 9, 2022
1 parent 4eac737 commit fa7d800
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 14 deletions.
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 @@ -128,11 +128,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 @@ -77,11 +77,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 @@ -75,7 +75,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 @@ -76,11 +76,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 @@ -82,7 +82,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

0 comments on commit fa7d800

Please sign in to comment.