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

client-go: factor the dynamic client similarly to others #112774

Merged
Merged
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
25 changes: 15 additions & 10 deletions staging/src/k8s.io/client-go/dynamic/simple.go
Expand Up @@ -31,11 +31,11 @@ import (
"k8s.io/client-go/rest"
)

type dynamicClient struct {
client *rest.RESTClient
type DynamicClient struct {
client rest.Interface
Copy link
Member

@liggitt liggitt Sep 28, 2022

Choose a reason for hiding this comment

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

+1 on switching this to an interface (and I think +1 on having a constructor that can construct a dynamic client passing in a rest.Interface... though I haven't thought through the use there a lot)

}

var _ Interface = &dynamicClient{}
var _ Interface = &DynamicClient{}

// ConfigFor returns a copy of the provided config with the
// appropriate dynamic client defaults set.
Expand All @@ -50,9 +50,14 @@ func ConfigFor(inConfig *rest.Config) *rest.Config {
return config
}

// NewForConfigOrDie creates a new Interface for the given config and
// New creates a new DynamicClient for the given RESTClient.
func New(c rest.Interface) *DynamicClient {
return &DynamicClient{client: c}
}

// NewForConfigOrDie creates a new DynamicClient for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) Interface {
func NewForConfigOrDie(c *rest.Config) *DynamicClient {
ret, err := NewForConfig(c)
if err != nil {
panic(err)
Expand All @@ -63,7 +68,7 @@ func NewForConfigOrDie(c *rest.Config) Interface {
// NewForConfig creates a new dynamic client or returns an error.
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
// where httpClient was generated with rest.HTTPClientFor(c).
func NewForConfig(inConfig *rest.Config) (Interface, error) {
func NewForConfig(inConfig *rest.Config) (*DynamicClient, error) {
config := ConfigFor(inConfig)

httpClient, err := rest.HTTPClientFor(config)
Expand All @@ -75,7 +80,7 @@ func NewForConfig(inConfig *rest.Config) (Interface, error) {

// NewForConfigAndClient creates a new dynamic client for the given config and http client.
// Note the http client provided takes precedence over the configured transport values.
func NewForConfigAndClient(inConfig *rest.Config, h *http.Client) (Interface, error) {
func NewForConfigAndClient(inConfig *rest.Config, h *http.Client) (*DynamicClient, error) {
config := ConfigFor(inConfig)
// for serializing the options
config.GroupVersion = &schema.GroupVersion{}
Expand All @@ -85,16 +90,16 @@ func NewForConfigAndClient(inConfig *rest.Config, h *http.Client) (Interface, er
if err != nil {
return nil, err
}
return &dynamicClient{client: restClient}, nil
return &DynamicClient{client: restClient}, nil
}

type dynamicResourceClient struct {
client *dynamicClient
client *DynamicClient
namespace string
resource schema.GroupVersionResource
}

func (c *dynamicClient) Resource(resource schema.GroupVersionResource) NamespaceableResourceInterface {
func (c *DynamicClient) Resource(resource schema.GroupVersionResource) NamespaceableResourceInterface {
return &dynamicResourceClient{client: c, resource: resource}
}

Expand Down