@@ -54,17 +54,14 @@ func FromSecret(ctx context.Context, c client.Reader, cluster client.ObjectKey)
5454}
5555
5656// New creates a new Kubeconfig using the cluster name and specified endpoint.
57- func New (clusterName , endpoint string , caCert * x509.Certificate , caKey crypto.Signer , options ... KubeConfigurationOption ) (* api.Config , error ) {
57+ func New (clusterName , endpoint string , caCert * x509.Certificate , caKey crypto.Signer , options ... KubeConfigOption ) (* api.Config , error ) {
5858 cfg := & certs.Config {
5959 CommonName : "kubernetes-admin" ,
6060 Organization : []string {"system:masters" },
6161 Usages : []x509.ExtKeyUsage {x509 .ExtKeyUsageClientAuth },
6262 }
6363
64- userName := fmt .Sprintf ("%s-admin" , clusterName )
65- contextName := fmt .Sprintf ("%s@%s" , userName , clusterName )
66-
67- kubeConfigOptions := & KubeConfigurationOptions {}
64+ kubeConfigOptions := & KubeConfigOptions {}
6865 kubeConfigOptions .ApplyOptions (options )
6966
7067 clientKey , err := certs .NewSigner (kubeConfigOptions .keyEncryptionAlgorithm )
@@ -82,6 +79,9 @@ func New(clusterName, endpoint string, caCert *x509.Certificate, caKey crypto.Si
8279 return nil , errors .Wrap (err , "unable to encode private key" )
8380 }
8481
82+ userName := fmt .Sprintf ("%s-admin" , clusterName )
83+ contextName := fmt .Sprintf ("%s@%s" , userName , clusterName )
84+
8585 return & api.Config {
8686 Clusters : map [string ]* api.Cluster {
8787 clusterName : {
@@ -106,7 +106,7 @@ func New(clusterName, endpoint string, caCert *x509.Certificate, caKey crypto.Si
106106}
107107
108108// CreateSecret creates the Kubeconfig secret for the given cluster.
109- func CreateSecret (ctx context.Context , c client.Client , cluster * clusterv1.Cluster , options ... KubeConfigurationOption ) error {
109+ func CreateSecret (ctx context.Context , c client.Client , cluster * clusterv1.Cluster , options ... KubeConfigOption ) error {
110110 name := util .ObjectKey (cluster )
111111 return CreateSecretWithOwner (ctx , c , name , cluster .Spec .ControlPlaneEndpoint .String (), metav1.OwnerReference {
112112 APIVersion : clusterv1 .GroupVersion .String (),
@@ -117,7 +117,7 @@ func CreateSecret(ctx context.Context, c client.Client, cluster *clusterv1.Clust
117117}
118118
119119// CreateSecretWithOwner creates the Kubeconfig secret for the given cluster name, namespace, endpoint, and owner reference.
120- func CreateSecretWithOwner (ctx context.Context , c client.Client , clusterName client.ObjectKey , endpoint string , owner metav1.OwnerReference , options ... KubeConfigurationOption ) error {
120+ func CreateSecretWithOwner (ctx context.Context , c client.Client , clusterName client.ObjectKey , endpoint string , owner metav1.OwnerReference , options ... KubeConfigOption ) error {
121121 server , err := url .JoinPath ("https://" , endpoint )
122122 if err != nil {
123123 return err
@@ -189,7 +189,7 @@ func NeedsClientCertRotation(configSecret *corev1.Secret, threshold time.Duratio
189189}
190190
191191// RegenerateSecret creates and stores a new Kubeconfig in the given secret.
192- func RegenerateSecret (ctx context.Context , c client.Client , configSecret * corev1.Secret , options ... KubeConfigurationOption ) error {
192+ func RegenerateSecret (ctx context.Context , c client.Client , configSecret * corev1.Secret , options ... KubeConfigOption ) error {
193193 clusterName , _ , err := secret .ParseSecretName (configSecret .Name )
194194 if err != nil {
195195 return errors .Wrap (err , "failed to parse secret name" )
@@ -213,7 +213,7 @@ func RegenerateSecret(ctx context.Context, c client.Client, configSecret *corev1
213213 return c .Update (ctx , configSecret )
214214}
215215
216- func generateKubeconfig (ctx context.Context , c client.Client , clusterName client.ObjectKey , endpoint string , options ... KubeConfigurationOption ) ([]byte , error ) {
216+ func generateKubeconfig (ctx context.Context , c client.Client , clusterName client.ObjectKey , endpoint string , options ... KubeConfigOption ) ([]byte , error ) {
217217 clusterCA , err := secret .GetFromNamespacedName (ctx , c , clusterName , secret .ClusterCA )
218218 if err != nil {
219219 if apierrors .IsNotFound (err ) {
0 commit comments