func encodeCertPEM(cert *x509.Certificate) []byte {
	block := pem.Block{
		Type:  "CERTIFICATE",
		Bytes: cert.Raw,
	}
	return pem.EncodeToMemory(&block)
}
encodeCertPEM encodes x509 certificate to pem
package kubeconfig
import (
	"bytes"
	"crypto/rsa"
	"crypto/x509"
	"encoding/base64"
	"encoding/pem"
	"fmt"
	"net"
	"strings"
	"text/template"
	vcpki "sigs.k8s.io/cluster-api-provider-nested/virtualcluster/pkg/controller/pki"
)
const (
	kubeconfigTemplate = `
kind: Config
apiVersion: v1
users:
- name: {{ .username }}
  user:
    client-certificate-data: {{ .cert }}
    client-key-data: {{ .key }}
clusters:
- name: {{ .cluster }}
  cluster:
    certificate-authority-data: {{ .ca }}
    server: {{ .master }}
contexts:
- context:
    cluster: {{ .cluster }}
    user: {{ .username }}
  name: default
current-context: default
preferences: {}
`
)
func GenerateKubeconfig(user, clusterName, apiserverDomain string, groups []string, rootCA *vcpki.CrtKeyPair) (string, error) {
	caPair, err := vcpki.NewClientCrtAndKey(user, rootCA, groups)
	if err != nil {
		return "", err
	}
	return generateKubeconfigUseCertAndKey(clusterName,
		[]string{apiserverDomain}, rootCA.Crt, caPair, user)
}