profile
viewpoint

gabihodoroaga/nginx-ntlm-module 32

A nginx module to allow proxying requests with NTLM Authentication.

gabihodoroaga/blog-dynamic-filters 8

A demo project for building dynamic filters in ASP.NET Core using AutoMapper, System.Dynamic.Linq and EntityFramework.

gabihodoroaga/porth 4

A simple secure port redirector

gabihodoroaga/blog-app-secrets 3

A demo project for managing passwords in ASP.NET Core web application.

gabihodoroaga/jinja-csv 3

Use Jinja2 templates to format data from CSV files.

gabihodoroaga/angular-modal-service 1

An example of how to create your own modal dialog system

gabihodoroaga/database-benchmark 1

Seed project to create a custom database benchmark tool

gabihodoroaga/google-auth-library-php 1

Google Auth Library for PHP

gabihodoroaga/nssocket 1

An elegant way to define lightweight protocols on-top of TCP/TLS sockets in node.js

gabihodoroaga/smtp-email-forward 1

A simple smtp server

issue commentadoptium/adoptium-support

Intermittent OpenJDK 11.0.8 (and 11.0.12) Crash in GC

The JVM crashes regularly on GCP VM.

A fatal error has been detected by the Java Runtime Environment:

SIGSEGV (0xb) at pc=0x00007f1b337a470d, pid=96328, tid=96349

JRE version: OpenJDK Runtime Environment Temurin-11.0.13+8 (11.0.13+8) (build 11.0.13+8)

Java VM: OpenJDK 64-Bit Server VM Temurin-11.0.13+8 (11.0.13+8, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)

Problematic frame:

V [libjvm.so+0x7c270d] G1ParScanThreadState::copy_to_survivor_space(InCSetState, oopDesc*, markOopDesc*)+0x36d

Core dump will be written. Default location: Core dumps may be processed with "/sbin/crash_reporter --user=%P:%s:%u:%g:%f" (or dumping to /home/project/test_project/dataflow/ble_to_bigquery/kotlin/app/core.96328)

If you would like to submit a bug report, please visit:

https://github.com/adoptium/adoptium-support/issues

--------------- S U M M A R Y ------------

Command Line: -Dorg.gradle.internal.worker.tmpdir=/home/project/test_project/dataflow/ble_to_bigquery/kotlin/app/build/tmp/test/work -Dorg.gradle.native=false --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 1'

Host: Intel(R) Xeon(R) CPU @ 3.10GHz, 4 cores, 15G, Alpine Linux v3.14 Time: Thu Jan 20 11:52:30 2022 UTC elapsed time: 19.243935 seconds (0d 0h 0m 19s)

kolehey

comment created time in 14 hours

push eventgabihodoroaga/cloud-run-casbin

Gabriel Hodoroaga

commit sha a4c2f657bc755c00bfbf09b82024435108f09c4a

Add authentication and authorization.

view details

push time in 4 days

create barnchgabihodoroaga/cloud-run-casbin

branch : master

created branch time in 20 days

created repositorygabihodoroaga/cloud-run-casbin

Combining "Sign in with Google" with Casbin you can add authentication and authorization to a Cloud Run service.

created time in 20 days

push eventgabihodoroaga/dataflow-e2e-demo

Gabriel Hodoroaga

commit sha 6a5897fe72db3f4d8c299d8a99723729504a0f28

Update readme

view details

push time in 2 months

push eventgabihodoroaga/dataflow-e2e-demo

Gabriel Hodoroaga

commit sha 1c893f55e8ec2a6f1cf4b1438366f699abc52293

Add readme

view details

push time in 2 months

create barnchgabihodoroaga/dataflow-e2e-demo

branch : master

created branch time in 2 months

created repositorygabihodoroaga/dataflow-e2e-demo

A seed and demo about how to do end-to-end testing of a Dataflow pipeline

created time in 2 months

issue commentkubernetes/ingress-gce

Firewall is not configured correctly when using named ports

/reopen The issue is still there.

gabihodoroaga

comment created time in 2 months

push eventcaseywebdev/ingress-gce

Swetha Repakula

commit sha 23145af3b3abde35d59cf13195a3bca254f5c648

Allow users to specify resource url for the nat subnet

view details

Kubernetes Prow Robot

commit sha 28d6d94cf16bbaef7d176d6d53fdecc233c47c41

Merge pull request #1608 from swetharepakula/psc-shared-vpc Allow users to specify resource url for the nat subnet

view details

Gabriel Hodoroaga

commit sha c002ce37f11d844665257b503c80ea114b3346ca

Merge remote-tracking branch 'upstream/master' into backendconfig-cdn-config

view details

push time in 2 months

Pull request review commentkubernetes/ingress-gce

Add missing CDN config options

 package features  import ( 	"reflect"+	"sort"+	"strings" +	"github.com/kr/pretty" 	"k8s.io/ingress-gce/pkg/composite" 	"k8s.io/ingress-gce/pkg/utils" 	"k8s.io/klog" ) +// This values are copied from GCP Load balancer+var defaultCdnPolicy = composite.BackendServiceCdnPolicy{+	CacheKeyPolicy:          &composite.CacheKeyPolicy{IncludeHost: true, IncludeProtocol: true, IncludeQueryString: true},+	CacheMode:               "CACHE_ALL_STATIC",+	ClientTtl:               3600,+	DefaultTtl:              3600,+	MaxTtl:                  86400,+	NegativeCaching:         true,+	RequestCoalescing:       true,+	ServeWhileStale:         86400,+	SignedUrlCacheMaxAgeSec: 0,+}+ // 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 { 	if sp.BackendConfig.Spec.Cdn == nil { 		return false 	}-	beTemp := &composite.BackendService{}-	applyCDNSettings(sp, beTemp)-	// Only compare CdnPolicy if it was specified.-	if (beTemp.CdnPolicy != nil && !reflect.DeepEqual(beTemp.CdnPolicy, be.CdnPolicy)) || beTemp.EnableCDN != be.EnableCDN {-		applyCDNSettings(sp, be)+	klog.V(3).Infof("BackendConfig.Spec.Cdn before merge = %s", prettyPrint(sp.BackendConfig.Spec.Cdn))+	klog.V(3).Infof("CdnPolicy before merge = %+v", prettyPrint(be.CdnPolicy))+	newConfig := renderConfig(sp)+	if hasDiff(newConfig, be) { 		klog.V(2).Infof("Updated CDN settings for service %v/%v.", sp.ID.Service.Namespace, sp.ID.Service.Name)+		applyConfig(newConfig, be) 		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-	// Apply the boolean switch-	be.EnableCDN = beConfig.Spec.Cdn.Enabled-	cacheKeyPolicy := beConfig.Spec.Cdn.CachePolicy-	// 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.+func prettyPrint(a interface{}) string {+	value := pretty.Sprint(a)+	return strings.ReplaceAll(value, "\n", "")+}++type negativeCachePolicySortInterface []*composite.BackendServiceCdnPolicyNegativeCachingPolicy++func (l negativeCachePolicySortInterface) Len() int           { return len(l) }+func (l negativeCachePolicySortInterface) Less(i, j int) bool { return l[i].Code < l[j].Code }+func (l negativeCachePolicySortInterface) Swap(i, j int)      { l[i], l[j] = l[j], l[i] }++func negativeCachingPolicyEqual(x, y []*composite.BackendServiceCdnPolicyNegativeCachingPolicy) bool {++	xSorted := negativeCachePolicySortInterface(append([]*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}, x...))+	ySorted := negativeCachePolicySortInterface(append([]*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}, y...))+	sort.Sort(xSorted)+	sort.Sort(ySorted)++	return reflect.DeepEqual(xSorted, ySorted)+}++func renderConfig(sp utils.ServicePort) *composite.BackendService {+	cdnConfig := sp.BackendConfig.Spec.Cdn+	be := &composite.BackendService{}+	be.EnableCDN = cdnConfig.Enabled++	be.CdnPolicy = &composite.BackendServiceCdnPolicy{}++	if cdnConfig.CachePolicy != nil {+		beCacheKeyPolicy := &composite.CacheKeyPolicy{}+		beCacheKeyPolicy.IncludeHost = cdnConfig.CachePolicy.IncludeHost+		beCacheKeyPolicy.IncludeProtocol = cdnConfig.CachePolicy.IncludeProtocol+		beCacheKeyPolicy.IncludeQueryString = cdnConfig.CachePolicy.IncludeQueryString+		if cdnConfig.CachePolicy.IncludeQueryString {+			if cdnConfig.CachePolicy.QueryStringBlacklist != nil && len(cdnConfig.CachePolicy.QueryStringBlacklist) > 0 {+				beCacheKeyPolicy.QueryStringBlacklist = cdnConfig.CachePolicy.QueryStringBlacklist+			}+			if cdnConfig.CachePolicy.QueryStringWhitelist != nil && len(cdnConfig.CachePolicy.QueryStringWhitelist) > 0 {+				beCacheKeyPolicy.QueryStringWhitelist = cdnConfig.CachePolicy.QueryStringWhitelist+			}+		}+		be.CdnPolicy.CacheKeyPolicy = beCacheKeyPolicy+	} else {+		be.CdnPolicy.CacheKeyPolicy = defaultCdnPolicy.CacheKeyPolicy+	}++	if cdnConfig.CacheMode != nil {+		be.CdnPolicy.CacheMode = *cdnConfig.CacheMode+	} else {+		be.CdnPolicy.CacheMode = defaultCdnPolicy.CacheMode+	}++	if cdnConfig.RequestCoalescing != nil {+		be.CdnPolicy.RequestCoalescing = *cdnConfig.RequestCoalescing+	} else {+		be.CdnPolicy.RequestCoalescing = defaultCdnPolicy.RequestCoalescing+	}++	if cdnConfig.ServeWhileStale != nil {+		be.CdnPolicy.ServeWhileStale = *cdnConfig.ServeWhileStale+	} else {+		be.CdnPolicy.ServeWhileStale = defaultCdnPolicy.ServeWhileStale+	}++	// MaxTtl must be specified with CACHE_ALL_STATIC cache_mode only+	if be.CdnPolicy.CacheMode != "CACHE_ALL_STATIC" {+		be.CdnPolicy.MaxTtl = 0+	} else if cdnConfig.MaxTtl != nil {+		be.CdnPolicy.MaxTtl = *cdnConfig.MaxTtl+		if be.CdnPolicy.MaxTtl == 0 {+			be.CdnPolicy.ForceSendFields = append(be.CdnPolicy.ForceSendFields, "MaxTtl")+		}+	} else {+		be.CdnPolicy.MaxTtl = defaultCdnPolicy.MaxTtl+	}++	// if USE_ORIGIN_HEADERS ClientTtl must be ignored+	if be.CdnPolicy.CacheMode == "USE_ORIGIN_HEADERS" {+		be.CdnPolicy.ClientTtl = 0+	} else if cdnConfig.ClientTtl != nil {+		be.CdnPolicy.ClientTtl = *cdnConfig.ClientTtl+		if be.CdnPolicy.ClientTtl == 0 {+			be.CdnPolicy.ForceSendFields = append(be.CdnPolicy.ForceSendFields, "ClientTtl")+		}+	} else {+		be.CdnPolicy.ClientTtl = defaultCdnPolicy.ClientTtl+	}++	// if USE_ORIGIN_HEADERS DefaultTtl must be ignored+	if be.CdnPolicy.CacheMode == "USE_ORIGIN_HEADERS" {+		be.CdnPolicy.DefaultTtl = 0+	} else if cdnConfig.DefaultTtl != nil {+		be.CdnPolicy.DefaultTtl = *cdnConfig.DefaultTtl+		if be.CdnPolicy.DefaultTtl == 0 {+			be.CdnPolicy.ForceSendFields = append(be.CdnPolicy.ForceSendFields, "DefaultTtl")+		}+	} else {+		be.CdnPolicy.DefaultTtl = defaultCdnPolicy.DefaultTtl+	}++	if cdnConfig.NegativeCaching != nil {+		be.CdnPolicy.NegativeCaching = *cdnConfig.NegativeCaching+	} else {+		be.CdnPolicy.NegativeCaching = defaultCdnPolicy.NegativeCaching+	}++	negativeCachingPolicy := []*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}+	if be.CdnPolicy.NegativeCaching {+		for _, policyRef := range cdnConfig.NegativeCachingPolicy {+			negativeCachingPolicy = append(+				negativeCachingPolicy,+				&composite.BackendServiceCdnPolicyNegativeCachingPolicy{+					Code: policyRef.Code,+					Ttl:  policyRef.Ttl,+				},+			)+		}+	}++	if len(negativeCachingPolicy) > 0 {+		be.CdnPolicy.NegativeCachingPolicy = negativeCachingPolicy+	}++	if cdnConfig.SignedUrlCacheMaxAgeSec != nil {+		be.CdnPolicy.SignedUrlCacheMaxAgeSec = *cdnConfig.SignedUrlCacheMaxAgeSec+	} else {+		be.CdnPolicy.SignedUrlCacheMaxAgeSec = defaultCdnPolicy.SignedUrlCacheMaxAgeSec+	}++	bypassCacheOnRequestHeaders := []*composite.BackendServiceCdnPolicyBypassCacheOnRequestHeader{}+	for _, policyRef := range cdnConfig.BypassCacheOnRequestHeaders {+		bypassCacheOnRequestHeaders = append(+			bypassCacheOnRequestHeaders,+			&composite.BackendServiceCdnPolicyBypassCacheOnRequestHeader{+				HeaderName: policyRef.HeaderName,+			},+		)+	}+	if len(bypassCacheOnRequestHeaders) > 0 {+		be.CdnPolicy.BypassCacheOnRequestHeaders = bypassCacheOnRequestHeaders+	}++	return be+}++func hasDiff(new *composite.BackendService, current *composite.BackendService) bool {++	if new.EnableCDN != current.EnableCDN {+		return true+	}++	if current.CdnPolicy == nil {+		return true+	}++	// In order to use reflect.DeepEqual we need to handle the special cases++	// SignedUrlKeyNames are not handled by this function and must be preserved as they are+	if current.CdnPolicy != nil && current.CdnPolicy.SignedUrlKeyNames != nil {+		new.CdnPolicy.SignedUrlKeyNames = current.CdnPolicy.SignedUrlKeyNames

All the comparisons are done in hasDiff. This part is only sets the value of NegativeCachingPolicy from the current when the values are equal regardless of the order so the reflect.DeepEqual will not fail because of this.

caseywebdev

comment created time in 2 months

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentkubernetes/ingress-gce

Add missing CDN config options

 package features  import ( 	"reflect"+	"sort"+	"strings" +	"github.com/kr/pretty" 	"k8s.io/ingress-gce/pkg/composite" 	"k8s.io/ingress-gce/pkg/utils" 	"k8s.io/klog" ) +// This values are copied from GCP Load balancer+var defaultCdnPolicy = composite.BackendServiceCdnPolicy{+	CacheKeyPolicy:          &composite.CacheKeyPolicy{IncludeHost: true, IncludeProtocol: true, IncludeQueryString: true},+	CacheMode:               "CACHE_ALL_STATIC",+	ClientTtl:               3600,+	DefaultTtl:              3600,+	MaxTtl:                  86400,+	NegativeCaching:         true,+	RequestCoalescing:       true,+	ServeWhileStale:         86400,+	SignedUrlCacheMaxAgeSec: 0,+}+ // 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 { 	if sp.BackendConfig.Spec.Cdn == nil { 		return false 	}-	beTemp := &composite.BackendService{}-	applyCDNSettings(sp, beTemp)-	// Only compare CdnPolicy if it was specified.-	if (beTemp.CdnPolicy != nil && !reflect.DeepEqual(beTemp.CdnPolicy, be.CdnPolicy)) || beTemp.EnableCDN != be.EnableCDN {-		applyCDNSettings(sp, be)+	klog.V(3).Infof("BackendConfig.Spec.Cdn before merge = %s", prettyPrint(sp.BackendConfig.Spec.Cdn))+	klog.V(3).Infof("CdnPolicy before merge = %+v", prettyPrint(be.CdnPolicy))+	newConfig := renderConfig(sp)+	if hasDiff(newConfig, be) { 		klog.V(2).Infof("Updated CDN settings for service %v/%v.", sp.ID.Service.Namespace, sp.ID.Service.Name)+		applyConfig(newConfig, be) 		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-	// Apply the boolean switch-	be.EnableCDN = beConfig.Spec.Cdn.Enabled-	cacheKeyPolicy := beConfig.Spec.Cdn.CachePolicy-	// 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.+func prettyPrint(a interface{}) string {+	value := pretty.Sprint(a)+	return strings.ReplaceAll(value, "\n", "")+}++type negativeCachePolicySortInterface []*composite.BackendServiceCdnPolicyNegativeCachingPolicy++func (l negativeCachePolicySortInterface) Len() int           { return len(l) }+func (l negativeCachePolicySortInterface) Less(i, j int) bool { return l[i].Code < l[j].Code }+func (l negativeCachePolicySortInterface) Swap(i, j int)      { l[i], l[j] = l[j], l[i] }++func negativeCachingPolicyEqual(x, y []*composite.BackendServiceCdnPolicyNegativeCachingPolicy) bool {++	xSorted := negativeCachePolicySortInterface(append([]*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}, x...))+	ySorted := negativeCachePolicySortInterface(append([]*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}, y...))+	sort.Sort(xSorted)+	sort.Sort(ySorted)++	return reflect.DeepEqual(xSorted, ySorted)+}++func renderConfig(sp utils.ServicePort) *composite.BackendService {+	cdnConfig := sp.BackendConfig.Spec.Cdn+	be := &composite.BackendService{}+	be.EnableCDN = cdnConfig.Enabled++	be.CdnPolicy = &composite.BackendServiceCdnPolicy{}++	if cdnConfig.CachePolicy != nil {+		beCacheKeyPolicy := &composite.CacheKeyPolicy{}+		beCacheKeyPolicy.IncludeHost = cdnConfig.CachePolicy.IncludeHost+		beCacheKeyPolicy.IncludeProtocol = cdnConfig.CachePolicy.IncludeProtocol+		beCacheKeyPolicy.IncludeQueryString = cdnConfig.CachePolicy.IncludeQueryString+		if cdnConfig.CachePolicy.IncludeQueryString {+			if cdnConfig.CachePolicy.QueryStringBlacklist != nil && len(cdnConfig.CachePolicy.QueryStringBlacklist) > 0 {+				beCacheKeyPolicy.QueryStringBlacklist = cdnConfig.CachePolicy.QueryStringBlacklist+			}+			if cdnConfig.CachePolicy.QueryStringWhitelist != nil && len(cdnConfig.CachePolicy.QueryStringWhitelist) > 0 {+				beCacheKeyPolicy.QueryStringWhitelist = cdnConfig.CachePolicy.QueryStringWhitelist

Done.

caseywebdev

comment created time in 2 months

Pull request review commentkubernetes/ingress-gce

Add missing CDN config options

 package features  import ( 	"reflect"+	"sort"+	"strings" +	"github.com/kr/pretty" 	"k8s.io/ingress-gce/pkg/composite" 	"k8s.io/ingress-gce/pkg/utils" 	"k8s.io/klog" ) +// This values are copied from GCP Load balancer+var defaultCdnPolicy = composite.BackendServiceCdnPolicy{+	CacheKeyPolicy:          &composite.CacheKeyPolicy{IncludeHost: true, IncludeProtocol: true, IncludeQueryString: true},+	CacheMode:               "CACHE_ALL_STATIC",+	ClientTtl:               3600,+	DefaultTtl:              3600,+	MaxTtl:                  86400,+	NegativeCaching:         true,+	RequestCoalescing:       true,+	ServeWhileStale:         86400,+	SignedUrlCacheMaxAgeSec: 0,+}+ // 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 { 	if sp.BackendConfig.Spec.Cdn == nil { 		return false 	}-	beTemp := &composite.BackendService{}-	applyCDNSettings(sp, beTemp)-	// Only compare CdnPolicy if it was specified.-	if (beTemp.CdnPolicy != nil && !reflect.DeepEqual(beTemp.CdnPolicy, be.CdnPolicy)) || beTemp.EnableCDN != be.EnableCDN {-		applyCDNSettings(sp, be)+	klog.V(3).Infof("BackendConfig.Spec.Cdn before merge = %s", prettyPrint(sp.BackendConfig.Spec.Cdn))+	klog.V(3).Infof("CdnPolicy before merge = %+v", prettyPrint(be.CdnPolicy))+	newConfig := renderConfig(sp)+	if hasDiff(newConfig, be) { 		klog.V(2).Infof("Updated CDN settings for service %v/%v.", sp.ID.Service.Namespace, sp.ID.Service.Name)+		applyConfig(newConfig, be) 		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-	// Apply the boolean switch-	be.EnableCDN = beConfig.Spec.Cdn.Enabled-	cacheKeyPolicy := beConfig.Spec.Cdn.CachePolicy-	// 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.+func prettyPrint(a interface{}) string {+	value := pretty.Sprint(a)+	return strings.ReplaceAll(value, "\n", "")+}++type negativeCachePolicySortInterface []*composite.BackendServiceCdnPolicyNegativeCachingPolicy++func (l negativeCachePolicySortInterface) Len() int           { return len(l) }+func (l negativeCachePolicySortInterface) Less(i, j int) bool { return l[i].Code < l[j].Code }+func (l negativeCachePolicySortInterface) Swap(i, j int)      { l[i], l[j] = l[j], l[i] }++func negativeCachingPolicyEqual(x, y []*composite.BackendServiceCdnPolicyNegativeCachingPolicy) bool {++	xSorted := negativeCachePolicySortInterface(append([]*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}, x...))+	ySorted := negativeCachePolicySortInterface(append([]*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}, y...))+	sort.Sort(xSorted)+	sort.Sort(ySorted)++	return reflect.DeepEqual(xSorted, ySorted)+}++func renderConfig(sp utils.ServicePort) *composite.BackendService {+	cdnConfig := sp.BackendConfig.Spec.Cdn+	be := &composite.BackendService{}+	be.EnableCDN = cdnConfig.Enabled++	be.CdnPolicy = &composite.BackendServiceCdnPolicy{}++	if cdnConfig.CachePolicy != nil {+		beCacheKeyPolicy := &composite.CacheKeyPolicy{}+		beCacheKeyPolicy.IncludeHost = cdnConfig.CachePolicy.IncludeHost+		beCacheKeyPolicy.IncludeProtocol = cdnConfig.CachePolicy.IncludeProtocol+		beCacheKeyPolicy.IncludeQueryString = cdnConfig.CachePolicy.IncludeQueryString+		if cdnConfig.CachePolicy.IncludeQueryString {+			if cdnConfig.CachePolicy.QueryStringBlacklist != nil && len(cdnConfig.CachePolicy.QueryStringBlacklist) > 0 {

Done.

caseywebdev

comment created time in 2 months

PullRequestReviewEvent

push eventcaseywebdev/ingress-gce

Gabriel Hodoroaga

commit sha bc8cdf88687990ab8909d08f2dba2c726e4c40a3

Add code comments

view details

push time in 2 months

pull request commentkubernetes/ingress-gce

Add missing CDN config options

@bowei Thank you for the review. I know that by approving this PR you are assuming a big responsibility and I appreciate all your effort.

caseywebdev

comment created time in 2 months

Pull request review commentkubernetes/ingress-gce

Add missing CDN config options

 func (crud *BackendConfigCRUD) Update(bc *v1.BackendConfig) (*v1.BackendConfig, 	return toV1(legacyBC), err } +// Ensure creates or updates the backend config+func (crud *BackendConfigCRUD) Ensure(bc *v1.BackendConfig) (*v1.BackendConfig, error) {

It is part of the e2e package.

caseywebdev

comment created time in 2 months

PullRequestReviewEvent

Pull request review commentkubernetes/ingress-gce

Add missing CDN config options

 func ({{$type.VarName}} *{{$type.Name}}) To{{$version}}() (*compute{{$extension}  	{{- if eq $type.Name "BackendService"}} 	// Set force send fields. This is a temporary hack.-	if {{$lower}}.CdnPolicy != nil && {{$lower}}.CdnPolicy.CacheKeyPolicy != nil {+	if {{$lower}}.CdnPolicy != nil { +		if {{$lower}}.CdnPolicy.CacheKeyPolicy != nil { 		{{$lower}}.CdnPolicy.CacheKeyPolicy.ForceSendFields = []string{"IncludeHost", "IncludeProtocol", "IncludeQueryString", "QueryStringBlacklist", "QueryStringWhitelist"}+		}+		{{$lower}}.CdnPolicy.ForceSendFields = append({{$type.VarName}}.CdnPolicy.ForceSendFields, []string{"NegativeCaching", "RequestCoalescing","SignedUrlCacheMaxAgeSec","ServeWhileStale"}...)

Yes. Otherwise empty values are not cleared from the backend.

caseywebdev

comment created time in 2 months

PullRequestReviewEvent

Pull request review commentkubernetes/ingress-gce

Add missing CDN config options

 func (s *backendSyncer) ensureBackendService(sp utils.ServicePort) error { 		} 	} +	// Sync SignedUrlKeys. Why here? This is the only place where I have access to the key values (sp)

Refactored on its own func. We cannot put this inside EnsureCDN because composite.BackendService.CdnPolicy.SignedUrlKeyNames contains only the keys names ([]string) and we cannot pass the information about the keys values, and what keys needs to be added or removed. Updating the backend inside EnsureCDN does not match the current pattern.

caseywebdev

comment created time in 2 months

PullRequestReviewEvent

Pull request review commentkubernetes/ingress-gce

Add missing CDN config options

 func (s *backendSyncer) ensureBackendService(sp utils.ServicePort) error { 		} 	} +	// Sync SignedUrlKeys. Why here? This is the only place where I have access to the key values (sp)+	existingKeyNames := map[string]bool{}+	if be.CdnPolicy != nil && be.CdnPolicy.SignedUrlKeyNames != nil {+		for _, key := range be.CdnPolicy.SignedUrlKeyNames {+			existingKeyNames[key] = false+		}+	}+	// there is a hard limit of maximum 3 keys per bakend, if you add before remove you will hit the limit+	// find existing and the new keys first+	newSignedUrlKeys := []*composite.SignedUrlKey{}+	if sp.BackendConfig != nil && sp.BackendConfig.Spec.Cdn != nil && sp.BackendConfig.Spec.Cdn.SignedUrlKeys != nil {+		for _, key := range sp.BackendConfig.Spec.Cdn.SignedUrlKeys {+			klog.V(5).Infof("Search for SignedUrlKey %q in backend %q", key.KeyName, be.Name)+			if _, found := existingKeyNames[key.KeyName]; !found {+				newSignedUrlKeys = append(newSignedUrlKeys, &composite.SignedUrlKey{KeyName: key.KeyName, KeyValue: key.KeyValue})+			} else {+				klog.V(5).Infof("SignedUrlKey %q found on backend %q, no update needed", key.KeyName, be.Name)+				existingKeyNames[key.KeyName] = true+			}+		}+	}+	// delete all removed keys+	for keyName, found := range existingKeyNames {+		if !found {+			klog.V(5).Infof("Removing SignedUrlKey %q from backend %q", keyName, be.Name)+			if err = s.backendPool.DeleteSignedUrlKey(be, keyName); err != nil {+				return err+			}+		}+	}+	// add all apended keys

Done.

caseywebdev

comment created time in 2 months

PullRequestReviewEvent

Pull request review commentkubernetes/ingress-gce

Add missing CDN config options

 func (s *backendSyncer) ensureBackendService(sp utils.ServicePort) error { 		} 	} +	// Sync SignedUrlKeys. Why here? This is the only place where I have access to the key values (sp)+	existingKeyNames := map[string]bool{}+	if be.CdnPolicy != nil && be.CdnPolicy.SignedUrlKeyNames != nil {+		for _, key := range be.CdnPolicy.SignedUrlKeyNames {+			existingKeyNames[key] = false+		}+	}+	// there is a hard limit of maximum 3 keys per bakend, if you add before remove you will hit the limit

Done.

caseywebdev

comment created time in 2 months

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentkubernetes/ingress-gce

Add missing CDN config options

 package features  import ( 	"reflect"+	"sort"+	"strings" +	"github.com/kr/pretty" 	"k8s.io/ingress-gce/pkg/composite" 	"k8s.io/ingress-gce/pkg/utils" 	"k8s.io/klog" ) +// This values are copied from GCP Load balancer+var defaultCdnPolicy = composite.BackendServiceCdnPolicy{+	CacheKeyPolicy:          &composite.CacheKeyPolicy{IncludeHost: true, IncludeProtocol: true, IncludeQueryString: true},+	CacheMode:               "CACHE_ALL_STATIC",+	ClientTtl:               3600,+	DefaultTtl:              3600,+	MaxTtl:                  86400,+	NegativeCaching:         true,+	RequestCoalescing:       true,+	ServeWhileStale:         86400,+	SignedUrlCacheMaxAgeSec: 0,+}+ // 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 { 	if sp.BackendConfig.Spec.Cdn == nil { 		return false 	}-	beTemp := &composite.BackendService{}-	applyCDNSettings(sp, beTemp)-	// Only compare CdnPolicy if it was specified.-	if (beTemp.CdnPolicy != nil && !reflect.DeepEqual(beTemp.CdnPolicy, be.CdnPolicy)) || beTemp.EnableCDN != be.EnableCDN {-		applyCDNSettings(sp, be)+	klog.V(3).Infof("BackendConfig.Spec.Cdn before merge = %s", prettyPrint(sp.BackendConfig.Spec.Cdn))+	klog.V(3).Infof("CdnPolicy before merge = %+v", prettyPrint(be.CdnPolicy))+	newConfig := renderConfig(sp)+	if hasDiff(newConfig, be) { 		klog.V(2).Infof("Updated CDN settings for service %v/%v.", sp.ID.Service.Namespace, sp.ID.Service.Name)+		applyConfig(newConfig, be) 		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-	// Apply the boolean switch-	be.EnableCDN = beConfig.Spec.Cdn.Enabled-	cacheKeyPolicy := beConfig.Spec.Cdn.CachePolicy-	// 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.+func prettyPrint(a interface{}) string {+	value := pretty.Sprint(a)+	return strings.ReplaceAll(value, "\n", "")+}++type negativeCachePolicySortInterface []*composite.BackendServiceCdnPolicyNegativeCachingPolicy++func (l negativeCachePolicySortInterface) Len() int           { return len(l) }+func (l negativeCachePolicySortInterface) Less(i, j int) bool { return l[i].Code < l[j].Code }+func (l negativeCachePolicySortInterface) Swap(i, j int)      { l[i], l[j] = l[j], l[i] }++func negativeCachingPolicyEqual(x, y []*composite.BackendServiceCdnPolicyNegativeCachingPolicy) bool {++	xSorted := negativeCachePolicySortInterface(append([]*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}, x...))+	ySorted := negativeCachePolicySortInterface(append([]*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}, y...))+	sort.Sort(xSorted)+	sort.Sort(ySorted)++	return reflect.DeepEqual(xSorted, ySorted)+}++func renderConfig(sp utils.ServicePort) *composite.BackendService {+	cdnConfig := sp.BackendConfig.Spec.Cdn+	be := &composite.BackendService{}+	be.EnableCDN = cdnConfig.Enabled++	be.CdnPolicy = &composite.BackendServiceCdnPolicy{}++	if cdnConfig.CachePolicy != nil {+		beCacheKeyPolicy := &composite.CacheKeyPolicy{}+		beCacheKeyPolicy.IncludeHost = cdnConfig.CachePolicy.IncludeHost+		beCacheKeyPolicy.IncludeProtocol = cdnConfig.CachePolicy.IncludeProtocol+		beCacheKeyPolicy.IncludeQueryString = cdnConfig.CachePolicy.IncludeQueryString+		if cdnConfig.CachePolicy.IncludeQueryString {+			if cdnConfig.CachePolicy.QueryStringBlacklist != nil && len(cdnConfig.CachePolicy.QueryStringBlacklist) > 0 {+				beCacheKeyPolicy.QueryStringBlacklist = cdnConfig.CachePolicy.QueryStringBlacklist+			}+			if cdnConfig.CachePolicy.QueryStringWhitelist != nil && len(cdnConfig.CachePolicy.QueryStringWhitelist) > 0 {+				beCacheKeyPolicy.QueryStringWhitelist = cdnConfig.CachePolicy.QueryStringWhitelist+			}+		}+		be.CdnPolicy.CacheKeyPolicy = beCacheKeyPolicy+	} else {+		be.CdnPolicy.CacheKeyPolicy = defaultCdnPolicy.CacheKeyPolicy+	}++	if cdnConfig.CacheMode != nil {+		be.CdnPolicy.CacheMode = *cdnConfig.CacheMode+	} else {+		be.CdnPolicy.CacheMode = defaultCdnPolicy.CacheMode+	}++	if cdnConfig.RequestCoalescing != nil {+		be.CdnPolicy.RequestCoalescing = *cdnConfig.RequestCoalescing+	} else {+		be.CdnPolicy.RequestCoalescing = defaultCdnPolicy.RequestCoalescing+	}++	if cdnConfig.ServeWhileStale != nil {+		be.CdnPolicy.ServeWhileStale = *cdnConfig.ServeWhileStale+	} else {+		be.CdnPolicy.ServeWhileStale = defaultCdnPolicy.ServeWhileStale+	}++	// MaxTtl must be specified with CACHE_ALL_STATIC cache_mode only+	if be.CdnPolicy.CacheMode != "CACHE_ALL_STATIC" {+		be.CdnPolicy.MaxTtl = 0+	} else if cdnConfig.MaxTtl != nil {+		be.CdnPolicy.MaxTtl = *cdnConfig.MaxTtl+		if be.CdnPolicy.MaxTtl == 0 {+			be.CdnPolicy.ForceSendFields = append(be.CdnPolicy.ForceSendFields, "MaxTtl")+		}+	} else {+		be.CdnPolicy.MaxTtl = defaultCdnPolicy.MaxTtl+	}++	// if USE_ORIGIN_HEADERS ClientTtl must be ignored+	if be.CdnPolicy.CacheMode == "USE_ORIGIN_HEADERS" {+		be.CdnPolicy.ClientTtl = 0+	} else if cdnConfig.ClientTtl != nil {+		be.CdnPolicy.ClientTtl = *cdnConfig.ClientTtl+		if be.CdnPolicy.ClientTtl == 0 {+			be.CdnPolicy.ForceSendFields = append(be.CdnPolicy.ForceSendFields, "ClientTtl")+		}+	} else {+		be.CdnPolicy.ClientTtl = defaultCdnPolicy.ClientTtl+	}++	// if USE_ORIGIN_HEADERS DefaultTtl must be ignored+	if be.CdnPolicy.CacheMode == "USE_ORIGIN_HEADERS" {+		be.CdnPolicy.DefaultTtl = 0+	} else if cdnConfig.DefaultTtl != nil {+		be.CdnPolicy.DefaultTtl = *cdnConfig.DefaultTtl+		if be.CdnPolicy.DefaultTtl == 0 {+			be.CdnPolicy.ForceSendFields = append(be.CdnPolicy.ForceSendFields, "DefaultTtl")+		}+	} else {+		be.CdnPolicy.DefaultTtl = defaultCdnPolicy.DefaultTtl+	}++	if cdnConfig.NegativeCaching != nil {+		be.CdnPolicy.NegativeCaching = *cdnConfig.NegativeCaching+	} else {+		be.CdnPolicy.NegativeCaching = defaultCdnPolicy.NegativeCaching+	}++	negativeCachingPolicy := []*composite.BackendServiceCdnPolicyNegativeCachingPolicy{}+	if be.CdnPolicy.NegativeCaching {+		for _, policyRef := range cdnConfig.NegativeCachingPolicy {+			negativeCachingPolicy = append(+				negativeCachingPolicy,+				&composite.BackendServiceCdnPolicyNegativeCachingPolicy{+					Code: policyRef.Code,+					Ttl:  policyRef.Ttl,+				},+			)+		}+	}++	if len(negativeCachingPolicy) > 0 {+		be.CdnPolicy.NegativeCachingPolicy = negativeCachingPolicy+	}++	if cdnConfig.SignedUrlCacheMaxAgeSec != nil {+		be.CdnPolicy.SignedUrlCacheMaxAgeSec = *cdnConfig.SignedUrlCacheMaxAgeSec+	} else {+		be.CdnPolicy.SignedUrlCacheMaxAgeSec = defaultCdnPolicy.SignedUrlCacheMaxAgeSec+	}++	bypassCacheOnRequestHeaders := []*composite.BackendServiceCdnPolicyBypassCacheOnRequestHeader{}+	for _, policyRef := range cdnConfig.BypassCacheOnRequestHeaders {+		bypassCacheOnRequestHeaders = append(+			bypassCacheOnRequestHeaders,+			&composite.BackendServiceCdnPolicyBypassCacheOnRequestHeader{+				HeaderName: policyRef.HeaderName,+			},+		)+	}+	if len(bypassCacheOnRequestHeaders) > 0 {+		be.CdnPolicy.BypassCacheOnRequestHeaders = bypassCacheOnRequestHeaders+	}++	return be+}++func hasDiff(new *composite.BackendService, current *composite.BackendService) bool {++	if new.EnableCDN != current.EnableCDN {+		return true+	}++	if current.CdnPolicy == nil {+		return true+	}++	// In order to use reflect.DeepEqual we need to handle the special cases++	// SignedUrlKeyNames are not handled by this function and must be preserved as they are+	if current.CdnPolicy != nil && current.CdnPolicy.SignedUrlKeyNames != nil {+		new.CdnPolicy.SignedUrlKeyNames = current.CdnPolicy.SignedUrlKeyNames

This is possible too, but I think is would be better not to alter the "current". Cloning the current it will add unnecessary overhead.

caseywebdev

comment created time in 2 months

more