Skip to content
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

Allow paths without a leading slash in probes #15681

Merged
merged 1 commit into from
Jan 21, 2025

Conversation

skonto
Copy link
Contributor

@skonto skonto commented Jan 10, 2025

Fixes #15673

Proposed Changes

  • K8s allows that afaik so we should keep the UX.

Release Note

Fixes previously supported probe syntax without a leading slash.

@knative-prow knative-prow bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 10, 2025
Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.83%. Comparing base (19b9a09) to head (0f8e118).
Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15681      +/-   ##
==========================================
+ Coverage   80.78%   80.83%   +0.04%     
==========================================
  Files         222      222              
  Lines       18025    18025              
==========================================
+ Hits        14561    14570       +9     
+ Misses       3092     3085       -7     
+ Partials      372      370       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@skonto
Copy link
Contributor Author

skonto commented Jan 10, 2025

I noticed this warning.

Your workflow is using a version of actions/cache that is scheduled for deprecation, actions/cache@0c45773. Please update your workflow to use either v3 or v4 of actions/cache to avoid interruptions. Learn more: https://github.blog/changelog/2024-12-05-notice-of-upcoming-releases-and-breaking-changes-for-github-actions/#actions-cache-v1-v2-and-actions-toolkit-cache-package-closing-down

cc @dprotaso is this a false positive as the version is v4.0.2?

@skonto
Copy link
Contributor Author

skonto commented Jan 10, 2025

/assign @dprotaso

@skonto skonto changed the title Allow paths without leading slash in probes Allow paths without a leading slash in probes Jan 10, 2025
@skonto
Copy link
Contributor Author

skonto commented Jan 14, 2025

@dprotaso gentle ping.

@skonto skonto added this to the v1.17.0 milestone Jan 14, 2025
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 14, 2025
@skonto skonto force-pushed the allow_paths_without_slash branch from 8821c8f to 0f8e118 Compare January 15, 2025 08:40
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 15, 2025
@@ -111,7 +112,7 @@ var transport = func() *http.Transport {
}()

func getURL(config HTTPProbeConfigOptions) (*url.URL, error) {
return url.Parse(string(config.Scheme) + "://" + net.JoinHostPort(config.Host, config.Port.String()) + config.Path)
return url.Parse(string(config.Scheme) + "://" + net.JoinHostPort(config.Host, config.Port.String()) + "/" + strings.TrimPrefix(config.Path, "/"))
Copy link
Member

Choose a reason for hiding this comment

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

We should just construct a URL struct instead of building a url string and then parsing it.

eg. url.URL handles normalizing the url - see: https://go.dev/play/p/BC7UV63Drih

u1 = url.URL{
	Scheme: "http",
	Path:   "/blah",
	Host:   net.JoinHostPort("host", "port"),
}

Copy link
Member

Choose a reason for hiding this comment

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

oh and lets add a unit test so we don't regress in the future

Copy link
Contributor Author

@skonto skonto Jan 20, 2025

Choose a reason for hiding this comment

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

It is not that straightforward because you need then to validate the url itself. For example the path needs to be cleaned from the query part. The fact that you manually create a url does not mean it is valid. Here is the full url.parse logic and I don't want to copy that, that is the reason I didn't use that in the first place:

func parse(rawURL string, viaRequest bool) (*URL, error) {
	var rest string
	var err error

	if stringContainsCTLByte(rawURL) {
		return nil, errors.New("net/url: invalid control character in URL")
	}

	if rawURL == "" && viaRequest {
		return nil, errors.New("empty url")
	}
	url := new(URL)

	if rawURL == "*" {
		url.Path = "*"
		return url, nil
	}

	// Split off possible leading "http:", "mailto:", etc.
	// Cannot contain escaped characters.
	if url.Scheme, rest, err = getScheme(rawURL); err != nil {
		return nil, err
	}
	url.Scheme = strings.ToLower(url.Scheme)

	if strings.HasSuffix(rest, "?") && strings.Count(rest, "?") == 1 {
		url.ForceQuery = true
		rest = rest[:len(rest)-1]
	} else {
		rest, url.RawQuery, _ = strings.Cut(rest, "?")
	}

	if !strings.HasPrefix(rest, "/") {
		if url.Scheme != "" {
			// We consider rootless paths per RFC 3986 as opaque.
			url.Opaque = rest
			return url, nil
		}
		if viaRequest {
			return nil, errors.New("invalid URI for request")
		}

		// Avoid confusion with malformed schemes, like cache_object:foo/bar.
		// See golang.org/issue/16822.
		//
		// RFC 3986, §3.3:
		// In addition, a URI reference (Section 4.1) may be a relative-path reference,
		// in which case the first path segment cannot contain a colon (":") character.
		if segment, _, _ := strings.Cut(rest, "/"); strings.Contains(segment, ":") {
			// First path segment has colon. Not allowed in relative URL.
			return nil, errors.New("first path segment in URL cannot contain colon")
		}
	}

	if (url.Scheme != "" || !viaRequest && !strings.HasPrefix(rest, "///")) && strings.HasPrefix(rest, "//") {
		var authority string
		authority, rest = rest[2:], ""
		if i := strings.Index(authority, "/"); i >= 0 {
			authority, rest = authority[:i], authority[i:]
		}
		url.User, url.Host, err = parseAuthority(authority)
		if err != nil {
			return nil, err
		}
	} else if url.Scheme != "" && strings.HasPrefix(rest, "/") {
		// OmitHost is set to true when rawURL has an empty host (authority).
		// See golang.org/issue/46059.
		url.OmitHost = true
	}

	// Set Path and, optionally, RawPath.
	// RawPath is a hint of the encoding of Path. We don't want to set it if
	// the default escaping of Path is equivalent, to help make sure that people
	// don't rely on it in general.
	if err := url.setPath(rest); err != nil {
		return nil, err
	}
	return url, nil
}

@dprotaso
Copy link
Member

/lgtm
/approve

Can you add a follow up unit test?

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jan 21, 2025
Copy link

knative-prow bot commented Jan 21, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, skonto

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

The pull request process is described here

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

@skonto
Copy link
Contributor Author

skonto commented Jan 21, 2025

Can you add a follow up unit test?

Sure.

@dprotaso
Copy link
Member

/cherry-pick release-1.16

@dprotaso
Copy link
Member

/cherry-pick release-1.15

@knative-prow-robot
Copy link
Contributor

@dprotaso: once the present PR merges, I will cherry-pick it on top of release-1.16 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.16

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.

@knative-prow-robot
Copy link
Contributor

@dprotaso: once the present PR merges, I will cherry-pick it on top of release-1.15 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.15

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.

@knative-prow knative-prow bot merged commit 1a30e12 into knative:main Jan 21, 2025
68 checks passed
@knative-prow-robot
Copy link
Contributor

@dprotaso: #15681 failed to apply on top of branch "release-1.15":

Applying: Allow paths without leading slash in probes
Using index info to reconstruct a base tree...
M	pkg/queue/health/probe.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/queue/health/probe.go
CONFLICT (content): Merge conflict in pkg/queue/health/probe.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 Allow paths without leading slash in probes

In response to this:

/cherry-pick release-1.15

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.

@knative-prow-robot
Copy link
Contributor

@dprotaso: #15681 failed to apply on top of branch "release-1.16":

Applying: Allow paths without leading slash in probes
Using index info to reconstruct a base tree...
M	pkg/queue/health/probe.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/queue/health/probe.go
CONFLICT (content): Merge conflict in pkg/queue/health/probe.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 Allow paths without leading slash in probes

In response to this:

/cherry-pick release-1.16

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.

@skonto skonto added the kind/bug Categorizes issue or PR as related to a bug. label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in readiness path handling causes parsing error
3 participants