You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: cert.go
    path of file: ./repos/sealos/controllers/user/controllers/helper/kubeconfig
    
    the code of the file until where you have to start completion: /*
Copyright 2022 cuisongliu@qq.com.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://ww
    
func (c *CertConfig) Apply(config *rest.Config, _ client.Client) (*api.Config, error) {
	// make sure cadata is loaded into config under incluster mode
	if err := rest.LoadTLSFiles(config); err != nil {
		return nil, err
	}
	certs, err := cert.ParseCertsPEM(config.CAData)
	if err != nil {
		return nil, fmt.Errorf("error reading by config:  %s", err.Error())
	}
	caCert := certs[0]
	caKey, err := tryLoadKeyFromDisk(c.caKeyFile)
	if err != nil {
		return nil, fmt.Errorf("load ca key file failed %s", err)
	}
	clientCert, clientKey, err := newCertAndKey(caCert, caKey, c.user, c.groups, c.dnsNames, c.ipAddresses, c.expirationSeconds)
	if err != nil {
		return nil, fmt.Errorf("new client key failed %s", err)
	}
	encodedClientKey, err := keyutil.MarshalPrivateKeyToPEM(clientKey)
	if err != nil {
		return nil, fmt.Errorf("encode client key failed %s", err)
	}
	encodedClientCert := encodeCertPEM(clientCert)
	ctx := fmt.Sprintf("%s@%s", c.user, c.clusterName)
	return &api.Config{
		Clusters: map[string]*api.Cluster{
			c.clusterName: {
				Server:                   GetKubernetesHost(config),
				CertificateAuthorityData: encodeCertPEM(caCert),
			},
		},
		Contexts: map[string]*api.Context{
			ctx: {
				Cluster:   c.clusterName,
				AuthInfo:  c.user,
				Namespace: confighelper.GetUsersNamespace(c.user),
			},
		},
		AuthInfos: map[string]*api.AuthInfo{
			c.user: {
				ClientCertificateData: encodedClientCert,
				ClientKeyData:         encodedClientKey,
			},
		},
		CurrentContext: ctx,
	}, nil
}