-
Notifications
You must be signed in to change notification settings - Fork 303
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
IAP + CDN #301
IAP + CDN #301
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package features | ||
|
||
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" | ||
) | ||
|
||
// 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. | ||
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 { | ||
applyCDNSettings(sp, be) | ||
glog.V(2).Infof("Updated CDN settings for service %v/%v.", sp.ID.Service.Namespace, sp.ID.Service.Name) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// applyCDNSettings applies the CDN settings specified in the BackendConfig | ||
// to the passed in compute.BackendService. A GCE API call still needs to be | ||
// made to actually persist the changes. | ||
func applyCDNSettings(sp utils.ServicePort, be *composite.BackendService) { | ||
beConfig := sp.BackendConfig | ||
setCDNDefaults(beConfig) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is applying defaults to backendConfig but not backendService, I was confused :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, we apply defaults to the BackendConfig so that in the apply[IAP,CDN]Settings functions we don't have to have ugly nil checks. |
||
// 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{}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious is it valid to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. If the user disabled CDN but provided cache policies, then we will act on it accordingly. |
||
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 == nil { | ||
beConfig.Spec.Cdn = &backendconfigv1beta1.CDNConfig{} | ||
} | ||
if beConfig.Spec.Cdn.CachePolicy == nil { | ||
beConfig.Spec.Cdn.CachePolicy = &backendconfigv1beta1.CacheKeyPolicy{} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth to separate this out to another PR if we can't get this in soon..