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


Golang v1.Time類代碼示例

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


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

示例1: Convert_Slice_string_To_unversioned_Time

// Convert_Slice_string_To_unversioned_Time allows converting a URL query parameter value
func Convert_Slice_string_To_unversioned_Time(input *[]string, out *metav1.Time, s conversion.Scope) error {
    str := ""
    if len(*input) > 0 {
        str = (*input)[0]
    }
    return out.UnmarshalQueryParameter(str)
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:8,代碼來源:conversion.go

示例2: GetDeletionTimestamp

func (u *Unstructured) GetDeletionTimestamp() *metav1.Time {
    var timestamp metav1.Time
    timestamp.UnmarshalQueryParameter(getNestedString(u.Object, "metadata", "deletionTimestamp"))
    if timestamp.IsZero() {
        return nil
    }
    return &timestamp
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:8,代碼來源:unstructured.go

示例3: TestScaleDownRCImmediately

func TestScaleDownRCImmediately(t *testing.T) {
    time := metav1.Time{Time: time.Now()}
    tc := testCase{
        minReplicas:         2,
        maxReplicas:         5,
        initialReplicas:     6,
        desiredReplicas:     5,
        CPUTarget:           50,
        reportedLevels:      []uint64{8000, 9500, 1000},
        reportedCPURequests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},
        useMetricsApi:       true,
        lastScaleTime:       &time,
    }
    tc.runTest(t)
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:15,代碼來源:horizontal_test.go

示例4: TestScaleUpRCImmediately

func TestScaleUpRCImmediately(t *testing.T) {
    time := metav1.Time{Time: time.Now()}
    tc := testCase{
        minReplicas:         2,
        maxReplicas:         6,
        initialReplicas:     1,
        desiredReplicas:     2,
        verifyCPUCurrent:    true,
        reportedLevels:      []uint64{0, 0, 0, 0},
        reportedCPURequests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},
        useMetricsApi:       true,
        lastScaleTime:       &time,
    }
    tc.runTest(t)
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:15,代碼來源:horizontal_test.go

示例5: makeEvent

func (recorder *recorderImpl) makeEvent(ref *v1.ObjectReference, eventtype, reason, message string) *v1.Event {
    t := metav1.Time{Time: recorder.clock.Now()}
    namespace := ref.Namespace
    if namespace == "" {
        namespace = v1.NamespaceDefault
    }
    return &v1.Event{
        ObjectMeta: metav1.ObjectMeta{
            Name:      fmt.Sprintf("%v.%x", ref.Name, t.UnixNano()),
            Namespace: namespace,
        },
        InvolvedObject: *ref,
        Reason:         reason,
        Message:        message,
        FirstTimestamp: t,
        LastTimestamp:  t,
        Count:          1,
        Type:           eventtype,
    }
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:20,代碼來源:event.go

示例6: TestSelectorUpdate

// TestSelectorUpdate ensures that from two overlapping deployments, the one that is working won't
// be marked as overlapping if its selector is updated but still overlaps with the other one.
func TestSelectorUpdate(t *testing.T) {
    f := newFixture(t)
    now := metav1.Now()
    later := metav1.Time{Time: now.Add(time.Minute)}
    selectorUpdated := metav1.Time{Time: later.Add(time.Minute)}

    foo := newDeployment("foo", 1, nil, nil, nil, map[string]string{"foo": "bar"})
    foo.CreationTimestamp = now
    foo.Annotations = map[string]string{util.SelectorUpdateAnnotation: selectorUpdated.Format(time.RFC3339)}
    bar := newDeployment("bar", 1, nil, nil, nil, map[string]string{"foo": "bar", "app": "baz"})
    bar.CreationTimestamp = later
    bar.Annotations = map[string]string{util.OverlapAnnotation: "foo"}

    f.dLister = append(f.dLister, foo, bar)
    f.objects = append(f.objects, foo, bar)

    f.expectCreateRSAction(newReplicaSet(foo, "foo-rs", 1))
    f.expectUpdateDeploymentStatusAction(foo)
    f.expectUpdateDeploymentStatusAction(foo)
    f.run(getKey(foo, t))

    for _, a := range filterInformerActions(f.client.Actions()) {
        action, ok := a.(core.UpdateAction)
        if !ok {
            continue
        }
        d, ok := action.GetObject().(*extensions.Deployment)
        if !ok {
            continue
        }

        if d.Name == "foo" && len(d.Annotations[util.OverlapAnnotation]) > 0 {
            t.Errorf("deployment %q should not have the overlapping annotation", d.Name)
        }
        if d.Name == "bar" && len(d.Annotations[util.OverlapAnnotation]) == 0 {
            t.Errorf("deployment %q should have the overlapping annotation", d.Name)
        }
    }
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:41,代碼來源:deployment_controller_test.go

示例7: TestSelectorUpdatedBefore

func TestSelectorUpdatedBefore(t *testing.T) {
    now := metav1.Now()
    later := metav1.Time{Time: now.Add(time.Minute)}
    selectorUpdated := metav1.Time{Time: later.Add(time.Minute)}
    selectorUpdatedLater := metav1.Time{Time: selectorUpdated.Add(time.Minute)}

    tests := []struct {
        name string

        d1                 extensions.Deployment
        creationTimestamp1 *metav1.Time
        selectorUpdated1   *metav1.Time

        d2                 extensions.Deployment
        creationTimestamp2 *metav1.Time
        selectorUpdated2   *metav1.Time

        expected bool
    }{
        {
            name: "d1 created before d2",

            d1:                 generateDeployment("foo"),
            creationTimestamp1: &now,

            d2:                 generateDeployment("bar"),
            creationTimestamp2: &later,

            expected: true,
        },
        {
            name: "d1 created after d2",

            d1:                 generateDeployment("foo"),
            creationTimestamp1: &later,

            d2:                 generateDeployment("bar"),
            creationTimestamp2: &now,

            expected: false,
        },
        {
            // Think of the following scenario:
            // d1 is created first, d2 is created after and its selector overlaps
            // with d1. d2 is marked as overlapping correctly. If d1's selector is
            // updated and continues to overlap with the selector of d2 then d1 is
            // now marked overlapping and d2 is cleaned up. Proved by the following
            // test case. Callers of SelectorUpdatedBefore should first check for
            // the existence of the overlapping annotation in any of the two deployments
            // prior to comparing their timestamps and as a matter of fact this is
            // now handled in `(dc *DeploymentController) handleOverlap`.
            name: "d1 created before d2 but updated its selector afterwards",

            d1:                 generateDeployment("foo"),
            creationTimestamp1: &now,
            selectorUpdated1:   &selectorUpdated,

            d2:                 generateDeployment("bar"),
            creationTimestamp2: &later,

            expected: false,
        },
        {
            name: "d1 selector is older than d2",

            d1:               generateDeployment("foo"),
            selectorUpdated1: &selectorUpdated,

            d2:               generateDeployment("bar"),
            selectorUpdated2: &selectorUpdatedLater,

            expected: true,
        },
        {
            name: "d1 selector is younger than d2",

            d1:               generateDeployment("foo"),
            selectorUpdated1: &selectorUpdatedLater,

            d2:               generateDeployment("bar"),
            selectorUpdated2: &selectorUpdated,

            expected: false,
        },
    }

    for _, test := range tests {
        t.Logf("running scenario %q", test.name)

        if test.creationTimestamp1 != nil {
            test.d1.CreationTimestamp = *test.creationTimestamp1
        }
        if test.creationTimestamp2 != nil {
            test.d2.CreationTimestamp = *test.creationTimestamp2
        }
        if test.selectorUpdated1 != nil {
            test.d1.Annotations[SelectorUpdateAnnotation] = test.selectorUpdated1.Format(time.RFC3339)
        }
        if test.selectorUpdated2 != nil {
            test.d2.Annotations[SelectorUpdateAnnotation] = test.selectorUpdated2.Format(time.RFC3339)
//.........這裏部分代碼省略.........
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:101,代碼來源:deployment_util_test.go

示例8: afterOrZero

// afterOrZero checks if time t1 is after time t2; if one of them
// is zero, the zero time is seen as after non-zero time.
func afterOrZero(t1, t2 metav1.Time) bool {
    if t1.Time.IsZero() || t2.Time.IsZero() {
        return t1.Time.IsZero()
    }
    return t1.After(t2.Time)
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:8,代碼來源:controller_utils.go

示例9: SetDeletionTimestamp

func (u *Unstructured) SetDeletionTimestamp(timestamp *metav1.Time) {
    ts, _ := timestamp.MarshalQueryParameter()
    u.setNestedField(ts, "metadata", "deletionTimestamp")
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:4,代碼來源:unstructured.go

示例10: GetCreationTimestamp

func (u *Unstructured) GetCreationTimestamp() metav1.Time {
    var timestamp metav1.Time
    timestamp.UnmarshalQueryParameter(getNestedString(u.Object, "metadata", "creationTimestamp"))
    return timestamp
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:5,代碼來源:unstructured.go

示例11:

                scheduleTimes := make(map[string]metav1.Time, 0)
                runTimes := make(map[string]metav1.Time, 0)
                watchTimes := make(map[string]metav1.Time, 0)

                var mutex sync.Mutex
                checkPod := func(p *v1.Pod) {
                    mutex.Lock()
                    defer mutex.Unlock()
                    defer GinkgoRecover()

                    if p.Status.Phase == v1.PodRunning {
                        if _, found := watchTimes[p.Name]; !found {
                            watchTimes[p.Name] = metav1.Now()
                            createTimes[p.Name] = p.CreationTimestamp
                            nodeNames[p.Name] = p.Spec.NodeName
                            var startTime metav1.Time
                            for _, cs := range p.Status.ContainerStatuses {
                                if cs.State.Running != nil {
                                    if startTime.Before(cs.State.Running.StartedAt) {
                                        startTime = cs.State.Running.StartedAt
                                    }
                                }
                            }
                            if startTime != metav1.NewTime(time.Time{}) {
                                runTimes[p.Name] = startTime
                            } else {
                                framework.Failf("Pod %v is reported to be running, but none of its containers is", p.Name)
                            }
                        }
                    }
                }
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:31,代碼來源:density.go


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