mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 02:34:03 +00:00
Fix deployment unit test by adding a dummy update reactor
This commit is contained in:
parent
64643c6582
commit
740aa93838
@ -420,8 +420,10 @@ func (fdc *DeploymentController) schedule(fd *extensionsv1.Deployment, clusters
|
|||||||
if fdPref != nil { // create a new planner if user specified a preference
|
if fdPref != nil { // create a new planner if user specified a preference
|
||||||
plannerToBeUsed = planner.NewPlanner(fdPref)
|
plannerToBeUsed = planner.NewPlanner(fdPref)
|
||||||
}
|
}
|
||||||
|
replicas := int64(0)
|
||||||
replicas := int64(*fd.Spec.Replicas)
|
if fd.Spec.Replicas != nil {
|
||||||
|
replicas = int64(*fd.Spec.Replicas)
|
||||||
|
}
|
||||||
var clusterNames []string
|
var clusterNames []string
|
||||||
for _, cluster := range clusters {
|
for _, cluster := range clusters {
|
||||||
clusterNames = append(clusterNames, cluster.Name)
|
clusterNames = append(clusterNames, cluster.Name)
|
||||||
|
@ -85,6 +85,9 @@ func TestDeploymentController(t *testing.T) {
|
|||||||
cluster2 := NewCluster("cluster2", apiv1.ConditionTrue)
|
cluster2 := NewCluster("cluster2", apiv1.ConditionTrue)
|
||||||
|
|
||||||
fakeClient := &fakefedclientset.Clientset{}
|
fakeClient := &fakefedclientset.Clientset{}
|
||||||
|
// Add an update reactor on fake client to return the desired updated object.
|
||||||
|
// This is a hack to workaround https://github.com/kubernetes/kubernetes/issues/40939.
|
||||||
|
AddFakeUpdateReactor("deployments", &fakeClient.Fake)
|
||||||
RegisterFakeList("clusters", &fakeClient.Fake, &fedv1.ClusterList{Items: []fedv1.Cluster{*cluster1}})
|
RegisterFakeList("clusters", &fakeClient.Fake, &fedv1.ClusterList{Items: []fedv1.Cluster{*cluster1}})
|
||||||
deploymentsWatch := RegisterFakeWatch("deployments", &fakeClient.Fake)
|
deploymentsWatch := RegisterFakeWatch("deployments", &fakeClient.Fake)
|
||||||
clusterWatch := RegisterFakeWatch("clusters", &fakeClient.Fake)
|
clusterWatch := RegisterFakeWatch("clusters", &fakeClient.Fake)
|
||||||
|
@ -226,6 +226,18 @@ func RegisterFakeCopyOnUpdate(resource string, client *core.Fake, watcher *Watch
|
|||||||
return objChan
|
return objChan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds an update reactor to the given fake client.
|
||||||
|
// The reactor just returns the object passed to update action.
|
||||||
|
// This is used as a hack to workaround https://github.com/kubernetes/kubernetes/issues/40939.
|
||||||
|
// Without this, all update actions using fake client return empty objects.
|
||||||
|
func AddFakeUpdateReactor(resource string, client *core.Fake) {
|
||||||
|
client.AddReactor("update", resource, func(action core.Action) (bool, runtime.Object, error) {
|
||||||
|
updateAction := action.(core.UpdateAction)
|
||||||
|
originalObj := updateAction.GetObject()
|
||||||
|
return true, originalObj, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// GetObjectFromChan tries to get an api object from the given channel
|
// GetObjectFromChan tries to get an api object from the given channel
|
||||||
// within a reasonable time.
|
// within a reasonable time.
|
||||||
func GetObjectFromChan(c chan runtime.Object) runtime.Object {
|
func GetObjectFromChan(c chan runtime.Object) runtime.Object {
|
||||||
|
Loading…
Reference in New Issue
Block a user