From 8380ea755258d7c6d42eb412d6ba2088c06aa830 Mon Sep 17 00:00:00 2001 From: Alexander Zielenski Date: Thu, 10 Nov 2022 15:31:22 -0800 Subject: [PATCH] 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 Kubernetes-commit: 15506553368e26dedddbefe9f8d3890f87585365 --- pkg/apiserver/handler_discovery.go | 2 +- pkg/apiserver/handler_discovery_test.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/apiserver/handler_discovery.go b/pkg/apiserver/handler_discovery.go index 41d6e0be..4b109729 100644 --- a/pkg/apiserver/handler_discovery.go +++ b/pkg/apiserver/handler_discovery.go @@ -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 { diff --git a/pkg/apiserver/handler_discovery_test.go b/pkg/apiserver/handler_discovery_test.go index 2b7a94f5..58528378 100644 --- a/pkg/apiserver/handler_discovery_test.go +++ b/pkg/apiserver/handler_discovery_test.go @@ -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())