當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Clientset.Actions方法代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/client/testing/fake.Clientset.Actions方法的典型用法代碼示例。如果您正苦於以下問題:Golang Clientset.Actions方法的具體用法?Golang Clientset.Actions怎麽用?Golang Clientset.Actions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/kubernetes/pkg/client/testing/fake.Clientset的用法示例。


在下文中一共展示了Clientset.Actions方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestDeploymentController_reconcileNewReplicaSet

func TestDeploymentController_reconcileNewReplicaSet(t *testing.T) {
    tests := []struct {
        deploymentReplicas  int
        maxSurge            intstr.IntOrString
        oldReplicas         int
        newReplicas         int
        scaleExpected       bool
        expectedNewReplicas int
    }{
        {
            // Should not scale up.
            deploymentReplicas: 10,
            maxSurge:           intstr.FromInt(0),
            oldReplicas:        10,
            newReplicas:        0,
            scaleExpected:      false,
        },
        {
            deploymentReplicas:  10,
            maxSurge:            intstr.FromInt(2),
            oldReplicas:         10,
            newReplicas:         0,
            scaleExpected:       true,
            expectedNewReplicas: 2,
        },
        {
            deploymentReplicas:  10,
            maxSurge:            intstr.FromInt(2),
            oldReplicas:         5,
            newReplicas:         0,
            scaleExpected:       true,
            expectedNewReplicas: 7,
        },
        {
            deploymentReplicas: 10,
            maxSurge:           intstr.FromInt(2),
            oldReplicas:        10,
            newReplicas:        2,
            scaleExpected:      false,
        },
        {
            // Should scale down.
            deploymentReplicas:  10,
            maxSurge:            intstr.FromInt(2),
            oldReplicas:         2,
            newReplicas:         11,
            scaleExpected:       true,
            expectedNewReplicas: 10,
        },
    }

    for i, test := range tests {
        t.Logf("executing scenario %d", i)
        newRS := rs("foo-v2", test.newReplicas, nil)
        oldRS := rs("foo-v2", test.oldReplicas, nil)
        allRSs := []*exp.ReplicaSet{newRS, oldRS}
        deployment := deployment("foo", test.deploymentReplicas, test.maxSurge, intstr.FromInt(0))
        fake := fake.Clientset{}
        controller := &DeploymentController{
            client:        &fake,
            eventRecorder: &record.FakeRecorder{},
        }
        scaled, err := controller.reconcileNewReplicaSet(allRSs, newRS, deployment)
        if err != nil {
            t.Errorf("unexpected error: %v", err)
            continue
        }
        if !test.scaleExpected {
            if scaled || len(fake.Actions()) > 0 {
                t.Errorf("unexpected scaling: %v", fake.Actions())
            }
            continue
        }
        if test.scaleExpected && !scaled {
            t.Errorf("expected scaling to occur")
            continue
        }
        if len(fake.Actions()) != 1 {
            t.Errorf("expected 1 action during scale, got: %v", fake.Actions())
            continue
        }
        updated := fake.Actions()[0].(testclient.UpdateAction).GetObject().(*exp.ReplicaSet)
        if e, a := test.expectedNewReplicas, updated.Spec.Replicas; e != a {
            t.Errorf("expected update to %d replicas, got %d", e, a)
        }
    }
}
開發者ID:richm,項目名稱:origin,代碼行數:87,代碼來源:deployment_controller_test.go

示例2: TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate

func TestDeploymentController_scaleDownOldReplicaSetsForRollingUpdate(t *testing.T) {
    tests := []struct {
        deploymentReplicas  int
        maxUnavailable      intstr.IntOrString
        readyPods           int
        oldReplicas         int
        scaleExpected       bool
        expectedOldReplicas int
    }{
        {
            deploymentReplicas: 10,
            maxUnavailable:     intstr.FromInt(0),
            readyPods:          10,
            oldReplicas:        10,
            scaleExpected:      false,
        },
        {
            deploymentReplicas:  10,
            maxUnavailable:      intstr.FromInt(2),
            readyPods:           10,
            oldReplicas:         10,
            scaleExpected:       true,
            expectedOldReplicas: 8,
        },
        {
            deploymentReplicas: 10,
            maxUnavailable:     intstr.FromInt(2),
            readyPods:          8,
            oldReplicas:        10,
            scaleExpected:      false,
        },
        {
            deploymentReplicas: 10,
            maxUnavailable:     intstr.FromInt(2),
            readyPods:          10,
            oldReplicas:        0,
            scaleExpected:      false,
        },
    }

    for i, test := range tests {
        t.Logf("executing scenario %d", i)
        oldRS := rs("foo-v2", test.oldReplicas, nil)
        allRSs := []*exp.ReplicaSet{oldRS}
        oldRSs := []*exp.ReplicaSet{oldRS}
        deployment := deployment("foo", test.deploymentReplicas, intstr.FromInt(0), test.maxUnavailable)
        fakeClientset := fake.Clientset{}
        fakeClientset.AddReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) {
            switch action.(type) {
            case core.ListAction:
                podList := &api.PodList{}
                for podIndex := 0; podIndex < test.readyPods; podIndex++ {
                    podList.Items = append(podList.Items, api.Pod{
                        ObjectMeta: api.ObjectMeta{
                            Name:   fmt.Sprintf("%s-pod-%d", oldRS.Name, podIndex),
                            Labels: map[string]string{"foo": "bar"},
                        },
                        Status: api.PodStatus{
                            Conditions: []api.PodCondition{
                                {
                                    Type:   api.PodReady,
                                    Status: api.ConditionTrue,
                                },
                            },
                        },
                    })
                }
                return true, podList, nil
            }
            return false, nil, nil
        })
        controller := &DeploymentController{
            client:        &fakeClientset,
            eventRecorder: &record.FakeRecorder{},
        }
        scaled, err := controller.scaleDownOldReplicaSetsForRollingUpdate(allRSs, oldRSs, deployment)
        if err != nil {
            t.Errorf("unexpected error: %v", err)
            continue
        }
        if !test.scaleExpected {
            if scaled != 0 {
                t.Errorf("unexpected scaling: %v", fakeClientset.Actions())
            }
            continue
        }
        if test.scaleExpected && scaled == 0 {
            t.Errorf("expected scaling to occur; actions: %v", fakeClientset.Actions())
            continue
        }
        // There are both list and update actions logged, so extract the update
        // action for verification.
        var updateAction testclient.UpdateAction
        for _, action := range fakeClientset.Actions() {
            switch a := action.(type) {
            case testclient.UpdateAction:
                if updateAction != nil {
                    t.Errorf("expected only 1 update action; had %v and found %v", updateAction, a)
                } else {
                    updateAction = a
//.........這裏部分代碼省略.........
開發者ID:richm,項目名稱:origin,代碼行數:101,代碼來源:deployment_controller_test.go

示例3: TestDeploymentController_reconcileOldReplicaSets


//.........這裏部分代碼省略.........
        oldSelector := map[string]string{"foo": "old"}
        newRS := rs("foo-new", test.newReplicas, newSelector)
        oldRS := rs("foo-old", test.oldReplicas, oldSelector)
        oldRSs := []*exp.ReplicaSet{oldRS}
        allRSs := []*exp.ReplicaSet{oldRS, newRS}

        deployment := deployment("foo", test.deploymentReplicas, intstr.FromInt(0), test.maxUnavailable)
        fakeClientset := fake.Clientset{}
        fakeClientset.AddReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) {
            switch action.(type) {
            case core.ListAction:
                podList := &api.PodList{}
                for podIndex := 0; podIndex < test.readyPodsFromOldRS; podIndex++ {
                    podList.Items = append(podList.Items, api.Pod{
                        ObjectMeta: api.ObjectMeta{
                            Name:   fmt.Sprintf("%s-oldReadyPod-%d", oldRS.Name, podIndex),
                            Labels: oldSelector,
                        },
                        Status: api.PodStatus{
                            Conditions: []api.PodCondition{
                                {
                                    Type:   api.PodReady,
                                    Status: api.ConditionTrue,
                                },
                            },
                        },
                    })
                }
                for podIndex := 0; podIndex < test.oldReplicas-test.readyPodsFromOldRS; podIndex++ {
                    podList.Items = append(podList.Items, api.Pod{
                        ObjectMeta: api.ObjectMeta{
                            Name:   fmt.Sprintf("%s-oldUnhealthyPod-%d", oldRS.Name, podIndex),
                            Labels: oldSelector,
                        },
                        Status: api.PodStatus{
                            Conditions: []api.PodCondition{
                                {
                                    Type:   api.PodReady,
                                    Status: api.ConditionFalse,
                                },
                            },
                        },
                    })
                }
                for podIndex := 0; podIndex < test.readyPodsFromNewRS; podIndex++ {
                    podList.Items = append(podList.Items, api.Pod{
                        ObjectMeta: api.ObjectMeta{
                            Name:   fmt.Sprintf("%s-newReadyPod-%d", oldRS.Name, podIndex),
                            Labels: newSelector,
                        },
                        Status: api.PodStatus{
                            Conditions: []api.PodCondition{
                                {
                                    Type:   api.PodReady,
                                    Status: api.ConditionTrue,
                                },
                            },
                        },
                    })
                }
                for podIndex := 0; podIndex < test.oldReplicas-test.readyPodsFromOldRS; podIndex++ {
                    podList.Items = append(podList.Items, api.Pod{
                        ObjectMeta: api.ObjectMeta{
                            Name:   fmt.Sprintf("%s-newUnhealthyPod-%d", oldRS.Name, podIndex),
                            Labels: newSelector,
                        },
                        Status: api.PodStatus{
                            Conditions: []api.PodCondition{
                                {
                                    Type:   api.PodReady,
                                    Status: api.ConditionFalse,
                                },
                            },
                        },
                    })
                }
                return true, podList, nil
            }
            return false, nil, nil
        })
        controller := &DeploymentController{
            client:        &fakeClientset,
            eventRecorder: &record.FakeRecorder{},
        }

        scaled, err := controller.reconcileOldReplicaSets(allRSs, oldRSs, newRS, deployment, false)
        if err != nil {
            t.Errorf("unexpected error: %v", err)
            continue
        }
        if !test.scaleExpected && scaled {
            t.Errorf("unexpected scaling: %v", fakeClientset.Actions())
        }
        if test.scaleExpected && !scaled {
            t.Errorf("expected scaling to occur")
            continue
        }
        continue
    }
}
開發者ID:richm,項目名稱:origin,代碼行數:101,代碼來源:deployment_controller_test.go


注:本文中的k8s/io/kubernetes/pkg/client/testing/fake.Clientset.Actions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。