From 34e052b5cc7adbad7d494ff9469fea0e14226a0e Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Tue, 19 Sep 2017 22:24:27 -0300 Subject: [PATCH] Improve equals --- core/pkg/ingress/types_equals.go | 24 +- tests/manifests/configuration-b.json | 384 +++++++++++++-------------- 2 files changed, 198 insertions(+), 210 deletions(-) diff --git a/core/pkg/ingress/types_equals.go b/core/pkg/ingress/types_equals.go index 69a214d1e..76a3d0598 100644 --- a/core/pkg/ingress/types_equals.go +++ b/core/pkg/ingress/types_equals.go @@ -70,15 +70,9 @@ func (c1 *Configuration) Equal(c2 *Configuration) bool { return false } - for _, c1s := range c1.Servers { - found := false - for _, c2s := range c2.Servers { - if c1s.Equal(c2s) { - found = true - break - } - } - if !found { + // Servers are sorted + for idx, c1s := range c1.Servers { + if !c1s.Equal(c2.Servers[idx]) { return false } } @@ -306,15 +300,9 @@ func (s1 *Server) Equal(s2 *Server) bool { return false } - for _, s1l := range s1.Locations { - found := false - for _, sl2 := range s2.Locations { - if s1l.Equal(sl2) { - found = true - break - } - } - if !found { + // Location are sorted + for idx, s1l := range s1.Locations { + if !s1l.Equal(s2.Locations[idx]) { return false } } diff --git a/tests/manifests/configuration-b.json b/tests/manifests/configuration-b.json index 6cd73cb46..f9235a17a 100644 --- a/tests/manifests/configuration-b.json +++ b/tests/manifests/configuration-b.json @@ -199,198 +199,6 @@ } }], "servers": [{ - "hostname": "domain.tld", - "sslPassthrough": false, - "sslCertificate": "", - "sslExpireTime": "0001-01-01T00:00:00Z", - "sslPemChecksum": "", - "locations": [{ - "path": "/dashboard", - "isDefBackend": false, - "backend": "kube-system-kubernetes-dashboard-80", - "service": { - "metadata": { - "name": "kubernetes-dashboard", - "namespace": "kube-system", - "selfLink": "/api/v1/namespaces/kube-system/services/kubernetes-dashboard", - "uid": "b957713f-5176-11e7-b3db-080027494b5d", - "resourceVersion": "82", - "creationTimestamp": "2017-06-15T03:00:01Z", - "labels": { - "addonmanager.kubernetes.io/mode": "Reconcile", - "app": "kubernetes-dashboard", - "kubernetes.io/minikube-addons": "dashboard", - "kubernetes.io/minikube-addons-endpoint": "dashboard" - }, - "annotations": { - "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"addonmanager.kubernetes.io/mode\":\"Reconcile\",\"app\":\"kubernetes-dashboard\",\"kubernetes.io/minikube-addons\":\"dashboard\",\"kubernetes.io/minikube-addons-endpoint\":\"dashboard\"},\"name\":\"kubernetes-dashboard\",\"namespace\":\"kube-system\"},\"spec\":{\"ports\":[{\"nodePort\":30000,\"port\":80,\"targetPort\":9090}],\"selector\":{\"app\":\"kubernetes-dashboard\"},\"type\":\"NodePort\"}}\n" - } - }, - "spec": { - "ports": [{ - "protocol": "TCP", - "port": 80, - "targetPort": 9090, - "nodePort": 30000 - }], - "selector": { - "app": "kubernetes-dashboard" - }, - "clusterIP": "10.0.0.120", - "type": "NodePort", - "sessionAffinity": "None" - }, - "status": { - "loadBalancer": {} - } - }, - "port": 80, - "basicDigestAuth": { - "type": "", - "realm": "", - "file": "", - "secured": false, - "fileSha": "" - }, - "externalAuth": { - "url": "", - "host": "", - "signinUrl": "", - "method": "", - "sendBody": false, - "responseHeaders": null - }, - "rateLimit": { - "connections": { - "name": "", - "limit": 0, - "burst": 0, - "sharedSize": 0 - }, - "rps": { - "name": "", - "limit": 0, - "burst": 0, - "sharedSize": 0 - }, - "rpm": { - "name": "", - "limit": 0, - "burst": 0, - "sharedSize": 0 - } - }, - "redirect": { - "target": "/", - "addBaseUrl": false, - "sslRedirect": true, - "forceSSLRedirect": false, - "appRoot": "" - }, - "whitelist": { - "cidr": null - }, - "proxy": { - "bodySize": "1m", - "conectTimeout": 5, - "sendTimeout": 60, - "readTimeout": 60, - "bufferSize": "4k", - "cookieDomain": "off", - "cookiePath": "off", - "nextUpstream": "error timeout invalid_header http_502 http_503 http_504" - }, - "certificateAuth": { - "authSSLCert": { - "secret": "", - "caFilename": "", - "pemSha": "" - }, - "validationDepth": 0 - }, - "use-port-in-redirects": false, - "configuration-snippet": "" - }, { - "path": "/", - "isDefBackend": true, - "backend": "upstream-default-backend", - "service": { - "metadata": { - "creationTimestamp": null - }, - "spec": {}, - "status": { - "loadBalancer": {} - } - }, - "port": 0, - "basicDigestAuth": { - "type": "", - "realm": "", - "file": "", - "secured": false, - "fileSha": "" - }, - "externalAuth": { - "url": "", - "host": "", - "signinUrl": "", - "method": "", - "sendBody": false, - "responseHeaders": null - }, - "rateLimit": { - "connections": { - "name": "", - "limit": 0, - "burst": 0, - "sharedSize": 0 - }, - "rps": { - "name": "", - "limit": 0, - "burst": 0, - "sharedSize": 0 - }, - "rpm": { - "name": "", - "limit": 0, - "burst": 0, - "sharedSize": 0 - } - }, - "redirect": { - "target": "", - "addBaseUrl": false, - "sslRedirect": false, - "forceSSLRedirect": false, - "appRoot": "" - }, - "whitelist": { - "cidr": null - }, - "proxy": { - "bodySize": "1m", - "conectTimeout": 5, - "sendTimeout": 60, - "readTimeout": 60, - "bufferSize": "4k", - "cookieDomain": "off", - "cookiePath": "off", - "nextUpstream": "error timeout invalid_header http_502 http_503 http_504" - }, - "certificateAuth": { - "authSSLCert": { - "secret": "", - "caFilename": "", - "pemSha": "" - }, - "validationDepth": 0 - }, - "use-port-in-redirects": false, - "configuration-snippet": "" - }] - },{ "hostname": "_", "sslPassthrough": false, "sslCertificate": "/ingress-controller/ssl/default-fake-certificate.pem", @@ -683,6 +491,198 @@ "use-port-in-redirects": false, "configuration-snippet": "" }] + }, { + "hostname": "domain.tld", + "sslPassthrough": false, + "sslCertificate": "", + "sslExpireTime": "0001-01-01T00:00:00Z", + "sslPemChecksum": "", + "locations": [{ + "path": "/dashboard", + "isDefBackend": false, + "backend": "kube-system-kubernetes-dashboard-80", + "service": { + "metadata": { + "name": "kubernetes-dashboard", + "namespace": "kube-system", + "selfLink": "/api/v1/namespaces/kube-system/services/kubernetes-dashboard", + "uid": "b957713f-5176-11e7-b3db-080027494b5d", + "resourceVersion": "82", + "creationTimestamp": "2017-06-15T03:00:01Z", + "labels": { + "addonmanager.kubernetes.io/mode": "Reconcile", + "app": "kubernetes-dashboard", + "kubernetes.io/minikube-addons": "dashboard", + "kubernetes.io/minikube-addons-endpoint": "dashboard" + }, + "annotations": { + "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"addonmanager.kubernetes.io/mode\":\"Reconcile\",\"app\":\"kubernetes-dashboard\",\"kubernetes.io/minikube-addons\":\"dashboard\",\"kubernetes.io/minikube-addons-endpoint\":\"dashboard\"},\"name\":\"kubernetes-dashboard\",\"namespace\":\"kube-system\"},\"spec\":{\"ports\":[{\"nodePort\":30000,\"port\":80,\"targetPort\":9090}],\"selector\":{\"app\":\"kubernetes-dashboard\"},\"type\":\"NodePort\"}}\n" + } + }, + "spec": { + "ports": [{ + "protocol": "TCP", + "port": 80, + "targetPort": 9090, + "nodePort": 30000 + }], + "selector": { + "app": "kubernetes-dashboard" + }, + "clusterIP": "10.0.0.120", + "type": "NodePort", + "sessionAffinity": "None" + }, + "status": { + "loadBalancer": {} + } + }, + "port": 80, + "basicDigestAuth": { + "type": "", + "realm": "", + "file": "", + "secured": false, + "fileSha": "" + }, + "externalAuth": { + "url": "", + "host": "", + "signinUrl": "", + "method": "", + "sendBody": false, + "responseHeaders": null + }, + "rateLimit": { + "connections": { + "name": "", + "limit": 0, + "burst": 0, + "sharedSize": 0 + }, + "rps": { + "name": "", + "limit": 0, + "burst": 0, + "sharedSize": 0 + }, + "rpm": { + "name": "", + "limit": 0, + "burst": 0, + "sharedSize": 0 + } + }, + "redirect": { + "target": "/", + "addBaseUrl": false, + "sslRedirect": true, + "forceSSLRedirect": false, + "appRoot": "" + }, + "whitelist": { + "cidr": null + }, + "proxy": { + "bodySize": "1m", + "conectTimeout": 5, + "sendTimeout": 60, + "readTimeout": 60, + "bufferSize": "4k", + "cookieDomain": "off", + "cookiePath": "off", + "nextUpstream": "error timeout invalid_header http_502 http_503 http_504" + }, + "certificateAuth": { + "authSSLCert": { + "secret": "", + "caFilename": "", + "pemSha": "" + }, + "validationDepth": 0 + }, + "use-port-in-redirects": false, + "configuration-snippet": "" + }, { + "path": "/", + "isDefBackend": true, + "backend": "upstream-default-backend", + "service": { + "metadata": { + "creationTimestamp": null + }, + "spec": {}, + "status": { + "loadBalancer": {} + } + }, + "port": 0, + "basicDigestAuth": { + "type": "", + "realm": "", + "file": "", + "secured": false, + "fileSha": "" + }, + "externalAuth": { + "url": "", + "host": "", + "signinUrl": "", + "method": "", + "sendBody": false, + "responseHeaders": null + }, + "proxy": { + "bodySize": "1m", + "conectTimeout": 5, + "sendTimeout": 60, + "readTimeout": 60, + "bufferSize": "4k", + "cookieDomain": "off", + "cookiePath": "off", + "nextUpstream": "error timeout invalid_header http_502 http_503 http_504" + }, + "certificateAuth": { + "authSSLCert": { + "secret": "", + "caFilename": "", + "pemSha": "" + }, + "validationDepth": 0 + }, + "use-port-in-redirects": false, + "configuration-snippet": "", + "rateLimit": { + "connections": { + "name": "", + "limit": 0, + "burst": 0, + "sharedSize": 0 + }, + "rps": { + "name": "", + "limit": 0, + "burst": 0, + "sharedSize": 0 + }, + "rpm": { + "name": "", + "limit": 0, + "burst": 0, + "sharedSize": 0 + } + }, + "redirect": { + "target": "", + "addBaseUrl": false, + "sslRedirect": false, + "forceSSLRedirect": false, + "appRoot": "" + }, + "whitelist": { + "cidr": null + } + }] }], "TCPBackends": [], "UDPBackends": []