mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-03 07:11:01 +00:00
Merge pull request #32374 from soltysh/e2e_check_resource
Automatic merge from submit-queue Provide an e2e skip helper checking for available resource @janetkuo @dims this is the promised util function, but unfortunately I just learned that dynamic client suffers from the problem I've fixed in the manually written one (https://github.com/kubernetes/kubernetes/pull/29187) I need to look into the dynamic client in that case :/
This commit is contained in:
@@ -434,6 +434,22 @@ func SkipUnlessFederated(c *client.Client) {
|
||||
}
|
||||
}
|
||||
|
||||
func SkipIfMissingResource(clientPool dynamic.ClientPool, gvr unversioned.GroupVersionResource, namespace string) {
|
||||
dynamicClient, err := clientPool.ClientForGroupVersion(gvr.GroupVersion())
|
||||
if err != nil {
|
||||
Failf("Unexpected error getting dynamic client for %v: %v", gvr.GroupVersion(), err)
|
||||
}
|
||||
apiResource := unversioned.APIResource{Name: gvr.Resource, Namespaced: true}
|
||||
_, err = dynamicClient.Resource(&apiResource, namespace).List(&v1.ListOptions{})
|
||||
if err != nil {
|
||||
// not all resources support list, so we ignore those
|
||||
if apierrs.IsMethodNotSupported(err) || apierrs.IsNotFound(err) || apierrs.IsForbidden(err) {
|
||||
Skipf("Could not find %s resource, skipping test: %#v", gvr, err)
|
||||
}
|
||||
Failf("Unexpected error getting %v: %v", gvr, err)
|
||||
}
|
||||
}
|
||||
|
||||
// ProvidersWithSSH are those providers where each node is accessible with SSH
|
||||
var ProvidersWithSSH = []string{"gce", "gke", "aws"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user