func SplitYAMLDocuments(yamlBytes []byte) ([]byte, []byte, error) {
	gvkListCluster := make([]byte, 0)
	gvkListOther := make([]byte, 0)
	errs := []error{}
	buf := bytes.NewBuffer(yamlBytes)
	reader := utilyaml.NewYAMLReader(bufio.NewReader(buf))
	for {
		typeMetaInfo := runtime.TypeMeta{}
		typeObjectInfo := corev1.ObjectReference{}
		b, err := reader.Read()
		if err == io.EOF {
			break
		} else if err != nil {
			return nil, nil, err
		}
		if len(b) == 0 {
			break
		}
		if err := yaml.Unmarshal(b, &typeMetaInfo); err != nil {
			return nil, nil, err
		}
		if err := yaml.Unmarshal(b, &typeObjectInfo); err != nil {
			return nil, nil, err
		}
		if len(typeMetaInfo.APIVersion) == 0 || len(typeMetaInfo.Kind) == 0 {
			errs = append(errs, errors.New("invalid configuration: kind and apiVersion is mandatory information that needs to be specified in all YAML documents"))
			continue
		}
		fmt.Println("kind", typeMetaInfo.Kind, len(b))
		switch typeMetaInfo.Kind {
		case "Namespace":
		case "ConstraintTemplate", "Constraint":
			fallthrough
		case "ClusterRole":
			fallthrough
		case "ClusterRoleBinding":
			fallthrough
		case "CustomResourceDefinition":
			b = append([]byte("---\n"), b...)
			gvkListCluster = append(gvkListCluster, b...)
		case "MutatingWebhookConfiguration":
			fallthrough
		case "ValidatingWebhookConfiguration":
			configMapBytes, err := createConfigMapWithYAML(b)
			if err != nil {
				return nil, nil, err
			}
			gvkListOther = append(gvkListOther, configMapBytes...)
		default:
			b = append([]byte("---\n"), b...)
			gvkListOther = append(gvkListOther, b...)
		}
	}
	return gvkListCluster, gvkListOther, nil
}
SplitYAMLDocuments reads the YAML bytes per-document, unmarshals the TypeMeta information from each document
and returns a map between the GroupVersionKind of the document and the document bytes
package main
import (
	"bufio"
	"bytes"
	b64 "encoding/base64"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"github.com/pkg/errors"
	"gopkg.in/yaml.v2"
	"k8s.io/api/admissionregistration/v1beta1"
	"k8s.io/apimachinery/pkg/runtime"
	utilyaml "k8s.io/apimachinery/pkg/util/yaml"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/client-go/kubernetes/scheme"
)
func createConfigMapWithYAML(b []byte) ([]byte, error) {
	decode := scheme.Codecs.UniversalDeserializer().Decode
	obj, groupVersionKind, err := decode(b, nil, nil)
	if err != nil {
		return nil, errors.New("Invalid Object")
	}
	name := ""
	namespace := ""
	if groupVersionKind.Kind == "MutatingWebhookConfiguration" {
		name = obj.(*v1beta1.MutatingWebhookConfiguration).Name
		namespace = obj.(*v1beta1.MutatingWebhookConfiguration).Namespace
	}
	if groupVersionKind.Kind == "ValidatingWebhookConfiguration" {
		name = obj.(*v1beta1.ValidatingWebhookConfiguration).Name
		namespace = obj.(*v1beta1.ValidatingWebhookConfiguration).Namespace
	}
	if len(namespace) > 0 {
		namespace = "namespace: " + namespace + "\n"
	}
	sEnc := b64.StdEncoding.EncodeToString(b)
	b = append([]byte("---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n" +
		"  name: " + name + "\n" + namespace +
		"data:\n" +
		"  webhook.yaml: " + sEnc + "\n"))
	return b, nil
}