fix aggregated discovery legacy fallback

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
This commit is contained in:
Alexander Zielenski 2022-11-10 15:31:22 -08:00
parent b2c72feca8
commit 1550655336
2 changed files with 5 additions and 2 deletions

View File

@ -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 {

View File

@ -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",
@ -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())