From e5585a9e291c8c068e97027297550d00d9c782dc Mon Sep 17 00:00:00 2001 From: Iramis Valentin <85186645+git-ival@users.noreply.github.com> Date: Fri, 5 Jan 2024 17:02:09 +0000 Subject: [PATCH 1/2] update dyn client to use the rancher dynamic client struct types --- clients/dynamic/dynamic.go | 6 +++--- clients/rancher/client.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clients/dynamic/dynamic.go b/clients/dynamic/dynamic.go index b46ec3ec..f2a6f1a5 100644 --- a/clients/dynamic/dynamic.go +++ b/clients/dynamic/dynamic.go @@ -23,7 +23,7 @@ type Client struct { } // NewForConfig creates a new dynamic client or returns an error. -func NewForConfig(ts *session.Session, inConfig *rest.Config) (dynamic.Interface, error) { +func NewForConfig(ts *session.Session, inConfig *rest.Config) (*Client, error) { logrus.Debugf("Dynamic Client Host:%s", inConfig.Host) dynamicClient, err := dynamic.NewForConfig(inConfig) @@ -44,7 +44,7 @@ func NewForConfig(ts *session.Session, inConfig *rest.Config) (dynamic.Interface // Version: "v3", // Resource: "users", // } -func (d *Client) Resource(resource schema.GroupVersionResource) dynamic.NamespaceableResourceInterface { +func (d *Client) Resource(resource schema.GroupVersionResource) *NamespaceableResourceClient { return &NamespaceableResourceClient{ NamespaceableResourceInterface: d.Interface.Resource(resource), ts: d.ts, @@ -59,7 +59,7 @@ type NamespaceableResourceClient struct { } // Namespace returns a dynamic.ResourceInterface that is embedded in ResourceClient, so ultimately its Create is overwritten. -func (d *NamespaceableResourceClient) Namespace(s string) dynamic.ResourceInterface { +func (d *NamespaceableResourceClient) Namespace(s string) *ResourceClient { return &ResourceClient{ ResourceInterface: d.NamespaceableResourceInterface.Namespace(s), ts: d.ts, diff --git a/clients/rancher/client.go b/clients/rancher/client.go index 2e757774..67118745 100644 --- a/clients/rancher/client.go +++ b/clients/rancher/client.go @@ -17,6 +17,7 @@ import ( management "github.com/rancher/shepherd/clients/rancher/generated/management/v3" v1 "github.com/rancher/shepherd/clients/rancher/v1" + rancherDynamic "github.com/rancher/shepherd/clients/dynamic" kubeProvisioning "github.com/rancher/shepherd/clients/provisioning" "github.com/rancher/shepherd/clients/ranchercli" kubeRKE "github.com/rancher/shepherd/clients/rke" @@ -28,7 +29,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/dynamic" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" ) @@ -254,7 +254,7 @@ func (c *Client) GetClusterCatalogClient(clusterID string) (*catalog.Client, err } // GetRancherDynamicClient is a helper function that instantiates a dynamic client to communicate with the rancher host. -func (c *Client) GetRancherDynamicClient() (dynamic.Interface, error) { +func (c *Client) GetRancherDynamicClient() (*rancherDynamic.Client, error) { dynamic, err := frameworkDynamic.NewForConfig(c.Session, c.restConfig) if err != nil { return nil, err @@ -283,7 +283,7 @@ func (c *Client) GetKubeAPIRKEClient() (*kubeRKE.Client, error) { } // GetDownStreamClusterClient is a helper function that instantiates a dynamic client to communicate with a specific cluster. -func (c *Client) GetDownStreamClusterClient(clusterID string) (dynamic.Interface, error) { +func (c *Client) GetDownStreamClusterClient(clusterID string) (*rancherDynamic.Client, error) { restConfig := *c.restConfig restConfig.Host = fmt.Sprintf("https://%s/k8s/clusters/%s", c.restConfig.Host, clusterID) @@ -295,7 +295,7 @@ func (c *Client) GetDownStreamClusterClient(clusterID string) (dynamic.Interface } // SwitchContext is a helper function that changes the current context to `context` and instantiates a dynamic client -func (c *Client) SwitchContext(context string, clientConfig *clientcmd.ClientConfig) (dynamic.Interface, error) { +func (c *Client) SwitchContext(context string, clientConfig *clientcmd.ClientConfig) (*rancherDynamic.Client, error) { overrides := clientcmd.ConfigOverrides{CurrentContext: context} rawConfig, err := (*clientConfig).RawConfig() From 6c67e31617ca3aa9888951c4c5631fa4d667f0f6 Mon Sep 17 00:00:00 2001 From: Iramis Valentin <85186645+git-ival@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:00:17 +0000 Subject: [PATCH 2/2] update dynamic client import naming --- clients/rancher/client.go | 15 +++++++-------- extensions/clusters/import.go | 4 ++-- extensions/kubectl/template.go | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/clients/rancher/client.go b/clients/rancher/client.go index 67118745..b015b952 100644 --- a/clients/rancher/client.go +++ b/clients/rancher/client.go @@ -11,13 +11,12 @@ import ( "github.com/pkg/errors" "github.com/rancher/norman/httperror" - frameworkDynamic "github.com/rancher/shepherd/clients/dynamic" + shepherdDynamic "github.com/rancher/shepherd/clients/dynamic" "github.com/rancher/shepherd/clients/ec2" "github.com/rancher/shepherd/clients/rancher/catalog" management "github.com/rancher/shepherd/clients/rancher/generated/management/v3" v1 "github.com/rancher/shepherd/clients/rancher/v1" - rancherDynamic "github.com/rancher/shepherd/clients/dynamic" kubeProvisioning "github.com/rancher/shepherd/clients/provisioning" "github.com/rancher/shepherd/clients/ranchercli" kubeRKE "github.com/rancher/shepherd/clients/rke" @@ -254,8 +253,8 @@ func (c *Client) GetClusterCatalogClient(clusterID string) (*catalog.Client, err } // GetRancherDynamicClient is a helper function that instantiates a dynamic client to communicate with the rancher host. -func (c *Client) GetRancherDynamicClient() (*rancherDynamic.Client, error) { - dynamic, err := frameworkDynamic.NewForConfig(c.Session, c.restConfig) +func (c *Client) GetRancherDynamicClient() (*shepherdDynamic.Client, error) { + dynamic, err := shepherdDynamic.NewForConfig(c.Session, c.restConfig) if err != nil { return nil, err } @@ -283,11 +282,11 @@ func (c *Client) GetKubeAPIRKEClient() (*kubeRKE.Client, error) { } // GetDownStreamClusterClient is a helper function that instantiates a dynamic client to communicate with a specific cluster. -func (c *Client) GetDownStreamClusterClient(clusterID string) (*rancherDynamic.Client, error) { +func (c *Client) GetDownStreamClusterClient(clusterID string) (*shepherdDynamic.Client, error) { restConfig := *c.restConfig restConfig.Host = fmt.Sprintf("https://%s/k8s/clusters/%s", c.restConfig.Host, clusterID) - dynamic, err := frameworkDynamic.NewForConfig(c.Session, &restConfig) + dynamic, err := shepherdDynamic.NewForConfig(c.Session, &restConfig) if err != nil { return nil, err } @@ -295,7 +294,7 @@ func (c *Client) GetDownStreamClusterClient(clusterID string) (*rancherDynamic.C } // SwitchContext is a helper function that changes the current context to `context` and instantiates a dynamic client -func (c *Client) SwitchContext(context string, clientConfig *clientcmd.ClientConfig) (*rancherDynamic.Client, error) { +func (c *Client) SwitchContext(context string, clientConfig *clientcmd.ClientConfig) (*shepherdDynamic.Client, error) { overrides := clientcmd.ConfigOverrides{CurrentContext: context} rawConfig, err := (*clientConfig).RawConfig() @@ -310,7 +309,7 @@ func (c *Client) SwitchContext(context string, clientConfig *clientcmd.ClientCon return nil, err } - dynamic, err := frameworkDynamic.NewForConfig(c.Session, restConfig) + dynamic, err := shepherdDynamic.NewForConfig(c.Session, restConfig) if err != nil { return nil, err } diff --git a/extensions/clusters/import.go b/extensions/clusters/import.go index 1663cbfe..3c4738c6 100644 --- a/extensions/clusters/import.go +++ b/extensions/clusters/import.go @@ -7,7 +7,7 @@ import ( "github.com/rancher/norman/types" apisV1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1" - "github.com/rancher/shepherd/clients/dynamic" + shepherdDynamic "github.com/rancher/shepherd/clients/dynamic" "github.com/rancher/shepherd/clients/rancher" management "github.com/rancher/shepherd/clients/rancher/generated/management/v3" ext_unstructured "github.com/rancher/shepherd/extensions/unstructured" @@ -89,7 +89,7 @@ func ImportCluster(client *rancher.Client, cluster *apisV1.Cluster, rest *rest.C return err } - downClient, err := dynamic.NewForConfig(ts, rest) + downClient, err := shepherdDynamic.NewForConfig(ts, rest) if err != nil { return err } diff --git a/extensions/kubectl/template.go b/extensions/kubectl/template.go index a0f35f43..3e9c0f3b 100644 --- a/extensions/kubectl/template.go +++ b/extensions/kubectl/template.go @@ -11,7 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/rancher/shepherd/clients/dynamic" + shepherdDynamic "github.com/rancher/shepherd/clients/dynamic" "github.com/rancher/shepherd/extensions/unstructured" "github.com/rancher/shepherd/pkg/wait" rbacv1 "k8s.io/api/rbac/v1" @@ -54,7 +54,7 @@ func CreateJobAndRunKubectlCommands(clusterID, jobname string, job *batchv1.Job, ts := client.Session.NewSession() defer ts.Cleanup() - downClient, err := dynamic.NewForConfig(ts, restConfig) + downClient, err := shepherdDynamic.NewForConfig(ts, restConfig) if err != nil { return err }