-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't enqueue ingress for some service changes (#365)
When a service changes we get a service change event and an endpoint change event. Previously we'd enqueue the associated ingresses for all service changes. Now we only enqueue it when the service changes in a way that won't be covered by the endpoint changes. Specifically for Service.spec.selector changes, which users sometimes use to do blue/green deployments, we will no longer enqueue an ingress - instead the changes will be handled (correctly) by the endpoint handler.
- Loading branch information
1 parent
7e54578
commit d100319
Showing
2 changed files
with
200 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package handlers | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
) | ||
|
||
func TestHasServicePortChanges(t *testing.T) { | ||
cases := []struct { | ||
a []v1.ServicePort | ||
b []v1.ServicePort | ||
result bool | ||
reason string | ||
}{ | ||
{ | ||
[]v1.ServicePort{}, | ||
[]v1.ServicePort{}, | ||
false, | ||
"Empty should report no changes", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Port: 80, | ||
}}, | ||
[]v1.ServicePort{{ | ||
Port: 8080, | ||
}}, | ||
true, | ||
"Different Ports", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Port: 80, | ||
}}, | ||
[]v1.ServicePort{{ | ||
Port: 80, | ||
}}, | ||
false, | ||
"Same Ports", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Name: "asdf", | ||
Port: 80, | ||
}}, | ||
[]v1.ServicePort{{ | ||
Name: "asdf", | ||
Port: 80, | ||
}}, | ||
false, | ||
"Same Port and Name", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Name: "foo", | ||
Port: 80, | ||
}}, | ||
[]v1.ServicePort{{ | ||
Name: "bar", | ||
Port: 80, | ||
}}, | ||
true, | ||
"Different Name same Port", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Name: "foo", | ||
Port: 8080, | ||
}}, | ||
[]v1.ServicePort{{ | ||
Name: "bar", | ||
Port: 80, | ||
}}, | ||
true, | ||
"Different Name different Port", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Name: "foo", | ||
}}, | ||
[]v1.ServicePort{{ | ||
Name: "fooo", | ||
}}, | ||
true, | ||
"Very similar Name", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Name: "asdf", | ||
Port: 80, | ||
TargetPort: intstr.IntOrString{ | ||
IntVal: 80, | ||
}, | ||
}}, | ||
[]v1.ServicePort{{ | ||
Name: "asdf", | ||
Port: 80, | ||
TargetPort: intstr.IntOrString{ | ||
IntVal: 8080, | ||
}, | ||
}}, | ||
false, | ||
"TargetPort should be ignored", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Name: "foo", | ||
}, { | ||
Name: "bar", | ||
}}, | ||
[]v1.ServicePort{{ | ||
Name: "foo", | ||
}, { | ||
Name: "bar", | ||
}}, | ||
false, | ||
"Multiple same names", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Name: "foo", | ||
}, { | ||
Name: "bar", | ||
}}, | ||
[]v1.ServicePort{{ | ||
Name: "foo", | ||
}, { | ||
Name: "bars", | ||
}}, | ||
true, | ||
"Multiple different names", | ||
}, | ||
{ | ||
[]v1.ServicePort{{ | ||
Name: "foo", | ||
}, { | ||
Port: 80, | ||
}}, | ||
[]v1.ServicePort{{ | ||
Port: 80, | ||
}, { | ||
Name: "foo", | ||
}}, | ||
false, | ||
"Some names some ports", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
if c.result != hasServicePortChanges(c.a, c.b) { | ||
t.Errorf("hasServicePortChanges returned %v, but expected %v for %q case", c.result, !c.result, c.reason) | ||
} | ||
} | ||
} |