Skip to content

Commit

Permalink
Merge pull request #611 from rramkumar1/cdn-bug-fix
Browse files Browse the repository at this point in the history
[BackendConfig] CDN default cache key policy should be true instead of false.
  • Loading branch information
rramkumar1 authored Jan 16, 2019
2 parents 4b36c3a + c7d68cb commit 71a3a75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
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

0 comments on commit 71a3a75

Please sign in to comment.