Skip to content

Commit

Permalink
e2e: allow kubeclient to add namespace to resources
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerdev committed Apr 10, 2024
1 parent 25bffb3 commit 38c8d56
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions e2e/internal/kubeclient/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,22 @@ func (c *Kubeclient) Delete(ctx context.Context, objects ...*unstructured.Unstru
}
return nil
}

// PatchNamespace adjusts the namespace of the given object in-place if it is an instance of a namespaced resource.
func (c *Kubeclient) PatchNamespace(namespace string, obj *unstructured.Unstructured) error {
gvk := obj.GroupVersionKind()
resources, err := c.client.DiscoveryClient.ServerResourcesForGroupVersion(gvk.GroupVersion().String())
if err != nil {
return fmt.Errorf("API resources not found for %#v: %w", gvk, err)
}
for _, resource := range resources.APIResources {
if resource.Kind != obj.GetKind() {
continue
}
if resource.Namespaced {
obj.SetNamespace(namespace)
}
return nil
}
return fmt.Errorf("API resource not found for %#v", gvk)
}

0 comments on commit 38c8d56

Please sign in to comment.