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

Remove bad heuristic path manipulation #16881

Merged
merged 1 commit into from
Nov 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/client/unversioned/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (c *Client) ServerVersion() (*version.Info, error) {

// ServerAPIVersions retrieves and parses the list of API versions the server supports.
func (c *Client) ServerAPIVersions() (*unversioned.APIVersions, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks @krousey. This reminds me we should remove ServerAPIVersions() from typed clients since we have the discovery client now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I? I wasn't sure if it was still in use some where.

Copy link
Member

Choose a reason for hiding this comment

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

I can do the cleaning work. No need to do it in this PR.

body, err := c.Get().UnversionedPath("").Do().Raw()
body, err := c.Get().AbsPath("/api").Do().Raw()
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/unversioned/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *ExtensionsClient) ServerVersion() (*version.Info, error) {
// ServerAPIVersions retrieves and parses the list of experimental API versions the
// server supports.
func (c *ExtensionsClient) ServerAPIVersions() (*unversioned.APIVersions, error) {
body, err := c.Get().UnversionedPath("").Do().Raw()
body, err := c.Get().AbsPath("/apis/extensions").Do().Raw()
if err != nil {
return nil, err
}
Expand Down
17 changes: 0 additions & 17 deletions pkg/client/unversioned/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,6 @@ func (r *Request) NamespaceIfScoped(namespace string, scoped bool) *Request {
return r
}

// UnversionedPath strips the apiVersion from the baseURL before appending segments.
func (r *Request) UnversionedPath(segments ...string) *Request {
if r.err != nil {
return r
}
upath := path.Clean(r.baseURL.Path)
//TODO(jdef) this is a pretty hackish version test
if strings.HasPrefix(path.Base(upath), "v") {
upath = path.Dir(upath)
if upath == "." {
upath = "/"
}
}
r.path = path.Join(append([]string{upath}, segments...)...)
return r
}

// AbsPath overwrites an existing path with the segments provided. Trailing slashes are preserved
// when a single segment is passed.
func (r *Request) AbsPath(segments ...string) *Request {
Expand Down
37 changes: 0 additions & 37 deletions pkg/client/unversioned/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,43 +995,6 @@ func TestVerbs(t *testing.T) {
}
}

func TestUnversionedPath(t *testing.T) {
tt := []struct {
host string
prefix string
unversioned string
expectedPath string
}{
{"", "", "", "/api"},
{"", "", "versions", "/api/versions"},
{"", "/", "", "/"},
{"", "/versions", "", "/versions"},
{"", "/api", "", "/api"},
{"", "/api/vfake", "", "/api/vfake"},
{"", "/api/vfake", "v1beta100", "/api/vfake/v1beta100"},
{"", "/api", "/versions", "/api/versions"},
{"", "/api", "versions", "/api/versions"},
{"", "/a/api", "", "/a/api"},
{"", "/a/api", "/versions", "/a/api/versions"},
{"", "/a/api", "/versions/d/e", "/a/api/versions/d/e"},
{"", "/a/api/vfake", "/versions/d/e", "/a/api/vfake/versions/d/e"},
}
for i, tc := range tt {
c := NewOrDie(&Config{Host: tc.host, Prefix: tc.prefix})
r := c.Post().Prefix("/alpha").UnversionedPath(tc.unversioned)
if r.path != tc.expectedPath {
t.Errorf("test case %d failed: unexpected path: %s, expected %s", i+1, r.path, tc.expectedPath)
}
}
for i, tc := range tt {
c := NewOrDie(&Config{Host: tc.host, Prefix: tc.prefix, Version: "v1"})
r := c.Post().Prefix("/alpha").UnversionedPath(tc.unversioned)
if r.path != tc.expectedPath {
t.Errorf("test case %d failed: unexpected path: %s, expected %s", i+1, r.path, tc.expectedPath)
}
}
}

func TestAbsPath(t *testing.T) {
expectedPath := "/bar/foo"
c := NewOrDie(&Config{})
Expand Down