mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #84862 from yutedz/master-subset-check
Check that endpoint has subset before accessing first subset
This commit is contained in:
commit
fb87f72b88
@ -558,6 +558,32 @@ func TestReconcileEndpoints(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptySubsets(t *testing.T) {
|
||||||
|
ns := metav1.NamespaceDefault
|
||||||
|
om := func(name string) metav1.ObjectMeta {
|
||||||
|
return metav1.ObjectMeta{Namespace: ns, Name: name}
|
||||||
|
}
|
||||||
|
endpoints := &corev1.EndpointsList{
|
||||||
|
Items: []corev1.Endpoints{{
|
||||||
|
ObjectMeta: om("foo"),
|
||||||
|
Subsets: nil,
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
fakeClient := fake.NewSimpleClientset()
|
||||||
|
if endpoints != nil {
|
||||||
|
fakeClient = fake.NewSimpleClientset(endpoints)
|
||||||
|
}
|
||||||
|
epAdapter := reconcilers.NewEndpointsAdapter(fakeClient.CoreV1(), nil)
|
||||||
|
reconciler := reconcilers.NewMasterCountEndpointReconciler(1, epAdapter)
|
||||||
|
endpointPorts := []corev1.EndpointPort{
|
||||||
|
{Name: "foo", Port: 8080, Protocol: "TCP"},
|
||||||
|
}
|
||||||
|
err := reconciler.RemoveEndpoints("foo", net.ParseIP("1.2.3.4"), endpointPorts)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateOrUpdateMasterService(t *testing.T) {
|
func TestCreateOrUpdateMasterService(t *testing.T) {
|
||||||
ns := metav1.NamespaceDefault
|
ns := metav1.NamespaceDefault
|
||||||
om := func(name string) metav1.ObjectMeta {
|
om := func(name string) metav1.ObjectMeta {
|
||||||
|
@ -67,9 +67,11 @@ func (s *storageLeases) ListLeases() ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ipList := make([]string, len(ipInfoList.Items))
|
ipList := make([]string, 0, len(ipInfoList.Items))
|
||||||
for i, ip := range ipInfoList.Items {
|
for _, ip := range ipInfoList.Items {
|
||||||
ipList[i] = ip.Subsets[0].Addresses[0].IP
|
if len(ip.Subsets) > 0 && len(ip.Subsets[0].Addresses) > 0 && len(ip.Subsets[0].Addresses[0].IP) > 0 {
|
||||||
|
ipList = append(ipList, ip.Subsets[0].Addresses[0].IP)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.V(6).Infof("Current master IPs listed in storage are %v", ipList)
|
klog.V(6).Infof("Current master IPs listed in storage are %v", ipList)
|
||||||
|
@ -617,6 +617,19 @@ func TestLeaseRemoveEndpoints(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
testName: "endpoint with no subset",
|
||||||
|
serviceName: "foo",
|
||||||
|
ip: "5.6.7.8",
|
||||||
|
endpointPorts: []corev1.EndpointPort{{Name: "foo", Port: 8080, Protocol: "TCP"}},
|
||||||
|
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"),
|
||||||
|
Subsets: nil,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, test := range stopTests {
|
for _, test := range stopTests {
|
||||||
t.Run(test.testName, func(t *testing.T) {
|
t.Run(test.testName, func(t *testing.T) {
|
||||||
|
@ -149,6 +149,10 @@ func (r *masterCountEndpointReconciler) RemoveEndpoints(serviceName string, ip n
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(e.Subsets) == 0 {
|
||||||
|
// no action is needed to remove the endpoint
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// Remove our IP from the list of addresses
|
// Remove our IP from the list of addresses
|
||||||
new := []corev1.EndpointAddress{}
|
new := []corev1.EndpointAddress{}
|
||||||
for _, addr := range e.Subsets[0].Addresses {
|
for _, addr := range e.Subsets[0].Addresses {
|
||||||
|
Loading…
Reference in New Issue
Block a user