mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #92339 from fatkun/fixed_on_endpointslice_update
Fix bug that use obj as prev obj in endpoint slice update
This commit is contained in:
commit
6316f4f582
@ -68,6 +68,7 @@ go_test(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/informers:go_default_library",
|
"//staging/src/k8s.io/client-go/informers:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
|
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
||||||
|
@ -404,7 +404,7 @@ func (c *Controller) onEndpointSliceAdd(obj interface{}) {
|
|||||||
// endpointSliceTracker or the managed-by value of the EndpointSlice has changed
|
// endpointSliceTracker or the managed-by value of the EndpointSlice has changed
|
||||||
// from or to this controller.
|
// from or to this controller.
|
||||||
func (c *Controller) onEndpointSliceUpdate(prevObj, obj interface{}) {
|
func (c *Controller) onEndpointSliceUpdate(prevObj, obj interface{}) {
|
||||||
prevEndpointSlice := obj.(*discovery.EndpointSlice)
|
prevEndpointSlice := prevObj.(*discovery.EndpointSlice)
|
||||||
endpointSlice := obj.(*discovery.EndpointSlice)
|
endpointSlice := obj.(*discovery.EndpointSlice)
|
||||||
if endpointSlice == nil || prevEndpointSlice == nil {
|
if endpointSlice == nil || prevEndpointSlice == nil {
|
||||||
utilruntime.HandleError(fmt.Errorf("Invalid EndpointSlice provided to onEndpointSliceUpdate()"))
|
utilruntime.HandleError(fmt.Errorf("Invalid EndpointSlice provided to onEndpointSliceUpdate()"))
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/client-go/informers"
|
"k8s.io/client-go/informers"
|
||||||
"k8s.io/client-go/kubernetes/fake"
|
"k8s.io/client-go/kubernetes/fake"
|
||||||
k8stesting "k8s.io/client-go/testing"
|
k8stesting "k8s.io/client-go/testing"
|
||||||
@ -274,6 +275,39 @@ func TestSyncServiceEndpointSliceLabelSelection(t *testing.T) {
|
|||||||
cmc.Check(t)
|
cmc.Check(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOnEndpointSliceUpdate(t *testing.T) {
|
||||||
|
_, esController := newController([]string{"node-1"}, time.Duration(0))
|
||||||
|
ns := metav1.NamespaceDefault
|
||||||
|
serviceName := "testing-1"
|
||||||
|
epSlice1 := &discovery.EndpointSlice{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "matching-1",
|
||||||
|
Namespace: ns,
|
||||||
|
Labels: map[string]string{
|
||||||
|
discovery.LabelServiceName: serviceName,
|
||||||
|
discovery.LabelManagedBy: controllerName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AddressType: discovery.AddressTypeIPv4,
|
||||||
|
}
|
||||||
|
|
||||||
|
epSlice2 := epSlice1.DeepCopy()
|
||||||
|
epSlice2.Labels[discovery.LabelManagedBy] = "something else"
|
||||||
|
|
||||||
|
assert.Equal(t, 0, esController.queue.Len())
|
||||||
|
esController.onEndpointSliceUpdate(epSlice1, epSlice2)
|
||||||
|
err := wait.PollImmediate(100*time.Millisecond, 3*time.Second, func() (bool, error) {
|
||||||
|
if esController.queue.Len() > 0 {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error waiting for add to queue")
|
||||||
|
}
|
||||||
|
assert.Equal(t, 1, esController.queue.Len())
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure SyncService handles a variety of protocols and IPs appropriately.
|
// Ensure SyncService handles a variety of protocols and IPs appropriately.
|
||||||
func TestSyncServiceFull(t *testing.T) {
|
func TestSyncServiceFull(t *testing.T) {
|
||||||
client, esController := newController([]string{"node-1"}, time.Duration(0))
|
client, esController := newController([]string{"node-1"}, time.Duration(0))
|
||||||
|
Loading…
Reference in New Issue
Block a user