Skip to content

Commit

Permalink
fix aggregated discovery legacy fallback
Browse files Browse the repository at this point in the history
due to redesign where we changed from new endpoint to /apis. The expected error was not also changed.

Caught by e2e tests when feature enabled. Should have been caught by unit test first but it was implemented without root /apis. Unit test also fixed

Kubernetes-commit: 15506553368e26dedddbefe9f8d3890f87585365
  • Loading branch information
Alexander Zielenski authored and k8s-publishing-bot committed Nov 10, 2022
1 parent 62030e3 commit 8380ea7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/apiserver/handler_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (dm *discoveryManager) fetchFreshDiscoveryForService(gv metav1.GroupVersion

dm.setCacheEntryForService(info.service, cached)
return &cached, nil
case http.StatusNotFound:
case http.StatusNotAcceptable:
// Discovery Document is not being served at all.
// Fall back to legacy discovery information
if len(gv.Version) == 0 {
Expand Down
5 changes: 4 additions & 1 deletion pkg/apiserver/handler_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func TestRemoveAPIService(t *testing.T) {

func TestLegacyFallback(t *testing.T) {
aggregatedResourceManager := discoveryendpoint.NewResourceManager()
rootAPIsHandler := discovery.NewRootAPIsHandler(discovery.DefaultAddresses{DefaultAddress: "192.168.1.1"}, scheme.Codecs)

legacyGroupHandler := discovery.NewAPIGroupHandler(scheme.Codecs, metav1.APIGroup{
Name: "stable.example.com",
Expand Down Expand Up @@ -262,9 +263,11 @@ func TestLegacyFallback(t *testing.T) {
} else if r.URL.Path == "/apis/stable.example.com/v1" {
// defer to legacy discovery
legacyResourceHandler.ServeHTTP(w, r)
} else if r.URL.Path == "/apis" {
rootAPIsHandler.ServeHTTP(w, r)
} else {
// Unknown url
w.WriteHeader(http.StatusNotFound)
t.Fatalf("unexpected request sent to %v", r.URL.Path)
}
}))
testCtx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 8380ea7

Please sign in to comment.