Skip to content

Commit f466fdd

Browse files
Merge pull request #1885 from bertinatto/fixes-aggregate-discovery
API1835: manifestclient: fixes for aggregated discovery
2 parents 307f9dc + f2ba168 commit f466fdd

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pkg/manifestclient/group_resource_discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (mrt *manifestRoundTripper) getGroupResourceDiscovery(requestInfo *apireque
3030
return ret, err
3131
default:
3232
// TODO can probably do better
33-
return mrt.getLegacyGroupResourceDiscovery(requestInfo)
33+
return nil, fmt.Errorf("unsupported discovery path: %q", requestInfo.Path)
3434
}
3535
}
3636

pkg/manifestclient/read_roundtripper.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (mrt *manifestRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
6767

6868
isDiscovery := isServerGroupResourceDiscovery(requestInfo.Path)
6969
if !requestInfo.IsResourceRequest && !isDiscovery {
70-
return nil, fmt.Errorf("non-resource requests are not supported by this implementation")
70+
return nil, fmt.Errorf("non-resource requests are not supported by this implementation: %q", requestInfo.Path)
7171
}
7272
if len(requestInfo.Subresource) != 0 {
7373
return nil, fmt.Errorf("subresource %v is not supported by this implementation", requestInfo.Subresource)
@@ -113,7 +113,9 @@ func (mrt *manifestRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
113113
return nil, fmt.Errorf("verb %v is not supported by this implementation", requestInfo.Verb)
114114
}
115115

116-
resp := &http.Response{}
116+
resp := &http.Response{
117+
Header: map[string][]string{},
118+
}
117119
switch {
118120
case apierrors.IsNotFound(returnErr):
119121
resp.StatusCode = http.StatusNotFound
@@ -129,7 +131,11 @@ func (mrt *manifestRoundTripper) RoundTrip(req *http.Request) (*http.Response, e
129131
resp.Body = io.NopCloser(bytes.NewReader(returnBody))
130132
// We always return application/json. Avoid clients expecting proto for built-ins.
131133
resp.Header = make(http.Header)
132-
resp.Header.Set("Content-Type", "application/json")
134+
if isDiscovery {
135+
resp.Header.Set("Content-Type", "application/json;as=APIGroupDiscoveryList;v=v2;g=apidiscovery.k8s.io")
136+
} else {
137+
resp.Header.Set("Content-Type", "application/json")
138+
}
133139
}
134140

135141
return resp, nil
@@ -152,6 +158,9 @@ func isServerGroupResourceDiscovery(path string) bool {
152158
if path == "/api" {
153159
return true
154160
}
161+
if path == "/apis" {
162+
return true
163+
}
155164

156165
parts := strings.Split(path, "/")
157166
if len(parts) != 4 {

0 commit comments

Comments
 (0)