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

(1.4 Cherry Pick) [BackendConfig] CDN default cache key policy should be true instead of false #612

Merged
merged 1 commit into from
Jan 16, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions pkg/backends/features/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"reflect"

"github.com/golang/glog"
backendconfigv1beta1 "k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1"
"k8s.io/ingress-gce/pkg/composite"
"k8s.io/ingress-gce/pkg/utils"
)
Expand All @@ -34,7 +33,8 @@ func EnsureCDN(sp utils.ServicePort, be *composite.BackendService) bool {
}
beTemp := &composite.BackendService{}
applyCDNSettings(sp, beTemp)
if !reflect.DeepEqual(beTemp.CdnPolicy, be.CdnPolicy) || beTemp.EnableCDN != be.EnableCDN {
// Only compare CdnPolicy if it was specified.
if (beTemp.CdnPolicy != nil && !reflect.DeepEqual(beTemp.CdnPolicy, be.CdnPolicy)) || beTemp.EnableCDN != be.EnableCDN {
applyCDNSettings(sp, be)
glog.V(2).Infof("Updated CDN settings for service %v/%v.", sp.ID.Service.Namespace, sp.ID.Service.Name)
return true
Expand All @@ -47,22 +47,19 @@ func EnsureCDN(sp utils.ServicePort, be *composite.BackendService) bool {
// made to actually persist the changes.
func applyCDNSettings(sp utils.ServicePort, be *composite.BackendService) {
beConfig := sp.BackendConfig
setCDNDefaults(beConfig)
// Apply the boolean switch
be.EnableCDN = beConfig.Spec.Cdn.Enabled
// Apply the cache key policies
cacheKeyPolicy := beConfig.Spec.Cdn.CachePolicy
be.CdnPolicy = &composite.BackendServiceCdnPolicy{CacheKeyPolicy: &composite.CacheKeyPolicy{}}
be.CdnPolicy.CacheKeyPolicy.IncludeHost = cacheKeyPolicy.IncludeHost
be.CdnPolicy.CacheKeyPolicy.IncludeProtocol = cacheKeyPolicy.IncludeProtocol
be.CdnPolicy.CacheKeyPolicy.IncludeQueryString = cacheKeyPolicy.IncludeQueryString
be.CdnPolicy.CacheKeyPolicy.QueryStringBlacklist = cacheKeyPolicy.QueryStringBlacklist
be.CdnPolicy.CacheKeyPolicy.QueryStringWhitelist = cacheKeyPolicy.QueryStringWhitelist
}

// setCDNDefaults initializes any nil pointers in CDN configuration which ensures that there are defaults for missing sub-types.
func setCDNDefaults(beConfig *backendconfigv1beta1.BackendConfig) {
if beConfig.Spec.Cdn.CachePolicy == nil {
beConfig.Spec.Cdn.CachePolicy = &backendconfigv1beta1.CacheKeyPolicy{}
// Apply the cache key policies if the BackendConfig contains them.
if cacheKeyPolicy != nil {
be.CdnPolicy = &composite.BackendServiceCdnPolicy{CacheKeyPolicy: &composite.CacheKeyPolicy{}}
be.CdnPolicy.CacheKeyPolicy.IncludeHost = cacheKeyPolicy.IncludeHost
be.CdnPolicy.CacheKeyPolicy.IncludeProtocol = cacheKeyPolicy.IncludeProtocol
be.CdnPolicy.CacheKeyPolicy.IncludeQueryString = cacheKeyPolicy.IncludeQueryString
be.CdnPolicy.CacheKeyPolicy.QueryStringBlacklist = cacheKeyPolicy.QueryStringBlacklist
be.CdnPolicy.CacheKeyPolicy.QueryStringWhitelist = cacheKeyPolicy.QueryStringWhitelist
}
// Note that upon creation of a BackendServices, the fields 'IncludeHost',
// 'IncludeProtocol' and 'IncludeQueryString' all default to true if not
// explicitly specified.
}
4 changes: 2 additions & 2 deletions pkg/backends/features/cdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestEnsureCDN(t *testing.T) {
updateExpected: false,
},
{
desc: "cache policies are missing from spec, update needed",
desc: "cache policies are missing from spec, no update needed",
sp: utils.ServicePort{
BackendConfig: &backendconfigv1beta1.BackendConfig{
Spec: backendconfigv1beta1.BackendConfigSpec{
Expand All @@ -69,7 +69,7 @@ func TestEnsureCDN(t *testing.T) {
},
},
},
updateExpected: true,
updateExpected: false,
},
{
desc: "settings are identical, no update needed",
Expand Down