Skip to content

Commit

Permalink
fix: change api server service ip to clusterip,port to clusterport
Browse files Browse the repository at this point in the history
Signed-off-by: qiuwei <[email protected]>
  • Loading branch information
qiuwei68 committed Apr 29, 2024
1 parent 5eb2ed8 commit 72697c3
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
fmt.Printf("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 72697c3

Please sign in to comment.