Skip to content

Commit

Permalink
use kurl-proxy-kotsadm nodeport in embedded-cluster installations (#4365
Browse files Browse the repository at this point in the history
)

* use kurl-proxy-kotsadm nodeport in embedded-cluster installations

* fix error message

* find nodePort in either the 'kurl-proxy-kotsadm' or 'admin-console' services
  • Loading branch information
laverya authored Jan 17, 2024
1 parent f8f4479 commit 813ebea
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 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,19 +186,38 @@ 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, "admin-console", metav1.GetOptions{})
kurlProxyPort, err := getAdminConsolePortImpl(ctx, client, "kurl-proxy-kotsadm")
if err != nil {
return -1, fmt.Errorf("failed to get admin-console 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 {
return svc.Spec.Ports[0].NodePort, nil
}

for _, port := range svc.Spec.Ports {
if port.Name == "http" {
return port.NodePort, nil
}
}
return -1, fmt.Errorf("did not find port 'http' in service 'admin-console'")
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 813ebea

Please sign in to comment.