Skip to content

Vendor the dynamic RESTMapper from controller-runtime v0.19 #873

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

Merged
merged 2 commits into from
Feb 25, 2025
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
4 changes: 2 additions & 2 deletions runtime/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

"github.com/fluxcd/cli-utils/pkg/flowcontrol"
)
Expand Down Expand Up @@ -95,7 +94,8 @@ func NewDynamicRESTMapper(restConfig *rest.Config) (meta.RESTMapper, error) {
if err != nil {
return nil, err
}
restMapper, err := apiutil.NewDynamicRESTMapper(restConfig, httpClient)

restMapper, err := NewLazyRESTMapper(restConfig, httpClient)
if err != nil {
return nil, err
}
Expand Down
30 changes: 24 additions & 6 deletions runtime/client/impersonator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
// Impersonator holds the state for impersonating a Kubernetes account.
type Impersonator struct {
rc.Client
statusPoller *polling.StatusPoller
pollingOpts polling.Options
kubeConfigRef *meta.KubeConfigReference
kubeConfigOpts KubeConfigOptions
Expand All @@ -49,19 +48,17 @@ type Impersonator struct {

// NewImpersonator creates an Impersonator from the given arguments.
func NewImpersonator(kubeClient rc.Client,
statusPoller *polling.StatusPoller,
pollingOpts polling.Options,
kubeConfigRef *meta.KubeConfigReference,
kubeConfigOpts KubeConfigOptions,
defaultServiceAccount string,
serviceAccountName string,
namespace string) *Impersonator {
return NewImpersonatorWithScheme(kubeClient, statusPoller, pollingOpts, kubeConfigRef, kubeConfigOpts, defaultServiceAccount, serviceAccountName, namespace, kubeClient.Scheme())
return NewImpersonatorWithScheme(kubeClient, 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,
Expand All @@ -71,7 +68,6 @@ func NewImpersonatorWithScheme(kubeClient rc.Client,
scheme *runtime.Scheme) *Impersonator {
return &Impersonator{
Client: kubeClient,
statusPoller: statusPoller,
pollingOpts: pollingOpts,
kubeConfigRef: kubeConfigRef,
kubeConfigOpts: kubeConfigOpts,
Expand All @@ -94,7 +90,7 @@ func (i *Impersonator) GetClient(ctx context.Context) (rc.Client, *polling.Statu
case i.defaultServiceAccount != "" || i.serviceAccountName != "":
return i.clientForServiceAccountOrDefault()
default:
return i.Client, i.statusPoller, nil
return i.defaultClient()
}
}

Expand Down Expand Up @@ -147,7 +143,29 @@ func (i *Impersonator) clientForServiceAccountOrDefault() (rc.Client, *polling.S

statusPoller := polling.NewStatusPoller(client, restMapper, i.pollingOpts)
return client, statusPoller, err
}

func (i *Impersonator) defaultClient() (rc.Client, *polling.StatusPoller, error) {
restConfig, err := config.GetConfig()
if err != nil {
return nil, nil, err
}

restMapper, err := NewDynamicRESTMapper(restConfig)
if err != nil {
return nil, nil, err
}

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

statusPoller := polling.NewStatusPoller(client, restMapper, i.pollingOpts)
return client, statusPoller, err
}

func (i *Impersonator) clientForKubeConfig(ctx context.Context) (rc.Client, *polling.StatusPoller, error) {
Expand Down
Loading
Loading