Skip to content

Commit

Permalink
find nodePort in either the 'kurl-proxy-kotsadm' or 'admin-console' s…
Browse files Browse the repository at this point in the history
…ervices
  • Loading branch information
laverya committed Jan 17, 2024
1 parent b358fe1 commit a6b19cb
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pkg/embeddedcluster/node_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/replicatedhq/kots/pkg/embeddedcluster/types"
"github.com/replicatedhq/kots/pkg/k8sutil"
"github.com/replicatedhq/kots/pkg/util"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -185,11 +186,26 @@ func GenerateK0sJoinCommand(ctx context.Context, client kubernetes.Interface, ro
return strings.Join(cmd, " "), nil
}

// gets the port of the 'admin-console' service
// gets the port of the 'admin-console' or 'kurl-proxy-kotsadm' service
func getAdminConsolePort(ctx context.Context, client kubernetes.Interface) (int32, error) {
svc, err := client.CoreV1().Services(util.PodNamespace).Get(ctx, "kurl-proxy-kotsadm", metav1.GetOptions{})
kurlProxyPort, err := getAdminConsolePortImpl(ctx, client, "kurl-proxy-kotsadm")
if err != nil {
return -1, fmt.Errorf("failed to get kurl-proxy-kotsadm service: %w", err)
if errors.IsNotFound(err) {
adminConsolePort, err := getAdminConsolePortImpl(ctx, client, "admin-console")
if err != nil {
return -1, fmt.Errorf("failed to get admin-console port: %w", err)
}
return adminConsolePort, nil
}
return -1, fmt.Errorf("failed to get kurl-proxy-kotsadm port: %w", err)
}
return kurlProxyPort, nil
}

func getAdminConsolePortImpl(ctx context.Context, client kubernetes.Interface, svcName string) (int32, error) {
svc, err := client.CoreV1().Services(util.PodNamespace).Get(ctx, svcName, metav1.GetOptions{})
if err != nil {
return -1, fmt.Errorf("failed to get %s service: %w", svcName, err)
}

if len(svc.Spec.Ports) == 1 {
Expand All @@ -201,7 +217,7 @@ func getAdminConsolePort(ctx context.Context, client kubernetes.Interface) (int3
return port.NodePort, nil
}
}
return -1, fmt.Errorf("did not find port 'http' in service 'kurl-proxy-kotsadm'")
return -1, fmt.Errorf("did not find port 'http' in service '%s'", svcName)
}

// getControllerNodeIP gets the IP of a healthy controller node
Expand Down

0 comments on commit a6b19cb

Please sign in to comment.