Migrate to EndpointSlices API
This commit is contained in:
parent
61defcdd66
commit
a8a92eb2a5
88 changed files with 2177 additions and 1555 deletions
|
@ -4,12 +4,14 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
discoveryv1 "k8s.io/api/discovery/v1"
|
||||
netv1 "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func Test_detectChanges(t *testing.T) {
|
||||
portA := int32(80)
|
||||
portB := int32(8080)
|
||||
tests := []struct {
|
||||
name string
|
||||
oldObj interface{}
|
||||
|
@ -21,28 +23,28 @@ func Test_detectChanges(t *testing.T) {
|
|||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With empty endpoints",
|
||||
oldObj: &corev1.Endpoints{},
|
||||
newObj: &corev1.Endpoints{},
|
||||
name: "With empty endpointslice",
|
||||
oldObj: &discoveryv1.EndpointSlice{},
|
||||
newObj: &discoveryv1.EndpointSlice{},
|
||||
},
|
||||
{
|
||||
name: "With old nil",
|
||||
newObj: &corev1.Endpoints{},
|
||||
newObj: &discoveryv1.EndpointSlice{},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With new nil",
|
||||
oldObj: &corev1.Endpoints{},
|
||||
oldObj: &discoveryv1.EndpointSlice{},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With same version",
|
||||
oldObj: &corev1.Endpoints{
|
||||
oldObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
newObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
|
@ -50,12 +52,12 @@ func Test_detectChanges(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "With different version",
|
||||
oldObj: &corev1.Endpoints{
|
||||
oldObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
newObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
|
@ -90,7 +92,7 @@ func Test_detectChanges(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "With same annotations",
|
||||
oldObj: &corev1.Endpoints{
|
||||
oldObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
Annotations: map[string]string{
|
||||
|
@ -98,7 +100,7 @@ func Test_detectChanges(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
newObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
Annotations: map[string]string{
|
||||
|
@ -109,7 +111,7 @@ func Test_detectChanges(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "With different annotations",
|
||||
oldObj: &corev1.Endpoints{
|
||||
oldObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
Annotations: map[string]string{
|
||||
|
@ -117,7 +119,7 @@ func Test_detectChanges(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
newObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
Annotations: map[string]string{
|
||||
|
@ -127,384 +129,94 @@ func Test_detectChanges(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "With same subsets",
|
||||
oldObj: &corev1.Endpoints{
|
||||
name: "With same endpoints and ports",
|
||||
oldObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{},
|
||||
Endpoints: []discoveryv1.Endpoint{},
|
||||
Ports: []discoveryv1.EndpointPort{},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
newObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{},
|
||||
Endpoints: []discoveryv1.Endpoint{},
|
||||
Ports: []discoveryv1.EndpointPort{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "With different len of subsets",
|
||||
oldObj: &corev1.Endpoints{
|
||||
name: "With different len of endpoints",
|
||||
oldObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{},
|
||||
Endpoints: []discoveryv1.Endpoint{},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
newObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{}},
|
||||
Endpoints: []discoveryv1.Endpoint{{}},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of addresses",
|
||||
oldObj: &corev1.Endpoints{
|
||||
name: "With different endpoints",
|
||||
oldObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{},
|
||||
Endpoints: []discoveryv1.Endpoint{{
|
||||
Addresses: []string{"10.10.10.10"},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
newObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{},
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "With same subsets with different len of addresses",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{}},
|
||||
Endpoints: []discoveryv1.Endpoint{{
|
||||
Addresses: []string{"10.10.10.11"},
|
||||
}},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of ports",
|
||||
oldObj: &corev1.Endpoints{
|
||||
name: "With different len of ports",
|
||||
oldObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{},
|
||||
}},
|
||||
Ports: []discoveryv1.EndpointPort{},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
newObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{},
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "With same subsets with different len of ports",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{}},
|
||||
}},
|
||||
Ports: []discoveryv1.EndpointPort{{}},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of addresses with same ip",
|
||||
oldObj: &corev1.Endpoints{
|
||||
name: "With different ports",
|
||||
oldObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
IP: "10.10.10.10",
|
||||
}},
|
||||
Ports: []discoveryv1.EndpointPort{{
|
||||
Port: &portA,
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
newObj: &discoveryv1.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
IP: "10.10.10.10",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of addresses with different ip",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
IP: "10.10.10.10",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
IP: "10.10.10.42",
|
||||
}},
|
||||
Ports: []discoveryv1.EndpointPort{{
|
||||
Port: &portB,
|
||||
}},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of addresses with same hostname",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
Hostname: "foo",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
Hostname: "foo",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of addresses with same hostname",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
Hostname: "foo",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
Hostname: "bar",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of port with same name",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Name: "foo",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Name: "foo",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of port with different name",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Name: "foo",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Name: "bar",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of port with same port",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Port: 4242,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Port: 4242,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of port with different port",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Port: 4242,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Port: 6969,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of port with same protocol",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Protocol: "HTTP",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Protocol: "HTTP",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same len of port with different protocol",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Protocol: "HTTP",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Protocol: "TCP",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "With same subsets with same subset",
|
||||
oldObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
IP: "10.10.10.10",
|
||||
Hostname: "foo",
|
||||
}},
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Name: "bar",
|
||||
Port: 4242,
|
||||
Protocol: "HTTP",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
newObj: &corev1.Endpoints{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ResourceVersion: "2",
|
||||
},
|
||||
Subsets: []corev1.EndpointSubset{{
|
||||
Addresses: []corev1.EndpointAddress{{
|
||||
IP: "10.10.10.10",
|
||||
Hostname: "foo",
|
||||
}},
|
||||
Ports: []corev1.EndpointPort{{
|
||||
Name: "bar",
|
||||
Port: 4242,
|
||||
Protocol: "HTTP",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue