Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #90468: Restore cache-control header filter #90470

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions staging/src/k8s.io/apiserver/pkg/server/config.go
Expand Up @@ -680,6 +680,7 @@ func DefaultBuildHandlerChain(apiHandler http.Handler, c *Config) http.Handler {
if c.SecureServing != nil && !c.SecureServing.DisableHTTP2 && c.GoawayChance > 0 {
handler = genericfilters.WithProbabilisticGoaway(handler, c.GoawayChance)
}
handler = genericapifilters.WithCacheControl(handler)
handler = genericfilters.WithPanicRecovery(handler)
return handler
}
Expand Down
46 changes: 46 additions & 0 deletions test/integration/apiserver/apiserver_test.go
Expand Up @@ -215,6 +215,52 @@ func Test4xxStatusCodeInvalidPatch(t *testing.T) {
}
}

func TestCacheControl(t *testing.T) {
masterConfig := framework.NewIntegrationTestMasterConfigWithOptions(&framework.MasterConfigOptions{})
masterConfig.GenericConfig.OpenAPIConfig = framework.DefaultOpenAPIConfig()
master, _, closeFn := framework.RunAMaster(masterConfig)
defer closeFn()

rt, err := restclient.TransportFor(master.GenericAPIServer.LoopbackClientConfig)
if err != nil {
t.Fatal(err)
}

paths := []string{
// untyped
"/",
// health
"/healthz",
// openapi
"/openapi/v2",
// discovery
"/api",
"/api/v1",
"/apis",
"/apis/apps",
"/apis/apps/v1",
// apis
"/api/v1/namespaces",
"/apis/apps/v1/deployments",
}
for _, path := range paths {
t.Run(path, func(t *testing.T) {
req, err := http.NewRequest("GET", master.GenericAPIServer.LoopbackClientConfig.Host+path, nil)
if err != nil {
t.Fatal(err)
}
resp, err := rt.RoundTrip(req)
if err != nil {
t.Fatal(err)
}
cc := resp.Header.Get("Cache-Control")
if !strings.Contains(cc, "private") {
t.Errorf("expected private cache-control, got %q", cc)
}
})
}
}

// Tests that the apiserver returns 202 status code as expected.
func Test202StatusCode(t *testing.T) {
s, clientSet, closeFn := setup(t)
Expand Down