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


Golang intstr.FromString函數代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/util/intstr.FromString函數的典型用法代碼示例。如果您正苦於以下問題:Golang FromString函數的具體用法?Golang FromString怎麽用?Golang FromString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: createService

func createService(fcs *federation_internalclientset.Clientset, clusterClientSets []*release_1_3.Clientset, namespace string) {
    By("Creating a federated service")
    labels := map[string]string{
        "foo": "bar",
    }

    svc1port := "svc1"
    svc2port := "svc2"

    service := &api.Service{
        ObjectMeta: api.ObjectMeta{
            Name: FederatedServiceName,
        },
        Spec: api.ServiceSpec{
            Selector: labels,
            Ports: []api.ServicePort{
                {
                    Name:       "portname1",
                    Port:       80,
                    TargetPort: intstr.FromString(svc1port),
                },
                {
                    Name:       "portname2",
                    Port:       81,
                    TargetPort: intstr.FromString(svc2port),
                },
            },
        },
    }
    _, err := fcs.Core().Services(namespace).Create(service)
    Expect(err).NotTo(HaveOccurred())
    for _, cs := range clusterClientSets {
        waitForFederatedServiceShard(cs, namespace, service, 1)
    }
}
開發者ID:FlyWings,項目名稱:kubernetes,代碼行數:35,代碼來源:federated-service.go

示例2: SetDefaults_RollingDeploymentStrategyParams

func SetDefaults_RollingDeploymentStrategyParams(obj *RollingDeploymentStrategyParams) {
    if obj.IntervalSeconds == nil {
        obj.IntervalSeconds = mkintp(deployapi.DefaultRollingIntervalSeconds)
    }

    if obj.UpdatePeriodSeconds == nil {
        obj.UpdatePeriodSeconds = mkintp(deployapi.DefaultRollingUpdatePeriodSeconds)
    }

    if obj.TimeoutSeconds == nil {
        obj.TimeoutSeconds = mkintp(deployapi.DefaultRollingTimeoutSeconds)
    }

    if obj.UpdatePercent == nil {
        // Apply defaults.
        if obj.MaxUnavailable == nil {
            maxUnavailable := intstr.FromString("25%")
            obj.MaxUnavailable = &maxUnavailable
        }
        if obj.MaxSurge == nil {
            maxSurge := intstr.FromString("25%")
            obj.MaxSurge = &maxSurge
        }
    }
}
開發者ID:ZenoRewn,項目名稱:origin,代碼行數:25,代碼來源:defaults.go

示例3: TestDefaultResourceFromIngress

func TestDefaultResourceFromIngress(te *testing.T) {
    var (
        is  = assert.New(te)
        m   = NewCache()
        ing = &extensions.Ingress{
            ObjectMeta: api.ObjectMeta{Name: "ingress", Namespace: "test", UID: types.UID("one")},
            Spec: extensions.IngressSpec{
                Backend: &extensions.IngressBackend{
                    ServiceName: "service",
                    ServicePort: intstr.FromString("web"),
                },
            },
        }
        svc = &api.Service{
            ObjectMeta: api.ObjectMeta{Name: "service", Namespace: "test", UID: types.UID("two")},
            Spec: api.ServiceSpec{
                Type:      api.ServiceTypeClusterIP,
                ClusterIP: "1.2.3.4",
                Ports: []api.ServicePort{
                    api.ServicePort{Name: "web", Port: 80, TargetPort: intstr.FromString("http")},
                },
            },
        }
        end = &api.Endpoints{
            ObjectMeta: api.ObjectMeta{Name: "service", Namespace: "test", UID: types.UID("three")},
            Subsets: []api.EndpointSubset{
                api.EndpointSubset{
                    Addresses: []api.EndpointAddress{
                        api.EndpointAddress{IP: "10.11.12.13"},
                        api.EndpointAddress{IP: "10.20.21.23"},
                    },
                    Ports: []api.EndpointPort{
                        api.EndpointPort{Name: "web", Port: 8080, Protocol: api.ProtocolTCP},
                    },
                },
            },
        }
    )

    if testing.Verbose() {
        logger.Configure("debug", "[romulus-test] ", os.Stdout)
        defer logger.SetLevel("error")
    }

    m.SetServiceStore(cache.NewStore(cache.MetaNamespaceKeyFunc))
    m.SetEndpointsStore(cache.NewStore(cache.MetaNamespaceKeyFunc))
    m.endpoints.Add(end)
    m.service.Add(svc)

    list := resourcesFromIngress(m, ing)
    te.Logf("Default ResourceList: %v", list)
    is.True(len(list) > 0, "ResourceList should be non-zero")
    ma := list.Map()
    rsc, ok := ma["test.service.web"]
    if is.True(ok, "'test.service.web' not created: %v", list) {
        is.False(rsc.NoServers(), "%v should have servers", rsc)
    }
}
開發者ID:albertrdixon,項目名稱:romulus,代碼行數:58,代碼來源:resource_test.go

示例4: TestGetURLParts

func TestGetURLParts(t *testing.T) {
    testCases := []struct {
        probe *api.HTTPGetAction
        ok    bool
        host  string
        port  int
        path  string
    }{
        {&api.HTTPGetAction{Host: "", Port: intstr.FromInt(-1), Path: ""}, false, "", -1, ""},
        {&api.HTTPGetAction{Host: "", Port: intstr.FromString(""), Path: ""}, false, "", -1, ""},
        {&api.HTTPGetAction{Host: "", Port: intstr.FromString("-1"), Path: ""}, false, "", -1, ""},
        {&api.HTTPGetAction{Host: "", Port: intstr.FromString("not-found"), Path: ""}, false, "", -1, ""},
        {&api.HTTPGetAction{Host: "", Port: intstr.FromString("found"), Path: ""}, true, "127.0.0.1", 93, ""},
        {&api.HTTPGetAction{Host: "", Port: intstr.FromInt(76), Path: ""}, true, "127.0.0.1", 76, ""},
        {&api.HTTPGetAction{Host: "", Port: intstr.FromString("118"), Path: ""}, true, "127.0.0.1", 118, ""},
        {&api.HTTPGetAction{Host: "hostname", Port: intstr.FromInt(76), Path: "path"}, true, "hostname", 76, "path"},
    }

    for _, test := range testCases {
        state := api.PodStatus{PodIP: "127.0.0.1"}
        container := api.Container{
            Ports: []api.ContainerPort{{Name: "found", ContainerPort: 93}},
            LivenessProbe: &api.Probe{
                Handler: api.Handler{
                    HTTPGet: test.probe,
                },
            },
        }

        scheme := test.probe.Scheme
        if scheme == "" {
            scheme = api.URISchemeHTTP
        }
        host := test.probe.Host
        if host == "" {
            host = state.PodIP
        }
        port, err := extractPort(test.probe.Port, container)
        if test.ok && err != nil {
            t.Errorf("Unexpected error: %v", err)
        }
        path := test.probe.Path

        if !test.ok && err == nil {
            t.Errorf("Expected error for %+v, got %s%s:%d/%s", test, scheme, host, port, path)
        }
        if test.ok {
            if host != test.host || port != test.port || path != test.path {
                t.Errorf("Expected %s:%d/%s, got %s:%d/%s",
                    test.host, test.port, test.path, host, port, path)
            }
        }
    }
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:54,代碼來源:prober_test.go

示例5: TestMultipleControllers

// Verify that multiple controllers doesn't allow the PDB to be set true.
func TestMultipleControllers(t *testing.T) {
    const rcCount = 2
    const podCount = 2

    dc, ps := newFakeDisruptionController()

    pdb, pdbName := newPodDisruptionBudget(t, intstr.FromString("1%"))
    add(t, dc.pdbLister.Store, pdb)

    for i := 0; i < podCount; i++ {
        pod, _ := newPod(t, fmt.Sprintf("pod %d", i))
        add(t, dc.podLister.Indexer, pod)
    }
    dc.sync(pdbName)

    // No controllers yet => no disruption allowed
    ps.VerifyDisruptionAllowed(t, pdbName, 0)

    rc, _ := newReplicationController(t, 1)
    rc.Name = "rc 1"
    add(t, dc.rcLister.Indexer, rc)
    dc.sync(pdbName)

    // One RC and 200%>1% healthy => disruption allowed
    ps.VerifyDisruptionAllowed(t, pdbName, 1)

    rc, _ = newReplicationController(t, 1)
    rc.Name = "rc 2"
    add(t, dc.rcLister.Indexer, rc)
    dc.sync(pdbName)

    // 100%>1% healthy BUT two RCs => no disruption allowed
    ps.VerifyDisruptionAllowed(t, pdbName, 0)
}
開發者ID:Q-Lee,項目名稱:kubernetes,代碼行數:35,代碼來源:disruption_test.go

示例6: Convert_v1beta3_RollingDeploymentStrategyParams_To_api_RollingDeploymentStrategyParams

func Convert_v1beta3_RollingDeploymentStrategyParams_To_api_RollingDeploymentStrategyParams(in *RollingDeploymentStrategyParams, out *newer.RollingDeploymentStrategyParams, s conversion.Scope) error {
    out.UpdatePeriodSeconds = in.UpdatePeriodSeconds
    out.IntervalSeconds = in.IntervalSeconds
    out.TimeoutSeconds = in.TimeoutSeconds
    out.UpdatePercent = in.UpdatePercent

    if in.Pre != nil {
        if err := s.Convert(&in.Pre, &out.Pre, 0); err != nil {
            return err
        }
    }
    if in.Post != nil {
        if err := s.Convert(&in.Post, &out.Post, 0); err != nil {
            return err
        }
    }

    if in.UpdatePercent != nil {
        pct := intstr.FromString(fmt.Sprintf("%d%%", int(math.Abs(float64(*in.UpdatePercent)))))
        if *in.UpdatePercent > 0 {
            out.MaxSurge = pct
        } else {
            out.MaxUnavailable = pct
        }
    } else {
        if err := s.Convert(in.MaxUnavailable, &out.MaxUnavailable, 0); err != nil {
            return err
        }
        if err := s.Convert(in.MaxSurge, &out.MaxSurge, 0); err != nil {
            return err
        }
    }
    return nil
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:34,代碼來源:conversion.go

示例7: Generate

// Generate accepts a set of parameters and maps them into a new route
func (RouteGenerator) Generate(genericParams map[string]interface{}) (runtime.Object, error) {
    var (
        labels map[string]string
        err    error
    )

    params := map[string]string{}
    for key, value := range genericParams {
        strVal, isString := value.(string)
        if !isString {
            return nil, fmt.Errorf("expected string, saw %v for '%s'", value, key)
        }
        params[key] = strVal
    }

    labelString, found := params["labels"]
    if found && len(labelString) > 0 {
        labels, err = kubectl.ParseLabels(labelString)
        if err != nil {
            return nil, err
        }
    }

    name, found := params["name"]
    if !found || len(name) == 0 {
        name, found = params["default-name"]
        if !found || len(name) == 0 {
            return nil, fmt.Errorf("'name' is a required parameter.")
        }
    }

    route := &api.Route{
        ObjectMeta: kapi.ObjectMeta{
            Name:   name,
            Labels: labels,
        },
        Spec: api.RouteSpec{
            Host: params["hostname"],
            Path: params["path"],
            To: api.RouteTargetReference{
                Name: params["default-name"],
            },
        },
    }

    portString := params["port"]
    if len(portString) > 0 {
        var targetPort intstr.IntOrString
        if port, err := strconv.Atoi(portString); err == nil {
            targetPort = intstr.FromInt(port)
        } else {
            targetPort = intstr.FromString(portString)
        }
        route.Spec.Port = &api.RoutePort{
            TargetPort: targetPort,
        }
    }

    return route, nil
}
開發者ID:Xmagicer,項目名稱:origin,代碼行數:61,代碼來源:generate.go

示例8: TestStatefulSetController

func TestStatefulSetController(t *testing.T) {
    labels := map[string]string{
        "foo": "bar",
        "baz": "quux",
    }

    dc, ps := newFakeDisruptionController()

    // 34% should round up to 2
    pdb, pdbName := newPodDisruptionBudget(t, intstr.FromString("34%"))
    add(t, dc.pdbLister.Store, pdb)
    ss, _ := newStatefulSet(t, 3)
    add(t, dc.ssLister.Store, ss)
    dc.sync(pdbName)

    // It starts out at 0 expected because, with no pods, the PDB doesn't know
    // about the SS.  This is a known bug.  TODO(mml): file issue
    ps.VerifyPdbStatus(t, pdbName, 0, 0, 0, 0, map[string]metav1.Time{})

    pods := []*v1.Pod{}

    for i := int32(0); i < 3; i++ {
        pod, _ := newPod(t, fmt.Sprintf("foobar %d", i))
        pods = append(pods, pod)
        pod.Labels = labels
        add(t, dc.podLister.Indexer, pod)
        dc.sync(pdbName)
        if i < 2 {
            ps.VerifyPdbStatus(t, pdbName, 0, i+1, 2, 3, map[string]metav1.Time{})
        } else {
            ps.VerifyPdbStatus(t, pdbName, 1, 3, 2, 3, map[string]metav1.Time{})
        }
    }
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:34,代碼來源:disruption_test.go

示例9: TestSetDefaultServicePort

func TestSetDefaultServicePort(t *testing.T) {
    if !registered.IsAllowedVersion(versioned.SchemeGroupVersion) {
        return
    }

    // Unchanged if set.
    in := &versioned.Service{Spec: versioned.ServiceSpec{
        Ports: []versioned.ServicePort{
            {Protocol: "UDP", Port: 9376, TargetPort: intstr.FromString("p")},
            {Protocol: "UDP", Port: 8675, TargetPort: intstr.FromInt(309)},
        },
    }}
    out := roundTrip(t, runtime.Object(in)).(*versioned.Service)
    if out.Spec.Ports[0].Protocol != versioned.ProtocolUDP {
        t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[0].Protocol)
    }
    if out.Spec.Ports[0].TargetPort != intstr.FromString("p") {
        t.Errorf("Expected port %d, got %s", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
    }
    if out.Spec.Ports[1].Protocol != versioned.ProtocolUDP {
        t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[1].Protocol)
    }
    if out.Spec.Ports[1].TargetPort != intstr.FromInt(309) {
        t.Errorf("Expected port %d, got %s", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
    }

    // Defaulted.
    in = &versioned.Service{Spec: versioned.ServiceSpec{
        Ports: []versioned.ServicePort{
            {Protocol: "", Port: 9376, TargetPort: intstr.FromString("")},
            {Protocol: "", Port: 8675, TargetPort: intstr.FromInt(0)},
        },
    }}
    out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
    if out.Spec.Ports[0].Protocol != versioned.ProtocolTCP {
        t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[0].Protocol)
    }
    if out.Spec.Ports[0].TargetPort != intstr.FromInt(in.Spec.Ports[0].Port) {
        t.Errorf("Expected port %d, got %d", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
    }
    if out.Spec.Ports[1].Protocol != versioned.ProtocolTCP {
        t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[1].Protocol)
    }
    if out.Spec.Ports[1].TargetPort != intstr.FromInt(in.Spec.Ports[1].Port) {
        t.Errorf("Expected port %d, got %d", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
    }
}
開發者ID:richm,項目名稱:origin,代碼行數:47,代碼來源:defaults_test.go

示例10: TestPodDisruptionBudgetStrategy

func TestPodDisruptionBudgetStrategy(t *testing.T) {
    ctx := api.NewDefaultContext()
    if !Strategy.NamespaceScoped() {
        t.Errorf("PodDisruptionBudget must be namespace scoped")
    }
    if Strategy.AllowCreateOnUpdate() {
        t.Errorf("PodDisruptionBudget should not allow create on update")
    }

    validSelector := map[string]string{"a": "b"}
    pdb := &policy.PodDisruptionBudget{
        ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
        Spec: policy.PodDisruptionBudgetSpec{
            MinAvailable: intstr.FromInt(3),
            Selector:     &unversioned.LabelSelector{MatchLabels: validSelector},
        },
    }

    Strategy.PrepareForCreate(pdb)
    errs := Strategy.Validate(ctx, pdb)
    if len(errs) != 0 {
        t.Errorf("Unexpected error validating %v", errs)
    }

    newPdb := &policy.PodDisruptionBudget{
        ObjectMeta: api.ObjectMeta{Name: pdb.Name, Namespace: pdb.Namespace},
        Spec:       pdb.Spec,
        Status: policy.PodDisruptionBudgetStatus{
            PodDisruptionAllowed: true,
            CurrentHealthy:       3,
            DesiredHealthy:       3,
            ExpectedPods:         3,
        },
    }

    // Nothing in Spec changes: OK
    Strategy.PrepareForUpdate(newPdb, pdb)
    errs = Strategy.ValidateUpdate(ctx, newPdb, pdb)
    if len(errs) != 0 {
        t.Errorf("Unexpected error updating PodDisruptionBudget.")
    }

    // Changing the selector?  No.
    newPdb.Spec.Selector = &unversioned.LabelSelector{MatchLabels: map[string]string{"a": "bar"}}
    Strategy.PrepareForUpdate(newPdb, pdb)
    errs = Strategy.ValidateUpdate(ctx, newPdb, pdb)
    if len(errs) == 0 {
        t.Errorf("Expected a validation error since updates are disallowed on poddisruptionbudgets.")
    }
    newPdb.Spec.Selector = pdb.Spec.Selector

    // Changing MinAvailable?  Also no.
    newPdb.Spec.MinAvailable = intstr.FromString("28%")
    Strategy.PrepareForUpdate(newPdb, pdb)
    errs = Strategy.ValidateUpdate(ctx, newPdb, pdb)
    if len(errs) == 0 {
        t.Errorf("Expected a validation error since updates are disallowed on poddisruptionbudgets.")
    }
}
開發者ID:40a,項目名稱:bootkube,代碼行數:59,代碼來源:strategy_test.go

示例11: TestPDBNotExist

// Test pdb doesn't exist
func TestPDBNotExist(t *testing.T) {
    dc, _ := newFakeDisruptionController()
    pdb, _ := newPodDisruptionBudget(t, intstr.FromString("67%"))
    add(t, dc.pdbLister.Store, pdb)
    if err := dc.sync("notExist"); err != nil {
        t.Errorf("Unexpected error: %v, expect nil", err)
    }
}
開發者ID:Q-Lee,項目名稱:kubernetes,代碼行數:9,代碼來源:disruption_test.go

示例12: TestSetDefaultServicePort

func TestSetDefaultServicePort(t *testing.T) {
    // Unchanged if set.
    in := &v1.Service{Spec: v1.ServiceSpec{
        Ports: []v1.ServicePort{
            {Protocol: "UDP", Port: 9376, TargetPort: intstr.FromString("p")},
            {Protocol: "UDP", Port: 8675, TargetPort: intstr.FromInt(309)},
        },
    }}
    out := roundTrip(t, runtime.Object(in)).(*v1.Service)
    if out.Spec.Ports[0].Protocol != v1.ProtocolUDP {
        t.Errorf("Expected protocol %s, got %s", v1.ProtocolUDP, out.Spec.Ports[0].Protocol)
    }
    if out.Spec.Ports[0].TargetPort != intstr.FromString("p") {
        t.Errorf("Expected port %v, got %v", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
    }
    if out.Spec.Ports[1].Protocol != v1.ProtocolUDP {
        t.Errorf("Expected protocol %s, got %s", v1.ProtocolUDP, out.Spec.Ports[1].Protocol)
    }
    if out.Spec.Ports[1].TargetPort != intstr.FromInt(309) {
        t.Errorf("Expected port %v, got %v", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
    }

    // Defaulted.
    in = &v1.Service{Spec: v1.ServiceSpec{
        Ports: []v1.ServicePort{
            {Protocol: "", Port: 9376, TargetPort: intstr.FromString("")},
            {Protocol: "", Port: 8675, TargetPort: intstr.FromInt(0)},
        },
    }}
    out = roundTrip(t, runtime.Object(in)).(*v1.Service)
    if out.Spec.Ports[0].Protocol != v1.ProtocolTCP {
        t.Errorf("Expected protocol %s, got %s", v1.ProtocolTCP, out.Spec.Ports[0].Protocol)
    }
    if out.Spec.Ports[0].TargetPort != intstr.FromInt(int(in.Spec.Ports[0].Port)) {
        t.Errorf("Expected port %v, got %v", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
    }
    if out.Spec.Ports[1].Protocol != v1.ProtocolTCP {
        t.Errorf("Expected protocol %s, got %s", v1.ProtocolTCP, out.Spec.Ports[1].Protocol)
    }
    if out.Spec.Ports[1].TargetPort != intstr.FromInt(int(in.Spec.Ports[1].Port)) {
        t.Errorf("Expected port %v, got %v", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
    }
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:43,代碼來源:defaults_test.go

示例13: TestUpdate_assignOriginalAnnotation

func TestUpdate_assignOriginalAnnotation(t *testing.T) {
    oldRc := oldRc(1, 1)
    delete(oldRc.Annotations, originalReplicasAnnotation)
    newRc := newRc(1, 1)
    var updatedOldRc *api.ReplicationController
    fake := &testclient.Fake{}
    fake.AddReactor("*", "*", func(action testclient.Action) (handled bool, ret runtime.Object, err error) {
        switch a := action.(type) {
        case testclient.GetAction:
            return true, oldRc, nil
        case testclient.UpdateAction:
            updatedOldRc = a.GetObject().(*api.ReplicationController)
            return true, updatedOldRc, nil
        }
        return false, nil, nil
    })
    updater := &RollingUpdater{
        c:  fake,
        ns: "default",
        scaleAndWait: func(rc *api.ReplicationController, retry *RetryParams, wait *RetryParams) (*api.ReplicationController, error) {
            return rc, nil
        },
        getOrCreateTargetController: func(controller *api.ReplicationController, sourceId string) (*api.ReplicationController, bool, error) {
            return newRc, false, nil
        },
        cleanup: func(oldRc, newRc *api.ReplicationController, config *RollingUpdaterConfig) error {
            return nil
        },
        getReadyPods: func(oldRc, newRc *api.ReplicationController) (int32, int32, error) {
            return 1, 1, nil
        },
    }
    var buffer bytes.Buffer
    config := &RollingUpdaterConfig{
        Out:            &buffer,
        OldRc:          oldRc,
        NewRc:          newRc,
        UpdatePeriod:   0,
        Interval:       time.Millisecond,
        Timeout:        time.Millisecond,
        CleanupPolicy:  DeleteRollingUpdateCleanupPolicy,
        MaxUnavailable: intstr.FromString("100%"),
    }
    err := updater.Update(config)
    if err != nil {
        t.Fatalf("unexpected error: %v", err)
    }
    if updatedOldRc == nil {
        t.Fatalf("expected rc to be updated")
    }
    if e, a := "1", updatedOldRc.Annotations[originalReplicasAnnotation]; e != a {
        t.Fatalf("expected annotation value %s, got %s", e, a)
    }
}
開發者ID:FlyWings,項目名稱:kubernetes,代碼行數:54,代碼來源:rolling_updater_test.go

示例14: SetDefaults_RollingDeploymentStrategyParams

func SetDefaults_RollingDeploymentStrategyParams(obj *RollingDeploymentStrategyParams) {
    if obj.IntervalSeconds == nil {
        obj.IntervalSeconds = mkintp(deployapi.DefaultRollingIntervalSeconds)
    }

    if obj.UpdatePeriodSeconds == nil {
        obj.UpdatePeriodSeconds = mkintp(deployapi.DefaultRollingUpdatePeriodSeconds)
    }

    if obj.TimeoutSeconds == nil {
        obj.TimeoutSeconds = mkintp(deployapi.DefaultRollingTimeoutSeconds)
    }

    if obj.MaxUnavailable == nil && obj.MaxSurge == nil {
        maxUnavailable := intstr.FromString("25%")
        obj.MaxUnavailable = &maxUnavailable

        maxSurge := intstr.FromString("25%")
        obj.MaxSurge = &maxSurge
    }

    if obj.MaxUnavailable == nil && obj.MaxSurge != nil &&
        (*obj.MaxSurge == intstr.FromInt(0) || *obj.MaxSurge == intstr.FromString("0%")) {
        maxUnavailable := intstr.FromString("25%")
        obj.MaxUnavailable = &maxUnavailable
    }

    if obj.MaxSurge == nil && obj.MaxUnavailable != nil &&
        (*obj.MaxUnavailable == intstr.FromInt(0) || *obj.MaxUnavailable == intstr.FromString("0%")) {
        maxSurge := intstr.FromString("25%")
        obj.MaxSurge = &maxSurge
    }
}
開發者ID:juanluisvaladas,項目名稱:origin,代碼行數:33,代碼來源:defaults.go

示例15: TestGetTCPAddrParts

func TestGetTCPAddrParts(t *testing.T) {
    testCases := []struct {
        probe *api.TCPSocketAction
        ok    bool
        host  string
        port  int
    }{
        {&api.TCPSocketAction{Port: intstr.FromInt(-1)}, false, "", -1},
        {&api.TCPSocketAction{Port: intstr.FromString("")}, false, "", -1},
        {&api.TCPSocketAction{Port: intstr.FromString("-1")}, false, "", -1},
        {&api.TCPSocketAction{Port: intstr.FromString("not-found")}, false, "", -1},
        {&api.TCPSocketAction{Port: intstr.FromString("found")}, true, "1.2.3.4", 93},
        {&api.TCPSocketAction{Port: intstr.FromInt(76)}, true, "1.2.3.4", 76},
        {&api.TCPSocketAction{Port: intstr.FromString("118")}, true, "1.2.3.4", 118},
    }

    for _, test := range testCases {
        host := "1.2.3.4"
        container := api.Container{
            Ports: []api.ContainerPort{{Name: "found", ContainerPort: 93}},
            LivenessProbe: &api.Probe{
                Handler: api.Handler{
                    TCPSocket: test.probe,
                },
            },
        }
        port, err := extractPort(test.probe.Port, container)
        if !test.ok && err == nil {
            t.Errorf("Expected error for %+v, got %s:%d", test, host, port)
        }
        if test.ok && err != nil {
            t.Errorf("Unexpected error: %v", err)
        }
        if test.ok {
            if host != test.host || port != test.port {
                t.Errorf("Expected %s:%d, got %s:%d", test.host, test.port, host, port)
            }
        }
    }
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:40,代碼來源:prober_test.go


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