diff --git a/e2e/internal/kubeclient/deploy.go b/e2e/internal/kubeclient/deploy.go index 028d328f5..3e226d0b3 100644 --- a/e2e/internal/kubeclient/deploy.go +++ b/e2e/internal/kubeclient/deploy.go @@ -491,7 +491,6 @@ func isPodReady(pod *corev1.Pod) bool { } func (c *Kubeclient) resourceInterfaceFor(obj *unstructured.Unstructured) (dynamic.ResourceInterface, error) { - dyn := dynamic.New(c.Client.RESTClient()) gvk := obj.GroupVersionKind() mapping, err := c.restMapper.RESTMapping(gvk.GroupKind(), gvk.Version) @@ -499,7 +498,7 @@ func (c *Kubeclient) resourceInterfaceFor(obj *unstructured.Unstructured) (dynam return nil, fmt.Errorf("getting resource for %#v: %w", gvk, err) } c.log.Info("found mapping", "resource", mapping.Resource) - ri := dyn.Resource(mapping.Resource) + ri := c.dyn.Resource(mapping.Resource) if mapping.Scope.Name() == "namespace" { namespace := obj.GetNamespace() if namespace == "" { diff --git a/e2e/internal/kubeclient/kubeclient.go b/e2e/internal/kubeclient/kubeclient.go index 36e8a4c5f..213e5a842 100644 --- a/e2e/internal/kubeclient/kubeclient.go +++ b/e2e/internal/kubeclient/kubeclient.go @@ -19,6 +19,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" @@ -37,14 +38,14 @@ type Kubeclient struct { restMapper meta.RESTMapper // config is the "Kubeconfig" for the client config *rest.Config + // dyn is a dynamic API client that can work with unstructured resources + dyn *dynamic.DynamicClient } // New creates a new Kubeclient from a given Kubeconfig. func New(config *rest.Config, log *slog.Logger) (*Kubeclient, error) { - client, err := kubernetes.NewForConfig(config) - if err != nil { - return nil, fmt.Errorf("creating kubernetes client: %w", err) - } + client := kubernetes.NewForConfigOrDie(config) + dyn := dynamic.NewForConfigOrDie(config) resources, err := restmapper.GetAPIGroupResources(client.Discovery()) if err != nil { @@ -56,6 +57,7 @@ func New(config *rest.Config, log *slog.Logger) (*Kubeclient, error) { Client: client, config: config, restMapper: restmapper.NewDiscoveryRESTMapper(resources), + dyn: dyn, }, nil }