mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #73441 from roycaihw/cleanup/remove-swagger-json-endpoints
Remove remaining code for deprecated openapi paths
This commit is contained in:
commit
31c6a2ba35
@ -392,7 +392,7 @@ func (d *DiscoveryClient) OpenAPISchema() (*openapi_v2.Document, error) {
|
||||
if err != nil {
|
||||
if errors.IsForbidden(err) || errors.IsNotFound(err) || errors.IsNotAcceptable(err) {
|
||||
// single endpoint not found/registered in old server, try to fetch old endpoint
|
||||
// TODO(roycaihw): remove this in 1.11
|
||||
// TODO: remove this when kubectl/client-go don't work with 1.9 server
|
||||
data, err = d.restClient.Get().AbsPath("/swagger-2.0.0.pb-v1").Do().Raw()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -113,32 +113,6 @@ func (h handlerTest) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(h.data)
|
||||
}
|
||||
|
||||
type handlerDeprecatedTest struct {
|
||||
etag string
|
||||
data []byte
|
||||
}
|
||||
|
||||
var _ http.Handler = handlerDeprecatedTest{}
|
||||
|
||||
func (h handlerDeprecatedTest) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// old server returns 403 on new endpoint
|
||||
if r.URL.Path == "/openapi/v2" {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
if len(h.etag) > 0 {
|
||||
w.Header().Add("Etag", h.etag)
|
||||
}
|
||||
ifNoneMatches := r.Header["If-None-Match"]
|
||||
for _, match := range ifNoneMatches {
|
||||
if match == h.etag {
|
||||
w.WriteHeader(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
}
|
||||
w.Write(h.data)
|
||||
}
|
||||
|
||||
func assertDownloadedSpec(actualSpec *spec.Swagger, actualEtag string, err error,
|
||||
expectedSpecID string, expectedEtag string) error {
|
||||
if err != nil {
|
||||
@ -178,9 +152,4 @@ func TestDownloadOpenAPISpec(t *testing.T) {
|
||||
actualSpec, actualEtag, _, err = s.Download(
|
||||
handlerTest{data: []byte("{\"id\": \"test\"}"), etag: "etag_test1"}, "etag_test2")
|
||||
assert.NoError(t, assertDownloadedSpec(actualSpec, actualEtag, err, "test", "etag_test1"))
|
||||
|
||||
// Test old server fallback path
|
||||
actualSpec, actualEtag, _, err = s.Download(handlerDeprecatedTest{data: []byte("{\"id\": \"test\"}")}, "")
|
||||
assert.NoError(t, assertDownloadedSpec(actualSpec, actualEtag, err, "test", "\"6E8F849B434D4B98A569B9D7718876E9-356ECAB19D7FBE1336BABB1E70F8F3025050DE218BE78256BE81620681CFC9A268508E542B8B55974E17B2184BBFC8FFFAA577E51BE195D32B3CA2547818ABE4\""))
|
||||
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func etagFor(data []byte) string {
|
||||
return fmt.Sprintf("%s%X\"", locallyGeneratedEtagPrefix, sha512.Sum512(data))
|
||||
}
|
||||
|
||||
// Download downloads openAPI spec from /openapi/v2 or /swagger.json endpoint of the given handler.
|
||||
// Download downloads openAPI spec from /openapi/v2 endpoint of the given handler.
|
||||
// httpStatus is only valid if err == nil
|
||||
func (s *Downloader) Download(handler http.Handler, etag string) (returnSpec *spec.Swagger, newEtag string, httpStatus int, err error) {
|
||||
handler = s.handlerWithUser(handler, &user.DefaultInfo{Name: aggregatorUser})
|
||||
@ -109,23 +109,6 @@ func (s *Downloader) Download(handler http.Handler, etag string) (returnSpec *sp
|
||||
writer := newInMemoryResponseWriter()
|
||||
handler.ServeHTTP(writer, req)
|
||||
|
||||
// single endpoint not found/registered in old server, try to fetch old endpoint
|
||||
// TODO(roycaihw): remove this in 1.11
|
||||
if writer.respCode == http.StatusForbidden || writer.respCode == http.StatusNotFound {
|
||||
req, err = http.NewRequest("GET", "/swagger.json", nil)
|
||||
if err != nil {
|
||||
return nil, "", 0, err
|
||||
}
|
||||
|
||||
// Only pass eTag if it is not generated locally
|
||||
if len(etag) > 0 && !strings.HasPrefix(etag, locallyGeneratedEtagPrefix) {
|
||||
req.Header.Add("If-None-Match", etag)
|
||||
}
|
||||
|
||||
writer = newInMemoryResponseWriter()
|
||||
handler.ServeHTTP(writer, req)
|
||||
}
|
||||
|
||||
switch writer.respCode {
|
||||
case http.StatusNotModified:
|
||||
if len(etag) == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user