Skip to content

Commit

Permalink
Merge pull request #441 from laozc/scheme
Browse files Browse the repository at this point in the history
Set scheme when getting client from kubeconfig
  • Loading branch information
darkowlzz authored Jan 10, 2023
2 parents 25ef474 + f58ab9e commit 946d9ac
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions runtime/client/impersonator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -43,6 +44,7 @@ type Impersonator struct {
defaultServiceAccount string
serviceAccountName string
namespace string
scheme *runtime.Scheme
}

// NewImpersonator creates an Impersonator from the given arguments.
Expand All @@ -54,6 +56,19 @@ func NewImpersonator(kubeClient rc.Client,
defaultServiceAccount string,
serviceAccountName string,
namespace string) *Impersonator {
return NewImpersonatorWithScheme(kubeClient, statusPoller, pollingOpts, kubeConfigRef, kubeConfigOpts, defaultServiceAccount, serviceAccountName, namespace, kubeClient.Scheme())
}

// NewImpersonatorWithScheme creates an Impersonator from the given arguments with a client runtime scheme.
func NewImpersonatorWithScheme(kubeClient rc.Client,
statusPoller *polling.StatusPoller,
pollingOpts polling.Options,
kubeConfigRef *meta.KubeConfigReference,
kubeConfigOpts KubeConfigOptions,
defaultServiceAccount string,
serviceAccountName string,
namespace string,
scheme *runtime.Scheme) *Impersonator {
return &Impersonator{
Client: kubeClient,
statusPoller: statusPoller,
Expand All @@ -63,6 +78,7 @@ func NewImpersonator(kubeClient rc.Client,
defaultServiceAccount: defaultServiceAccount,
serviceAccountName: serviceAccountName,
namespace: namespace,
scheme: scheme,
}
}

Expand Down Expand Up @@ -121,7 +137,10 @@ func (i *Impersonator) clientForServiceAccountOrDefault() (rc.Client, *polling.S
return nil, nil, err
}

client, err := rc.New(restConfig, rc.Options{Mapper: restMapper})
client, err := rc.New(restConfig, rc.Options{
Scheme: i.scheme,
Mapper: restMapper,
})
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -150,7 +169,10 @@ func (i *Impersonator) clientForKubeConfig(ctx context.Context) (rc.Client, *pol
return nil, nil, err
}

client, err := rc.New(restConfig, rc.Options{Mapper: restMapper})
client, err := rc.New(restConfig, rc.Options{
Scheme: i.scheme,
Mapper: restMapper,
})
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 946d9ac

Please sign in to comment.