Skip to content

Commit

Permalink
Merge pull request #1110 from aledbf/master
Browse files Browse the repository at this point in the history
Fix Endpoint comparison
  • Loading branch information
aledbf authored Aug 11, 2017
2 parents 45e43f8 + e1308d9 commit 36cf018
Show file tree
Hide file tree
Showing 7 changed files with 1,258 additions and 65 deletions.
23 changes: 15 additions & 8 deletions core/pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ func (ic *GenericController) getDefaultUpstream() *ingress.Backend {
endps = []ingress.Endpoint{newDefaultServer()}
}

upstream.Service = svc
upstream.Endpoints = append(upstream.Endpoints, endps...)
return upstream
}
Expand Down Expand Up @@ -840,6 +841,8 @@ func (ic *GenericController) createUpstreams(data []interface{}) map[string]*ing

glog.V(3).Infof("creating upstream %v", name)
upstreams[name] = newUpstream(name)
upstreams[name].Port = path.Backend.ServicePort

if !upstreams[name].Secure {
upstreams[name].Secure = secUpstream.Secure
}
Expand Down Expand Up @@ -876,12 +879,12 @@ func (ic *GenericController) createUpstreams(data []interface{}) map[string]*ing
continue
}

if exists {
upstreams[name].Service = s.(*api.Service)
} else {
if !exists {
glog.Warningf("service %v does not exists", svcKey)
continue
}
upstreams[name].Port = path.Backend.ServicePort

upstreams[name].Service = s.(*api.Service)
}
}
}
Expand Down Expand Up @@ -1006,6 +1009,7 @@ func (ic *GenericController) createServers(data []interface{},
}

// initialize the default server
du := ic.getDefaultUpstream()
servers[defServerName] = &ingress.Server{
Hostname: defServerName,
SSLCertificate: defaultPemFileName,
Expand All @@ -1014,8 +1018,9 @@ func (ic *GenericController) createServers(data []interface{},
{
Path: rootLocation,
IsDefBackend: true,
Backend: ic.getDefaultUpstream().Name,
Backend: du.Name,
Proxy: ngxProxy,
Service: du.Service,
},
}}

Expand All @@ -1028,12 +1033,13 @@ func (ic *GenericController) createServers(data []interface{},

// check if ssl passthrough is configured
sslpt := ic.annotations.SSLPassthrough(ing)
dun := ic.getDefaultUpstream().Name
du := ic.getDefaultUpstream()
un := du.Name
if ing.Spec.Backend != nil {
// replace default backend
defUpstream := fmt.Sprintf("%v-%v-%v", ing.GetNamespace(), ing.Spec.Backend.ServiceName, ing.Spec.Backend.ServicePort.String())
if backendUpstream, ok := upstreams[defUpstream]; ok {
dun = backendUpstream.Name
un = backendUpstream.Name
}
}

Expand All @@ -1053,8 +1059,9 @@ func (ic *GenericController) createServers(data []interface{},
{
Path: rootLocation,
IsDefBackend: true,
Backend: dun,
Backend: un,
Proxy: ngxProxy,
Service: &api.Service{},
},
}, SSLPassthrough: sslpt}
}
Expand Down
3 changes: 1 addition & 2 deletions core/pkg/ingress/type_equals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ func TestEqualConfiguration(t *testing.T) {
}

if !b.Equal(a) {
t.Errorf("expected equal configurations (configuration-a.json and configuration-b.json)")
t.Errorf("expected equal configurations (configuration-b.json and configuration-a.json)")
}

if a.Equal(c) {
t.Errorf("expected equal configurations (configuration-a.json and configuration-c.json)")
}

}

func readJSON(p string) (*Configuration, error) {
Expand Down
4 changes: 2 additions & 2 deletions core/pkg/ingress/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ type Endpoint struct {
// to consider the endpoint unavailable
FailTimeout int `json:"failTimeout"`
// Target returns a reference to the object providing the endpoint
Target *api.ObjectReference `json:"target"`
Target *api.ObjectReference `json:"target,omipempty"`
}

// Server describes a website
Expand Down Expand Up @@ -253,7 +253,7 @@ type Location struct {
// Backend describes the name of the backend to use.
Backend string `json:"backend"`

Service *api.Service `json:"service"`
Service *api.Service `json:"service,omitempty"`
Port intstr.IntOrString `json:"port"`
// BasicDigestAuth returns authentication configuration for
// an Ingress rule.
Expand Down
76 changes: 36 additions & 40 deletions core/pkg/ingress/types_equals.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,17 @@ func (b1 *Backend) Equal(b2 *Backend) bool {
return false
}

if (b1.Service == nil && b2.Service != nil) ||
(b1.Service != nil && b2.Service == nil) {
if b1.Service == nil || b2.Service == nil {
return false
}

if b1.Service != nil && b2.Service != nil {
if b1.Service.GetNamespace() != b2.Service.GetNamespace() {
return false
}
if b1.Service.GetName() != b2.Service.GetName() {
return false
}
if b1.Service.GetResourceVersion() != b2.Service.GetResourceVersion() {
return false
}
if b1.Service.GetNamespace() != b2.Service.GetNamespace() {
return false
}
if b1.Service.GetName() != b2.Service.GetName() {
return false
}
if b1.Service.GetResourceVersion() != b2.Service.GetResourceVersion() {
return false
}

if b1.Port != b2.Port {
Expand Down Expand Up @@ -258,7 +254,14 @@ func (e1 *Endpoint) Equal(e2 *Endpoint) bool {
if e1.FailTimeout != e2.FailTimeout {
return false
}
if e1.Target != e2.Target {

if e1.Target == nil || e2.Target == nil {
return false
}
if e1.Target.UID != e2.Target.UID {
return false
}
if e1.Target.ResourceVersion != e2.Target.ResourceVersion {
return false
}

Expand Down Expand Up @@ -324,21 +327,17 @@ func (l1 *Location) Equal(l2 *Location) bool {
return false
}

if (l1.Service == nil && l2.Service != nil) ||
(l1.Service != nil && l2.Service == nil) {
if l1.Service == nil || l2.Service == nil {
return false
}

if l1.Service != nil && l2.Service != nil {
if l1.Service.GetNamespace() != l2.Service.GetNamespace() {
return false
}
if l1.Service.GetName() != l2.Service.GetName() {
return false
}
if l1.Service.GetResourceVersion() != l2.Service.GetResourceVersion() {
return false
}
if l1.Service.GetNamespace() != l2.Service.GetNamespace() {
return false
}
if l1.Service.GetName() != l2.Service.GetName() {
return false
}
if l1.Service.GetResourceVersion() != l2.Service.GetResourceVersion() {
return false
}

if l1.Port.StrVal != l2.Port.StrVal {
Expand Down Expand Up @@ -398,21 +397,18 @@ func (ptb1 *SSLPassthroughBackend) Equal(ptb2 *SSLPassthroughBackend) bool {
if ptb1.Port != ptb2.Port {
return false
}
if (ptb1.Service == nil && ptb2.Service != nil) ||
(ptb1.Service != nil && ptb2.Service == nil) {

if ptb1.Service == nil || ptb2.Service == nil {
return false
}

if ptb1.Service != nil && ptb2.Service != nil {
if ptb1.Service.GetNamespace() != ptb2.Service.GetNamespace() {
return false
}
if ptb1.Service.GetName() != ptb2.Service.GetName() {
return false
}
if ptb1.Service.GetResourceVersion() != ptb2.Service.GetResourceVersion() {
return false
}
if ptb1.Service.GetNamespace() != ptb2.Service.GetNamespace() {
return false
}
if ptb1.Service.GetName() != ptb2.Service.GetName() {
return false
}
if ptb1.Service.GetResourceVersion() != ptb2.Service.GetResourceVersion() {
return false
}

return true
Expand Down
Loading

0 comments on commit 36cf018

Please sign in to comment.