mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #33769 from mwielgus/copy-test
Automatic merge from submit-queue Copy objects in federation test helper Push clean copies of passed objects in test helper in federation controllers tests. Fixes: #33667 cc: @gmarek @quinton-hoole @kubernetes/sig-cluster-federation
This commit is contained in:
		@@ -151,6 +151,7 @@ func TestIngressController(t *testing.T) {
 | 
			
		||||
	assert.Equal(t, updatedIngress2.ObjectMeta.Annotations["A"], updatedIngress.ObjectMeta.Annotations["A"], "Updated annotation not transferred from federated to cluster ingress.")
 | 
			
		||||
	// Test add cluster
 | 
			
		||||
	t.Log("Adding a second cluster")
 | 
			
		||||
	ing1.Annotations = make(map[string]string)
 | 
			
		||||
	ing1.Annotations[staticIPNameKeyWritable] = "foo" // Make sure that the base object has a static IP name first.
 | 
			
		||||
	fedIngressWatch.Modify(&ing1)
 | 
			
		||||
	clusterWatch.Add(cluster2)
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	federation_api "k8s.io/kubernetes/federation/apis/federation/v1beta1"
 | 
			
		||||
	"k8s.io/kubernetes/federation/pkg/federation-controller/util"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api"
 | 
			
		||||
	api_v1 "k8s.io/kubernetes/pkg/api/v1"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/client/testing/core"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/runtime"
 | 
			
		||||
@@ -48,14 +49,22 @@ func (wd *WatcherDispatcher) register(watcher *watch.FakeWatcher) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func copy(obj runtime.Object) runtime.Object {
 | 
			
		||||
	objCopy, err := api.Scheme.DeepCopy(obj)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	return objCopy.(runtime.Object)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Add sends an add event.
 | 
			
		||||
func (wd *WatcherDispatcher) Add(obj runtime.Object) {
 | 
			
		||||
	wd.Lock()
 | 
			
		||||
	defer wd.Unlock()
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: watch.Added, Object: obj})
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: watch.Added, Object: copy(obj)})
 | 
			
		||||
	for _, watcher := range wd.watchers {
 | 
			
		||||
		if !watcher.IsStopped() {
 | 
			
		||||
			watcher.Add(obj)
 | 
			
		||||
			watcher.Add(copy(obj))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -65,11 +74,11 @@ func (wd *WatcherDispatcher) Modify(obj runtime.Object) {
 | 
			
		||||
	wd.Lock()
 | 
			
		||||
	defer wd.Unlock()
 | 
			
		||||
	glog.V(4).Infof("->WatcherDispatcher.Modify(%v)", obj)
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: watch.Modified, Object: obj})
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: watch.Modified, Object: copy(obj)})
 | 
			
		||||
	for i, watcher := range wd.watchers {
 | 
			
		||||
		if !watcher.IsStopped() {
 | 
			
		||||
			glog.V(4).Infof("->Watcher(%d).Modify(%v)", i, obj)
 | 
			
		||||
			watcher.Modify(obj)
 | 
			
		||||
			watcher.Modify(copy(obj))
 | 
			
		||||
		} else {
 | 
			
		||||
			glog.V(4).Infof("->Watcher(%d) is stopped.  Not calling Modify(%v)", i, obj)
 | 
			
		||||
		}
 | 
			
		||||
@@ -80,10 +89,10 @@ func (wd *WatcherDispatcher) Modify(obj runtime.Object) {
 | 
			
		||||
func (wd *WatcherDispatcher) Delete(lastValue runtime.Object) {
 | 
			
		||||
	wd.Lock()
 | 
			
		||||
	defer wd.Unlock()
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: watch.Deleted, Object: lastValue})
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: watch.Deleted, Object: copy(lastValue)})
 | 
			
		||||
	for _, watcher := range wd.watchers {
 | 
			
		||||
		if !watcher.IsStopped() {
 | 
			
		||||
			watcher.Delete(lastValue)
 | 
			
		||||
			watcher.Delete(copy(lastValue))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -92,10 +101,10 @@ func (wd *WatcherDispatcher) Delete(lastValue runtime.Object) {
 | 
			
		||||
func (wd *WatcherDispatcher) Error(errValue runtime.Object) {
 | 
			
		||||
	wd.Lock()
 | 
			
		||||
	defer wd.Unlock()
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: watch.Error, Object: errValue})
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: watch.Error, Object: copy(errValue)})
 | 
			
		||||
	for _, watcher := range wd.watchers {
 | 
			
		||||
		if !watcher.IsStopped() {
 | 
			
		||||
			watcher.Error(errValue)
 | 
			
		||||
			watcher.Error(copy(errValue))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -104,10 +113,10 @@ func (wd *WatcherDispatcher) Error(errValue runtime.Object) {
 | 
			
		||||
func (wd *WatcherDispatcher) Action(action watch.EventType, obj runtime.Object) {
 | 
			
		||||
	wd.Lock()
 | 
			
		||||
	defer wd.Unlock()
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: action, Object: obj})
 | 
			
		||||
	wd.eventsSoFar = append(wd.eventsSoFar, &watch.Event{Type: action, Object: copy(obj)})
 | 
			
		||||
	for _, watcher := range wd.watchers {
 | 
			
		||||
		if !watcher.IsStopped() {
 | 
			
		||||
			watcher.Action(action, obj)
 | 
			
		||||
			watcher.Action(action, copy(obj))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -146,7 +155,7 @@ func RegisterFakeCopyOnCreate(resource string, client *core.Fake, watcher *Watch
 | 
			
		||||
		obj := createAction.GetObject()
 | 
			
		||||
		go func() {
 | 
			
		||||
			watcher.Add(obj)
 | 
			
		||||
			objChan <- obj
 | 
			
		||||
			objChan <- copy(obj)
 | 
			
		||||
		}()
 | 
			
		||||
		return true, obj, nil
 | 
			
		||||
	})
 | 
			
		||||
@@ -164,7 +173,7 @@ func RegisterFakeCopyOnUpdate(resource string, client *core.Fake, watcher *Watch
 | 
			
		||||
		go func() {
 | 
			
		||||
			glog.V(4).Infof("Object updated. Writing to channel: %v", obj)
 | 
			
		||||
			watcher.Modify(obj)
 | 
			
		||||
			objChan <- obj
 | 
			
		||||
			objChan <- copy(obj)
 | 
			
		||||
		}()
 | 
			
		||||
		return true, obj, nil
 | 
			
		||||
	})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user