Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change api server service ip to clusterip,port to clusterport #496

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/kubenest/constants/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
ApiServerServiceType = "NodePort"
// APICallRetryInterval defines how long kubeadm should wait before retrying a failed API operation
ApiServerCallRetryInterval = 100 * time.Millisecond
APIServerSVCPortName = "client"

//controlplane etcd
Etcd = "etcd"
Expand Down
17 changes: 9 additions & 8 deletions pkg/kubenest/tasks/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ func runUploadAdminKubeconfig(r workflow.RunData) error {
if err != nil {
return err
}
nodePort := getNodePortFromAPIServerService(service)
endpoint = fmt.Sprintf("https://%s:%d", data.ControlplaneAddress(), nodePort)

clusterPort := getClusterPortFromAPIServerService(service)
clusterIP := service.Spec.ClusterIP
klog.V(4).Infof("UploadAdminKubeconfig get Cluster IP is : %s\n", clusterIP)
endpoint = fmt.Sprintf("https://%s:%d", clusterIP, clusterPort)
kubeconfig, err := buildKubeConfigFromSpec(data, endpoint)
if err != nil {
return err
Expand All @@ -199,18 +200,18 @@ func runUploadAdminKubeconfig(r workflow.RunData) error {
return nil
}

func getNodePortFromAPIServerService(service *corev1.Service) int32 {
var nodePort int32
func getClusterPortFromAPIServerService(service *corev1.Service) int32 {
var clusterPort int32
if service.Spec.Type == corev1.ServiceTypeNodePort {
for _, port := range service.Spec.Ports {
if port.Name != "client" {
if port.Name != constants.APIServerSVCPortName {
continue
}
nodePort = port.NodePort
clusterPort = port.Port
}
}

return nodePort
return clusterPort
}

func buildKubeConfigFromSpec(data InitData, serverURL string) (*clientcmdapi.Config, error) {
Expand Down
Loading