Skip to content

Commit

Permalink
Merge pull request #496 from qiuwei68/feature_hostports
Browse files Browse the repository at this point in the history
fix: change api server service ip to clusterip,port to clusterport
  • Loading branch information
kosmos-robot authored Apr 29, 2024
2 parents 4cc460c + e5f67a0 commit 8116856
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
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

0 comments on commit 8116856

Please sign in to comment.