mirror of
https://github.com/rancher/k3k.git
synced 2026-08-23 22:36:17 +00:00
Refactor kubeconfig URL generation (#938)
* Refactor kubeconfig generation to remove unused port parameter and update related functions * Refactor kubeconfig generation to streamline error handling and remove unused imports * Refactor kubeconfig URL generation functions and deprecate old implementation * restore old behavior * Add 'k3kcli kubeconfig get' command and update documentation * Refactor URL generation by removing deprecated getURLFromService function and updating tests to use new implementation * Fix expected URL for LoadBalancer test case to include hostname * Refactor kubeconfig test documentation to clarify URL generation behavior for ClusterIP, NodePort, and LoadBalancer service types * Refactor kubeconfig URL generation functions to improve clarity and maintainability * Remove deprecated 'k3kcli kubeconfig get' command and update related documentation * Set logger to discard in NewRootCmd for improved logging control * Refactor getURLFromService to streamline ingress key retrieval
This commit is contained in:
@@ -443,7 +443,7 @@ func (c *ClusterReconciler) reconcile(ctx context.Context, cluster *v1beta1.Clus
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.ensureKubeconfigSecret(ctx, cluster, serviceIP, 443); err != nil {
|
||||
if err := c.ensureKubeconfigSecret(ctx, cluster, serviceIP); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -471,13 +471,13 @@ func (c *ClusterReconciler) ensureBootstrapSecret(ctx context.Context, cluster *
|
||||
}
|
||||
|
||||
// ensureKubeconfigSecret will create or update the Secret containing the kubeconfig data from the k3s server
|
||||
func (c *ClusterReconciler) ensureKubeconfigSecret(ctx context.Context, cluster *v1beta1.Cluster, serviceIP string, port int) error {
|
||||
func (c *ClusterReconciler) ensureKubeconfigSecret(ctx context.Context, cluster *v1beta1.Cluster, serviceIP string) error {
|
||||
log := ctrl.LoggerFrom(ctx)
|
||||
log.V(1).Info("Ensuring Kubeconfig Secret")
|
||||
|
||||
adminKubeconfig := kubeconfig.New()
|
||||
|
||||
kubeconfig, err := adminKubeconfig.Generate(ctx, c.Client, cluster, serviceIP, port)
|
||||
kubeconfig, err := adminKubeconfig.Generate(ctx, c.Client, cluster, serviceIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
httpsPort = 443
|
||||
k3sServerPort = 6443
|
||||
etcdPort = 2379
|
||||
httpsPort int32 = 443
|
||||
k3sServerPort int32 = 6443
|
||||
etcdPort int32 = 2379
|
||||
)
|
||||
|
||||
func IngressName(clusterName string) string {
|
||||
|
||||
@@ -32,7 +32,7 @@ func Service(cluster *v1beta1.Cluster) *corev1.Service {
|
||||
Name: "k3s-server-port",
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: httpsPort,
|
||||
TargetPort: intstr.FromInt(k3sServerPort),
|
||||
TargetPort: intstr.FromInt32(k3sServerPort),
|
||||
}
|
||||
|
||||
etcdPort := corev1.ServicePort{
|
||||
@@ -142,7 +142,7 @@ func (s *Server) StatefulServerService() *corev1.Service {
|
||||
Name: "k3s-server-port",
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
Port: httpsPort,
|
||||
TargetPort: intstr.FromInt(k3sServerPort),
|
||||
TargetPort: intstr.FromInt32(k3sServerPort),
|
||||
},
|
||||
{
|
||||
Name: "k3s-etcd-port",
|
||||
|
||||
Reference in New Issue
Block a user