mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Updating apiserver Endpoints management to set skip-mirror label
This will ensure that the self-referential kubernetes Endpoints resources is not mirrored by the EndpointSliceMirroring controller.
This commit is contained in:
		@@ -157,6 +157,7 @@ go_test(
 | 
			
		||||
        "//pkg/registry/registrytest:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/api/certificates/v1beta1:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/api/core/v1:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/api/discovery/v1beta1:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/apimachinery/pkg/api/apitesting/naming:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
 | 
			
		||||
        "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,7 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	corev1 "k8s.io/api/core/v1"
 | 
			
		||||
	discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
 | 
			
		||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
			
		||||
	"k8s.io/apimachinery/pkg/util/intstr"
 | 
			
		||||
	"k8s.io/client-go/kubernetes/fake"
 | 
			
		||||
@@ -31,8 +32,14 @@ import (
 | 
			
		||||
 | 
			
		||||
func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
	ns := metav1.NamespaceDefault
 | 
			
		||||
	om := func(name string) metav1.ObjectMeta {
 | 
			
		||||
		return metav1.ObjectMeta{Namespace: ns, Name: name}
 | 
			
		||||
	om := func(name string, skipMirrorLabel bool) metav1.ObjectMeta {
 | 
			
		||||
		o := metav1.ObjectMeta{Namespace: ns, Name: name}
 | 
			
		||||
		if skipMirrorLabel {
 | 
			
		||||
			o.Labels = map[string]string{
 | 
			
		||||
				discoveryv1beta1.LabelSkipMirror: "true",
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return o
 | 
			
		||||
	}
 | 
			
		||||
	reconcileTests := []struct {
 | 
			
		||||
		testName          string
 | 
			
		||||
@@ -51,7 +58,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints:     nil,
 | 
			
		||||
			expectCreate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -65,7 +72,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -80,7 +87,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}, {IP: "4.3.2.1"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -88,7 +95,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -103,7 +110,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			additionalMasters: 3,
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{
 | 
			
		||||
							{IP: "1.2.3.4"},
 | 
			
		||||
@@ -117,7 +124,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{
 | 
			
		||||
						{IP: "1.2.3.4"},
 | 
			
		||||
@@ -137,7 +144,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			additionalMasters: 3,
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{
 | 
			
		||||
							{IP: "1.2.3.4"},
 | 
			
		||||
@@ -151,7 +158,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{
 | 
			
		||||
						{IP: "4.3.2.1"},
 | 
			
		||||
@@ -171,7 +178,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			additionalMasters: 3,
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{
 | 
			
		||||
							{IP: "4.3.2.1"},
 | 
			
		||||
@@ -191,7 +198,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			additionalMasters: 3,
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{
 | 
			
		||||
							{IP: "4.3.2.1"},
 | 
			
		||||
@@ -201,7 +208,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{
 | 
			
		||||
						{IP: "4.3.2.1"},
 | 
			
		||||
@@ -218,7 +225,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("bar"),
 | 
			
		||||
					ObjectMeta: om("bar", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -226,7 +233,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectCreate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -240,7 +247,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "4.3.2.1"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -248,7 +255,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -262,7 +269,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 9090, Protocol: "TCP"}},
 | 
			
		||||
@@ -270,7 +277,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -284,7 +291,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "UDP"}},
 | 
			
		||||
@@ -292,7 +299,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -306,7 +313,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "baz", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -314,7 +321,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "baz", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -332,7 +339,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports: []corev1.EndpointPort{
 | 
			
		||||
@@ -354,7 +361,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -362,7 +369,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports: []corev1.EndpointPort{
 | 
			
		||||
@@ -379,7 +386,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "boo", Port: 7777, Protocol: "SCTP"}},
 | 
			
		||||
			endpoints:     nil,
 | 
			
		||||
			expectCreate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("boo"),
 | 
			
		||||
				ObjectMeta: om("boo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "boo", Port: 7777, Protocol: "SCTP"}},
 | 
			
		||||
@@ -457,7 +464,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -476,7 +483,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "4.3.2.1"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -484,7 +491,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -498,7 +505,7 @@ func TestReconcileEndpoints(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints:     nil,
 | 
			
		||||
			expectCreate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
 
 | 
			
		||||
@@ -193,3 +193,17 @@ func allAddressesIPv6(addresses []corev1.EndpointAddress) bool {
 | 
			
		||||
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setSkipMirrorTrue sets endpointslice.kubernetes.io/skip-mirror to true. It
 | 
			
		||||
// returns true if this has resulted in a change to the Endpoints resource.
 | 
			
		||||
func setSkipMirrorTrue(e *corev1.Endpoints) bool {
 | 
			
		||||
	skipMirrorVal, ok := e.Labels[discovery.LabelSkipMirror]
 | 
			
		||||
	if !ok || skipMirrorVal != "true" {
 | 
			
		||||
		if e.Labels == nil {
 | 
			
		||||
			e.Labels = map[string]string{}
 | 
			
		||||
		}
 | 
			
		||||
		e.Labels[discovery.LabelSkipMirror] = "true"
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -196,9 +196,13 @@ func (r *leaseEndpointReconciler) doReconcile(serviceName string, endpointPorts
 | 
			
		||||
		return fmt.Errorf("no master IPs were listed in storage, refusing to erase all endpoints for the kubernetes service")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Don't use the EndpointSliceMirroring controller to mirror this to
 | 
			
		||||
	// EndpointSlices. This may change in the future.
 | 
			
		||||
	skipMirrorChanged := setSkipMirrorTrue(e)
 | 
			
		||||
 | 
			
		||||
	// Next, we compare the current list of endpoints with the list of master IP keys
 | 
			
		||||
	formatCorrect, ipCorrect, portsCorrect := checkEndpointSubsetFormatWithLease(e, masterIPs, endpointPorts, reconcilePorts)
 | 
			
		||||
	if formatCorrect && ipCorrect && portsCorrect {
 | 
			
		||||
	if !skipMirrorChanged && formatCorrect && ipCorrect && portsCorrect {
 | 
			
		||||
		return r.epAdapter.EnsureEndpointSliceFromEndpoints(corev1.NamespaceDefault, e)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,7 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	corev1 "k8s.io/api/core/v1"
 | 
			
		||||
	discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
 | 
			
		||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
			
		||||
	"k8s.io/client-go/kubernetes/fake"
 | 
			
		||||
)
 | 
			
		||||
@@ -78,8 +79,14 @@ func (f *fakeLeases) GetUpdatedKeys() []string {
 | 
			
		||||
 | 
			
		||||
func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
	ns := corev1.NamespaceDefault
 | 
			
		||||
	om := func(name string) metav1.ObjectMeta {
 | 
			
		||||
		return metav1.ObjectMeta{Namespace: ns, Name: name}
 | 
			
		||||
	om := func(name string, skipMirrorLabel bool) metav1.ObjectMeta {
 | 
			
		||||
		o := metav1.ObjectMeta{Namespace: ns, Name: name}
 | 
			
		||||
		if skipMirrorLabel {
 | 
			
		||||
			o.Labels = map[string]string{
 | 
			
		||||
				discoveryv1beta1.LabelSkipMirror: "true",
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return o
 | 
			
		||||
	}
 | 
			
		||||
	reconcileTests := []struct {
 | 
			
		||||
		testName      string
 | 
			
		||||
@@ -97,7 +104,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints:     nil,
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -111,7 +118,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -127,7 +134,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointKeys:  []string{"1.2.3.4"},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -142,7 +149,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}, {IP: "4.3.2.1"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -150,7 +157,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -165,7 +172,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointKeys:  []string{"1.2.3.4", "4.3.2.2", "4.3.2.3", "4.3.2.4"},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{
 | 
			
		||||
							{IP: "1.2.3.4"},
 | 
			
		||||
@@ -179,7 +186,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{
 | 
			
		||||
						{IP: "1.2.3.4"},
 | 
			
		||||
@@ -199,7 +206,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointKeys:  []string{"4.3.2.1", "4.3.2.2", "4.3.2.3", "4.3.2.4"},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{
 | 
			
		||||
							{IP: "1.2.3.4"},
 | 
			
		||||
@@ -213,7 +220,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{
 | 
			
		||||
						{IP: "4.3.2.1"},
 | 
			
		||||
@@ -233,7 +240,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointKeys:  []string{"4.3.2.1"},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{
 | 
			
		||||
							{IP: "4.3.2.1"},
 | 
			
		||||
@@ -243,7 +250,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{
 | 
			
		||||
						{IP: "4.3.2.1"},
 | 
			
		||||
@@ -260,7 +267,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("bar"),
 | 
			
		||||
					ObjectMeta: om("bar", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -268,7 +275,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -282,7 +289,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "4.3.2.1"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -290,7 +297,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -304,7 +311,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 9090, Protocol: "TCP"}},
 | 
			
		||||
@@ -312,7 +319,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -326,7 +333,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "UDP"}},
 | 
			
		||||
@@ -334,7 +341,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -348,7 +355,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "baz", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -356,13 +363,35 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "baz", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			testName:      "existing endpoints without skip mirror label",
 | 
			
		||||
			serviceName:   "foo",
 | 
			
		||||
			ip:            "1.2.3.4",
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo", false),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
					}},
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			testName:    "existing endpoints extra service ports satisfy",
 | 
			
		||||
			serviceName: "foo",
 | 
			
		||||
@@ -374,7 +403,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports: []corev1.EndpointPort{
 | 
			
		||||
@@ -396,7 +425,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -404,7 +433,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports: []corev1.EndpointPort{
 | 
			
		||||
@@ -467,7 +496,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -486,7 +515,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{{IP: "4.3.2.1"}},
 | 
			
		||||
						Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -494,7 +523,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -508,7 +537,7 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
			endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
			endpoints:     nil,
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{{IP: "1.2.3.4"}},
 | 
			
		||||
					Ports:     []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
 | 
			
		||||
@@ -553,8 +582,14 @@ func TestLeaseEndpointReconciler(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
func TestLeaseRemoveEndpoints(t *testing.T) {
 | 
			
		||||
	ns := corev1.NamespaceDefault
 | 
			
		||||
	om := func(name string) metav1.ObjectMeta {
 | 
			
		||||
		return metav1.ObjectMeta{Namespace: ns, Name: name}
 | 
			
		||||
	om := func(name string, skipMirrorLabel bool) metav1.ObjectMeta {
 | 
			
		||||
		o := metav1.ObjectMeta{Namespace: ns, Name: name}
 | 
			
		||||
		if skipMirrorLabel {
 | 
			
		||||
			o.Labels = map[string]string{
 | 
			
		||||
				discoveryv1beta1.LabelSkipMirror: "true",
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return o
 | 
			
		||||
	}
 | 
			
		||||
	stopTests := []struct {
 | 
			
		||||
		testName      string
 | 
			
		||||
@@ -573,7 +608,7 @@ func TestLeaseRemoveEndpoints(t *testing.T) {
 | 
			
		||||
			endpointKeys:  []string{"1.2.3.4", "4.3.2.2", "4.3.2.3", "4.3.2.4"},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{
 | 
			
		||||
							{IP: "1.2.3.4"},
 | 
			
		||||
@@ -586,7 +621,7 @@ func TestLeaseRemoveEndpoints(t *testing.T) {
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
			expectUpdate: &corev1.Endpoints{
 | 
			
		||||
				ObjectMeta: om("foo"),
 | 
			
		||||
				ObjectMeta: om("foo", true),
 | 
			
		||||
				Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
					Addresses: []corev1.EndpointAddress{
 | 
			
		||||
						{IP: "4.3.2.2"},
 | 
			
		||||
@@ -605,7 +640,7 @@ func TestLeaseRemoveEndpoints(t *testing.T) {
 | 
			
		||||
			endpointKeys:  []string{"1.2.3.4", "4.3.2.2", "4.3.2.3", "4.3.2.4"},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets: []corev1.EndpointSubset{{
 | 
			
		||||
						Addresses: []corev1.EndpointAddress{
 | 
			
		||||
							{IP: "1.2.3.4"},
 | 
			
		||||
@@ -626,7 +661,7 @@ func TestLeaseRemoveEndpoints(t *testing.T) {
 | 
			
		||||
			endpointKeys:  []string{"1.2.3.4", "4.3.2.2", "4.3.2.3", "4.3.2.4"},
 | 
			
		||||
			endpoints: &corev1.EndpointsList{
 | 
			
		||||
				Items: []corev1.Endpoints{{
 | 
			
		||||
					ObjectMeta: om("foo"),
 | 
			
		||||
					ObjectMeta: om("foo", true),
 | 
			
		||||
					Subsets:    nil,
 | 
			
		||||
				}},
 | 
			
		||||
			},
 | 
			
		||||
 
 | 
			
		||||
@@ -76,6 +76,11 @@ func (r *masterCountEndpointReconciler) ReconcileEndpoints(serviceName string, i
 | 
			
		||||
			},
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Don't use the EndpointSliceMirroring controller to mirror this to
 | 
			
		||||
	// EndpointSlices. This may change in the future.
 | 
			
		||||
	skipMirrorChanged := setSkipMirrorTrue(e)
 | 
			
		||||
 | 
			
		||||
	if errors.IsNotFound(err) {
 | 
			
		||||
		// Simply create non-existing endpoints for the service.
 | 
			
		||||
		e.Subsets = []corev1.EndpointSubset{{
 | 
			
		||||
@@ -99,7 +104,8 @@ func (r *masterCountEndpointReconciler) ReconcileEndpoints(serviceName string, i
 | 
			
		||||
		_, err = r.epAdapter.Update(metav1.NamespaceDefault, e)
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if ipCorrect && portsCorrect {
 | 
			
		||||
 | 
			
		||||
	if !skipMirrorChanged && ipCorrect && portsCorrect {
 | 
			
		||||
		return r.epAdapter.EnsureEndpointSliceFromEndpoints(metav1.NamespaceDefault, e)
 | 
			
		||||
	}
 | 
			
		||||
	if !ipCorrect {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user