Skip to content

deck: add base path plumbing and helper APIs#576

Open
tsj-30 wants to merge 4 commits intokubernetes-sigs:mainfrom
tsj-30:subpath_prow
Open

deck: add base path plumbing and helper APIs#576
tsj-30 wants to merge 4 commits intokubernetes-sigs:mainfrom
tsj-30:subpath_prow

Conversation

@tsj-30
Copy link
Copy Markdown
Contributor

@tsj-30 tsj-30 commented Dec 12, 2025

This change teaches Deck about a configurable base path so it can be served from a sub‑URL without breaking static assets, APIs, or Spyglass. It introduces the --base-path flag, wraps the HTTP mux so requests are stripped/prefixed appropriately, extends template helpers to emit base-aware links, and adds deckURL utilities for the front-end.
This fixes #376.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tsj-30
Once this PR has been reviewed and has the lgtm label, please assign michelle192837 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the area/deck Issues or PRs related to prow's deck component label Dec 12, 2025
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 12, 2025
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @tsj-30. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 12, 2025
@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 12, 2025

Deploy Preview for k8s-prow ready!

Name Link
🔨 Latest commit 61dfbb1
🔍 Latest deploy log https://app.netlify.com/projects/k8s-prow/deploys/69d67ad58cd5840008bd18a9
😎 Deploy Preview https://deploy-preview-576--k8s-prow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@tsj-30
Copy link
Copy Markdown
Contributor Author

tsj-30 commented Dec 12, 2025

CC: @petr-muller , @matthyx
As suggested by Petr, I’ll break this down and raise smaller PRs to fix #376.

@Amulyam24
Copy link
Copy Markdown
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 12, 2025
@tsj-30
Copy link
Copy Markdown
Contributor Author

tsj-30 commented Jan 2, 2026

/retest

@tsj-30
Copy link
Copy Markdown
Contributor Author

tsj-30 commented Jan 2, 2026

Hi @petr-muller ,
Can you PTAL?
Thanks 😄

@tsj-30
Copy link
Copy Markdown
Contributor Author

tsj-30 commented Jan 9, 2026

cc: @loispostula

@loispostula
Copy link
Copy Markdown

@tsj-30 I'm not sure how to test this, I'll try to get a local build working and check

@tsj-30
Copy link
Copy Markdown
Contributor Author

tsj-30 commented Jan 21, 2026

Hi @loispostula,
Did you get a chance to test this, I have completed some additional code changes and looking forward to submit a follow PR if this looks good and merged.
If you need any futher help from my side please let me know.
Thanks!

Comment thread cmd/deck/basepath.go Outdated
@petr-muller
Copy link
Copy Markdown
Contributor

/cc
/hold

I have an in-flight review with some feedback, will post hopefully tomorrow

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 21, 2026
Copy link
Copy Markdown
Contributor

@petr-muller petr-muller left a comment

Choose a reason for hiding this comment

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

My main concern is how well this was tested on the current default case (path is "/")? If the new subpath functionality is not 100% then I don't mind because we can fix it as we go, but the one thing we need to prevent is breaking existing deployments.

Some comments inline

/hold cancel

Comment thread cmd/deck/main.go

func gatherOptions(fs *flag.FlagSet, args ...string) options {
var o options
o.basePath = "/"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: this is redundant with setting a default on L192

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will modify this.

Comment thread cmd/deck/main.go
}

func (o *options) Validate() error {
o.basePath = normalizeBasePath(o.basePath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems redundant with doing the same in gatherOptions

Comment thread cmd/deck/basepath.go
// withBasePath ensures that only requests that begin with the configured base path are handled
// and that downstream handlers only see paths relative to that base path.
func withBasePath(basePath string, handler http.Handler) http.Handler {
basePath = normalizeBasePath(basePath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

another normalizeBasePath call

Comment thread cmd/deck/templates.go
Comment on lines +77 to +78
"deckBasePath": func() string { return o.basePath },
"deckPath": func(p string) string { return o.absolutePath(p) },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How are these consumed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

deckPath is used throughout the templates to prefix links/static asset URLs and nav links.
deckBasePath is used in base.html to set window.prowBasePath. That gets consumed in the frontend JS helpers in urls.ts

Comment thread cmd/deck/basepath.go
Comment on lines +80 to +106
// absolutePath returns the absolute URL path for a given relative path by prepending the
// configured base path. The input is expected to be either "/" or begin with a slash.
func (o options) absolutePath(rel string) string {
if rel == "" {
return ""
}

pathPart := rel
suffix := ""
if idx := strings.IndexAny(rel, "?#"); idx >= 0 {
pathPart = rel[:idx]
suffix = rel[idx:]
}
if pathPart == "" {
pathPart = "/"
}
if !strings.HasPrefix(pathPart, "/") {
pathPart = "/" + pathPart
}
if o.basePath == "/" {
return pathPart + suffix
}
if pathPart == "/" {
return o.basePath + suffix
}
return o.basePath + pathPart + suffix
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's not easy to reason about all path manipulation possibilities, I'd like to have unit tests (also for stripBasePath and normalizeBasePath both to make sure they are correct and to serve as examples of what gets transformed to what.

Copy link
Copy Markdown
Contributor Author

@tsj-30 tsj-30 Feb 1, 2026

Choose a reason for hiding this comment

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

Makes sense — I’ll add unit tests for stripBasePath and normalizeBasePath (including tricky slash + ./.. cases) so we verify correctness and document expected transformations. Will push the code as part of this PR.

Comment thread cmd/deck/basepath.go

// absolutePath returns the absolute URL path for a given relative path by prepending the
// configured base path. The input is expected to be either "/" or begin with a slash.
func (o options) absolutePath(rel string) string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This technically only needs to basePath from options, could the field be a custom string type and the methods would be defined on that? It would make the interface more narrow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that’s possible. I can refactor this so it only depends on options.basePath: introduce a basePath custom string type and move absolutePath (and related helpers) onto it. I’ll push the change as well.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 24, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@tsj-30: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-prow-unit-test 61dfbb1 link true /test pull-prow-unit-test
pull-prow-verify-lint 61dfbb1 link true /test pull-prow-verify-lint
pull-prow-unit-test-race-detector-nonblocking 61dfbb1 link false /test pull-prow-unit-test-race-detector-nonblocking
pull-prow-integration 61dfbb1 link true /test pull-prow-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@tsj-30
Copy link
Copy Markdown
Contributor Author

tsj-30 commented Apr 9, 2026

Fix type error in templates_test.go by adding proper fakeConfigAgent

  • Fix template function call in base.html (remove printf wrapper)
  • Update test expectations to match actual output

Fixes linting failure in pull-prow-verify-lint check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/deck Issues or PRs related to prow's deck component cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot run prow at a subpath

6 participants