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 fa818e0d..04b97539 100644 --- a/clients/rancher/client.go +++ b/clients/rancher/client.go @@ -16,6 +16,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" kubeRKE "github.com/rancher/shepherd/clients/rke" "github.com/rancher/shepherd/pkg/clientbase" @@ -25,7 +26,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" ) @@ -202,7 +202,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 @@ -231,7 +231,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) @@ -243,7 +243,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() diff --git a/extensions/codecoverage/codecoverage.go b/extensions/codecoverage/codecoverage.go index 084d6019..4e49f47d 100644 --- a/extensions/codecoverage/codecoverage.go +++ b/extensions/codecoverage/codecoverage.go @@ -7,6 +7,7 @@ import ( "time" apiv1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1" + rancherDynamic "github.com/rancher/shepherd/clients/dynamic" "github.com/rancher/shepherd/clients/rancher" v1 "github.com/rancher/shepherd/clients/rancher/v1" "github.com/rancher/shepherd/extensions/clusters" @@ -17,7 +18,6 @@ import ( k8sErrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kwait "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/dynamic" ) var podGroupVersionResource = corev1.SchemeGroupVersion.WithResource("pods") @@ -30,7 +30,7 @@ const ( outputDir = "cover" ) -func checkServiceIsRunning(dynamicClient dynamic.Interface) error { +func checkServiceIsRunning(dynamicClient rancherDynamic.Client) error { return kwait.Poll(500*time.Millisecond, 2*time.Minute, func() (done bool, err error) { _, err = dynamicClient.Resource(podGroupVersionResource).Namespace(cattleSystemNameSpace).List(context.Background(), metav1.ListOptions{}) if k8sErrors.IsInternalError(err) || k8sErrors.IsServiceUnavailable(err) { @@ -120,7 +120,7 @@ func KillRancherTestServicesRetrieveCoverage(client *rancher.Client) error { return err } - err = checkServiceIsRunning(dynamicClient) + err = checkServiceIsRunning(*dynamicClient) if err != nil { return err } @@ -169,7 +169,7 @@ func KillAgentTestServicesRetrieveCoverage(client *rancher.Client) error { return err } - err = checkServiceIsRunning(dynamicClient) + err = checkServiceIsRunning(*dynamicClient) if err != nil { return err }