Skip to content

Commit

Permalink
Check via length
Browse files Browse the repository at this point in the history
  • Loading branch information
ammujumdar-bcom committed Oct 7, 2024
1 parent 202d89d commit 60882f1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,29 @@ func (r *Reconciler) ReconcileOwnerReferences(ctx *pkgctx.WebConsoleRequestConte
return nil
}

// Retrieve the Proxy Address. First, attempt to get it through the API Server DNS Names.
// ProxyAddress first attempts to get the proxy address through the API Server DNS Names.
// If that is unset, though, fall back to using the virtual IP.
func (r *Reconciler) ProxyAddress(ctx *pkgctx.WebConsoleRequestContext) (string, error) {
if !pkgcfg.FromContext(ctx).Features.SimplifiedEnablement {
return r.ProxyAddressFromVirtualIP(ctx)
}

// Attempt to use the API Server DNS Names to get the proxy address.
proxyAddress, err := webconsoleurl.ProxyServiceDNSName(ctx, r)

if err != nil {
return "", fmt.Errorf("failed to get proxy service URL: %w", err)
}

if proxyAddress == "" {
// If no API Server DNS Name exists, fall back to using the virtual IP.
if len(proxyAddress) == 0 {
return r.ProxyAddressFromVirtualIP(ctx)
}

return proxyAddress, nil
}

// Retrieve the virtual IP, which will be used as the Proxy Address.
// ProxyAddressFromVirtualIP retrieves the virtual IP, which will be used as the Proxy Address.
func (r *Reconciler) ProxyAddressFromVirtualIP(ctx *pkgctx.WebConsoleRequestContext) (string, error) {
proxySvc := &corev1.Service{}
proxySvcObjectKey := client.ObjectKey{Name: ProxyAddrServiceName, Namespace: ProxyAddrServiceNamespace}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,29 @@ func (r *Reconciler) ReconcileOwnerReferences(ctx *pkgctx.WebConsoleRequestConte
return nil
}

// Retrieve the Proxy Address. First, attempt to get it through the API Server DNS Names.
// ProxyAddress first attempts to get the proxy address through the API Server DNS Names.
// If that is unset, though, fall back to using the virtual IP.
func (r *Reconciler) ProxyAddress(ctx *pkgctx.WebConsoleRequestContextV1) (string, error) {
if !pkgcfg.FromContext(ctx).Features.SimplifiedEnablement {
return r.ProxyAddressFromVirtualIP(ctx)
}

// Attempt to use the API Server DNS Names to get the proxy address.
proxyAddress, err := webconsoleurl.ProxyServiceDNSName(ctx, r)

if err != nil {
return "", fmt.Errorf("failed to get proxy service URL: %w", err)
}

if proxyAddress == "" {
// If no API Server DNS Name exists, fall back to using the virtual IP.
if len(proxyAddress) == 0 {
return r.ProxyAddressFromVirtualIP(ctx)
}

return proxyAddress, nil
}

// Retrieve the virtual IP, which will be used as the Proxy Address.
// ProxyAddressFromVirtualIP retrieves the virtual IP, which will be used as the Proxy Address.
func (r *Reconciler) ProxyAddressFromVirtualIP(ctx *pkgctx.WebConsoleRequestContextV1) (string, error) {
proxySvc := &corev1.Service{}
proxySvcObjectKey := client.ObjectKey{Name: ProxyAddrServiceName, Namespace: ProxyAddrServiceNamespace}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ require (
github.com/vmware-tanzu/net-operator-api v0.0.0-20240523152550-862e2c4eb0e0
github.com/vmware-tanzu/nsx-operator/pkg/apis v0.0.0-20240902045731-00a14868c72d
github.com/vmware-tanzu/vm-operator/api v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/appplatform v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/byok v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/ncp v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/storage-policy-quota v0.0.0-00010101000000-000000000000
github.com/vmware-tanzu/vm-operator/external/tanzu-topology v0.0.0-00010101000000-000000000000
Expand Down
3 changes: 2 additions & 1 deletion pkg/webconsoleurl/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"context"
"fmt"

"github.com/vmware-tanzu/vm-operator/external/appplatform/api/vmw_v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/vmware-tanzu/vm-operator/external/appplatform/api/vmw_v1alpha1"
)

const (
Expand Down

0 comments on commit 60882f1

Please sign in to comment.