Skip to content

fix: correct url for virtual ws #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2025
Merged

fix: correct url for virtual ws #170

merged 3 commits into from
Apr 8, 2025

Conversation

vertex451
Copy link
Member

@vertex451 vertex451 commented Apr 7, 2025

When we create ApiExport, it assigns to virtual workspace url address with external host, which is not resolvable within openmfp cluster.
The solution is to take the host address that is present in kubeconfig and replace original virtual workspace url host.
It works in both cases - in openmpf and outside it.

Also, I added a change for local development - app is not failing in case of kubernetes.graphql.gateway apixexport absence, it starts but prints warning that ApiBindings are not watched.

On-behalf-of: @SAP [email protected]

On-behalf-of: @SAP [email protected]
Signed-off-by: Artem Shcherbatiuk <[email protected]>
@github-actions github-actions bot added the fix label Apr 7, 2025
On-behalf-of: @SAP [email protected]
Signed-off-by: Artem Shcherbatiuk <[email protected]>
@vertex451 vertex451 marked this pull request as ready for review April 7, 2025 09:17
@vertex451 vertex451 requested a review from a team as a code owner April 7, 2025 09:17
@vertex451 vertex451 requested a review from aaronschweig April 7, 2025 09:17
@vertex451 vertex451 self-assigned this Apr 7, 2025
Comment on lines +67 to +78
pathURL, err := url.Parse(pathURLStr)
if err != nil {
return "", errors.Join(ErrInvalidURL, err)
}

path := pathURL.Path

if !strings.HasPrefix(path, "/") {
path = "/" + path
}

return baseURL.ResolveReference(&url.URL{Path: path}).String(), nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you just use url.JoinPath(baseURLStr, pathURL) here instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it does simple concatenation, and instead of:

"https://openmfp-kcp-front-proxy.openmfp-system:8443/services/apiexport/root/kubernetes.graphql.gateway"

It end up with

"https://openmfp-kcp-front-proxy.openmfp-system:8443/clusters/root/https:/kcp.dev.local:8443/services/apiexport/root/kubernetes.graphql.gateway"

(host from second param is not removed)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the ResolveReference call (that was new to me tbh), I would probably do

        finalURL := url.URL{
		Scheme: baseURL.Scheme,
		Host:   baseURL.Host,
		Path:   path,
	}

	return finalURL.String(), nil

because it is more obvious to me. But ResolveReference does more or less the same and covers more edge cases, so we can leave it.

You can add an optional early return after the baseURL parsing that avoids all the stuff whenever the pathURLStr is empty like so:

    if pathURLStr == "" {
        return baseURL.String() + "/", nil
    }

@vertex451 vertex451 requested a review from nexus49 April 7, 2025 16:06
@vertex451 vertex451 enabled auto-merge (squash) April 8, 2025 07:00
Copy link

@pteich pteich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve in general but left some comments/suggestions.

@@ -25,6 +27,9 @@ func TestNewManager(t *testing.T) {
"successful_manager_creation": {isKCPEnabled: false, expectErr: false},
}

log, err := logger.New(logger.DefaultConfig())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as an information in case you are not aware: we also have a testlogger package that can be used to actually check log messages (not necessary here)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, thanks!

return nil, errors.Join(ErrFailedToGetAPIExport, err)
}

log.Warn().Msg(fmt.Sprintf("failed to find %s ApiExport, listener will not watch ApiBinding changes in realtime", appCfg.ApiExportName))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not use structured logging here?

Suggested change
log.Warn().Msg(fmt.Sprintf("failed to find %s ApiExport, listener will not watch ApiBinding changes in realtime", appCfg.ApiExportName))
log.Warn().Str("apiexport", appCfg.ApiExportName).Msg("failed to find ApiExport, listener will not watch ApiBinding changes in realtime"))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add it a new PR

@vertex451 vertex451 merged commit ee018ba into main Apr 8, 2025
11 checks passed
@vertex451 vertex451 deleted the feat/fix-virtual-ws-url branch April 8, 2025 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants