func stringInSlice(a string, list []string) bool {
	for _, b := range list {
		if b == a {
			return true
		}
	}
	return false
}
Check if a string in slice of strings.
package client
import (
	"fmt"
	"strings"
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"k8s.io/client-go/discovery"
	"k8s.io/client-go/dynamic"
	"k8s.io/client-go/rest"
)
type Config struct {
	Config        *rest.Config
	Namespace     string
	AllNamespaces bool
}
func (c Config) List(resourceName string) ([]unstructured.Unstructured, error) {
	var err error
	var list *unstructured.UnstructuredList
	resource, group, version, err := c.getResourceGroupVersion(resourceName)
	if err != nil {
		return nil, err
	}
	dynamicClient, err := dynamic.NewForConfig(c.Config)
	if err != nil {
		return nil, err
	}
	res := dynamicClient.Resource(schema.GroupVersionResource{
		Group:    group,
		Version:  version,
		Resource: resource.Name,
	})
	if !c.AllNamespaces && len(c.Namespace) > 0 && resource.Namespaced {
		list, err = res.Namespace(c.Namespace).List(v1.ListOptions{})
	} else {
		list, err = res.List(v1.ListOptions{})
	}
	if err != nil {
		return nil, err
	}
	return list.Items, err
}
func (c Config) getResourceGroupVersion(resourceName string) (v1.APIResource, string, string, error) {
	discoveryClient, err := discovery.NewDiscoveryClientForConfig(c.Config)
	if err != nil {
		return v1.APIResource{}, "", "", err
	}
	resources, err := discoveryClient.ServerPreferredResources()
	if err != nil {
		return v1.APIResource{}, "", "", err
	}
	resource := v1.APIResource{}
	resourceList := &v1.APIResourceList{}
	for _, rl := range resources {
		for _, r := range rl.APIResources {
			names := append(r.ShortNames, r.Name)
			if stringInSlice(resourceName, names) {
				resource = r
				resourceList = rl
			}
		}
		if len(resource.Name) > 0 {
			break
		}
	}
	if len(resource.Name) == 0 {
		return v1.APIResource{}, "", "", fmt.Errorf("Failed to find resource")
	}
	group, version := getGroupVersion(resourceList)
	return resource, group, version, nil
}
func getGroupVersion(resourceList *v1.APIResourceList) (string, string) {
	group := ""
	version := ""
	resourceGroupSplit := strings.Split(resourceList.GroupVersion, "/")
	if len(resourceGroupSplit) == 2 {
		group = resourceGroupSplit[0]
		version = resourceGroupSplit[1]
	} else {
		version = resourceGroupSplit[0]
	}
	return group, version
}