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

Add support for Cloud CDN dynamic compression #2004

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/apis/backendconfig/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type CDNConfig struct {
ServeWhileStale *int64 `json:"serveWhileStale,omitempty"`
SignedUrlCacheMaxAgeSec *int64 `json:"signedUrlCacheMaxAgeSec,omitempty"`
SignedUrlKeys []*SignedUrlKey `json:"signedUrlKeys,omitempty"`
CompressionMode *string `json:"compressionMode,omitempty"`
}

// BypassCacheOnRequestHeader contains configuration for how requests containing specific request
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/backendconfig/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ type OAuthClientCredentials struct {
// CDNConfig contains configuration for CDN-enabled backends.
// +k8s:openapi-gen=true
type CDNConfig struct {
Enabled bool `json:"enabled"`
CachePolicy *CacheKeyPolicy `json:"cachePolicy,omitempty"`
Enabled bool `json:"enabled"`
CachePolicy *CacheKeyPolicy `json:"cachePolicy,omitempty"`
CompressionMode *string `json:"compressionMode,omitempty"`
}

// CacheKeyPolicy contains configuration for how requests to a CDN-enabled backend are cached.
Expand Down
8 changes: 8 additions & 0 deletions pkg/backends/features/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var defaultCdnPolicy = composite.BackendServiceCdnPolicy{
SignedUrlCacheMaxAgeSec: 0,
}

var defaultCompressionMode string = "DISABLED"

// EnsureCDN reads the CDN configuration specified in the ServicePort.BackendConfig
// and applies it to the BackendService. It returns true if there were existing
// settings on the BackendService that were overwritten.
Expand Down Expand Up @@ -206,6 +208,12 @@ func renderConfig(sp utils.ServicePort) *composite.BackendService {
be.CdnPolicy.BypassCacheOnRequestHeaders = bypassCacheOnRequestHeaders
}

if cdnConfig.CompressionMode != nil {
be.CompressionMode = *cdnConfig.CompressionMode
} else {
be.CompressionMode = defaultCompressionMode
}

return be
}

Expand Down
16 changes: 11 additions & 5 deletions pkg/backends/features/cdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import (
)

var (
cacheAllStatic string = "CACHE_ALL_STATIC"
useOriginHeaders string = "USE_ORIGIN_HEADERS"
forceCacheAll string = "FORCE_CACHE_ALL"
cacheAllStatic string = "CACHE_ALL_STATIC"
useOriginHeaders string = "USE_ORIGIN_HEADERS"
forceCacheAll string = "FORCE_CACHE_ALL"
compressionModeAutomatic string = "AUTOMATIC"
compressionModeDisabled string = "DISABLED"
)

func init() {
Expand Down Expand Up @@ -244,12 +246,14 @@ func TestEnsureCDN(t *testing.T) {
{HeaderName: "header"},
},
SignedUrlCacheMaxAgeSec: createInt64(3600),
CompressionMode: &compressionModeDisabled,
},
},
},
},
be: &composite.BackendService{
EnableCDN: true,
EnableCDN: true,
CompressionMode: compressionModeAutomatic,
CdnPolicy: &composite.BackendServiceCdnPolicy{
CacheKeyPolicy: &composite.CacheKeyPolicy{
IncludeHost: true,
Expand Down Expand Up @@ -277,7 +281,8 @@ func TestEnsureCDN(t *testing.T) {
},
updateExpected: false,
beAfter: &composite.BackendService{
EnableCDN: true,
EnableCDN: true,
CompressionMode: compressionModeAutomatic,
CdnPolicy: &composite.BackendServiceCdnPolicy{
CacheKeyPolicy: &composite.CacheKeyPolicy{
IncludeHost: true,
Expand Down Expand Up @@ -363,6 +368,7 @@ func TestEnsureCDN(t *testing.T) {
cdn.ServeWhileStale = createInt64(defCdn.ServeWhileStale)
cdn.RequestCoalescing = createBool(defCdn.RequestCoalescing)
cdn.SignedUrlCacheMaxAgeSec = createInt64(defCdn.SignedUrlCacheMaxAgeSec)
cdn.CompressionMode = &defaultCompressionMode
}).build(),
be: newDefaultBackendService().build(),
updateExpected: false,
Expand Down