本文整理汇总了Golang中k8s/io/kubernetes/pkg/util.Time类的典型用法代码示例。如果您正苦于以下问题:Golang Time类的具体用法?Golang Time怎么用?Golang Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Time类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: printImageStream
func printImageStream(stream *imageapi.ImageStream, w io.Writer, withNamespace, wide bool, columnLabels []string) error {
tags := ""
set := util.NewStringSet()
var latest util.Time
for tag, list := range stream.Status.Tags {
set.Insert(tag)
if len(list.Items) > 0 {
if list.Items[0].Created.After(latest.Time) {
latest = list.Items[0].Created
}
}
}
latestTime := ""
if !latest.IsZero() {
latestTime = fmt.Sprintf("%s ago", formatRelativeTime(latest.Time))
}
tags = strings.Join(set.List(), ",")
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", stream.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", stream.Name, stream.Status.DockerImageRepository, tags, latestTime)
return err
}
示例2: printImageStream
func printImageStream(stream *imageapi.ImageStream, w io.Writer, withNamespace, wide bool, columnLabels []string) error {
tags := ""
const numOfTagsShown = 3
var latest util.Time
for _, list := range stream.Status.Tags {
if len(list.Items) > 0 {
if list.Items[0].Created.After(latest.Time) {
latest = list.Items[0].Created
}
}
}
latestTime := ""
if !latest.IsZero() {
latestTime = fmt.Sprintf("%s ago", formatRelativeTime(latest.Time))
}
list := imageapi.SortStatusTags(stream.Status.Tags)
more := false
if len(list) > numOfTagsShown {
list = list[:numOfTagsShown]
more = true
}
tags = strings.Join(list, ",")
if more {
tags = fmt.Sprintf("%s + %d more...", tags, len(stream.Status.Tags)-numOfTagsShown)
}
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", stream.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", stream.Name, stream.Status.DockerImageRepository, tags, latestTime)
return err
}
示例3: deepCopy_util_Time
func deepCopy_util_Time(in util.Time, out *util.Time, c *conversion.Cloner) error {
if newVal, err := c.DeepCopy(in.Time); err != nil {
return err
} else {
out.Time = newVal.(time.Time)
}
return nil
}
示例4: describeAdditionalBuildDetail
func describeAdditionalBuildDetail(build *buildgraph.BuildConfigNode, lastSuccessfulBuild *buildgraph.BuildNode, lastUnsuccessfulBuild *buildgraph.BuildNode, activeBuilds []*buildgraph.BuildNode, pushTargetResolved bool, includeSuccess bool) []string {
if build == nil {
return nil
}
out := []string{}
passTime := util.Time{}
if lastSuccessfulBuild != nil {
passTime = buildTimestamp(lastSuccessfulBuild.Build)
}
failTime := util.Time{}
if lastUnsuccessfulBuild != nil {
failTime = buildTimestamp(lastUnsuccessfulBuild.Build)
}
lastTime := failTime
if passTime.After(failTime.Time) {
lastTime = passTime
}
// display the last successful build if specifically requested or we're going to display an active build for context
if lastSuccessfulBuild != nil && (includeSuccess || len(activeBuilds) > 0) {
out = append(out, describeBuildPhase(lastSuccessfulBuild.Build, &passTime, build.BuildConfig.Name, pushTargetResolved))
}
if passTime.Before(failTime) {
out = append(out, describeBuildPhase(lastUnsuccessfulBuild.Build, &failTime, build.BuildConfig.Name, pushTargetResolved))
}
if len(activeBuilds) > 0 {
activeOut := []string{}
for i := range activeBuilds {
activeOut = append(activeOut, describeBuildPhase(activeBuilds[i].Build, nil, build.BuildConfig.Name, pushTargetResolved))
}
if buildTimestamp(activeBuilds[0].Build).Before(lastTime) {
out = append(out, activeOut...)
} else {
out = append(activeOut, out...)
}
}
if len(out) == 0 && lastSuccessfulBuild == nil {
out = append(out, "not built yet")
}
return out
}
示例5: describeBuildPhase
func describeBuildPhase(build *buildapi.Build, t *util.Time, parentName string, pushTargetResolved bool) string {
imageStreamFailure := ""
// if we're using an image stream and that image stream is the internal registry and that registry doesn't exist
if (build.Spec.Output.To != nil) && !pushTargetResolved {
imageStreamFailure = " (can't push to image)"
}
if t == nil {
ts := buildTimestamp(build)
t = &ts
}
var time string
if t.IsZero() {
time = "<unknown>"
} else {
time = strings.ToLower(formatRelativeTime(t.Time))
}
buildIdentification := fmt.Sprintf("build/%s", build.Name)
prefix := parentName + "-"
if strings.HasPrefix(build.Name, prefix) {
suffix := build.Name[len(prefix):]
if buildNumber, err := strconv.Atoi(suffix); err == nil {
buildIdentification = fmt.Sprintf("#%d build", buildNumber)
}
}
revision := describeSourceRevision(build.Spec.Revision)
if len(revision) != 0 {
revision = fmt.Sprintf(" - %s", revision)
}
switch build.Status.Phase {
case buildapi.BuildPhaseComplete:
return fmt.Sprintf("%s succeeded %s ago%s%s", buildIdentification, time, revision, imageStreamFailure)
case buildapi.BuildPhaseError:
return fmt.Sprintf("%s stopped with an error %s ago%s%s", buildIdentification, time, revision, imageStreamFailure)
case buildapi.BuildPhaseFailed:
return fmt.Sprintf("%s failed %s ago%s%s", buildIdentification, time, revision, imageStreamFailure)
default:
status := strings.ToLower(string(build.Status.Phase))
return fmt.Sprintf("%s %s for %s%s%s", buildIdentification, status, time, revision, imageStreamFailure)
}
}
示例6:
scheduleTimes := make(map[string]util.Time, 0)
runTimes := make(map[string]util.Time, 0)
watchTimes := make(map[string]util.Time, 0)
var mutex sync.Mutex
checkPod := func(p *api.Pod) {
mutex.Lock()
defer mutex.Unlock()
defer GinkgoRecover()
if p.Status.Phase == api.PodRunning {
if _, found := watchTimes[p.Name]; !found {
watchTimes[p.Name] = util.Now()
createTimes[p.Name] = p.CreationTimestamp
nodes[p.Name] = p.Spec.NodeName
var startTime util.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 != util.NewTime(time.Time{}) {
runTimes[p.Name] = startTime
} else {
Failf("Pod %v is reported to be running, but none of its containers is", p.Name)
}
}
}
}
示例7: translateTimestamp
// translateTimestamp returns the elapsed time since timestamp in
// human-readable approximation.
func translateTimestamp(timestamp util.Time) string {
if timestamp.IsZero() {
return "<unknown>"
}
return shortHumanDuration(time.Now().Sub(timestamp.Time))
}
示例8: TestHandleRoute
// TestHandleRoute test route watch events
func TestHandleRoute(t *testing.T) {
router := newTestRouter(make(map[string]ServiceUnit))
plugin := newDefaultTemplatePlugin(router)
original := util.Time{time.Now()}
//add
route := &routeapi.Route{
ObjectMeta: kapi.ObjectMeta{
CreationTimestamp: original,
Namespace: "foo",
Name: "test",
},
Host: "www.example.com",
ServiceName: "TestService",
}
serviceUnitKey := fmt.Sprintf("%s/%s", route.Namespace, route.ServiceName)
plugin.HandleRoute(watch.Added, route)
if !router.Committed {
t.Errorf("Expected router to be committed after HandleRoute call")
}
actualSU, ok := router.FindServiceUnit(serviceUnitKey)
if !ok {
t.Errorf("TestHandleRoute was unable to find the service unit %s after HandleRoute was called", route.ServiceName)
} else {
serviceAliasCfg, ok := actualSU.ServiceAliasConfigs[router.routeKey(route)]
if !ok {
t.Errorf("TestHandleRoute expected route key %s", router.routeKey(route))
} else {
if serviceAliasCfg.Host != route.Host || serviceAliasCfg.Path != route.Path {
t.Errorf("Expected route did not match service alias config %v : %v", route, serviceAliasCfg)
}
}
}
// attempt to add a second route with a newer time, verify it is ignored
duplicateRoute := &routeapi.Route{
ObjectMeta: kapi.ObjectMeta{
CreationTimestamp: util.Time{Time: original.Add(time.Hour)},
Namespace: "foo",
Name: "dupe",
},
Host: "www.example.com",
ServiceName: "TestService2",
}
if err := plugin.HandleRoute(watch.Added, duplicateRoute); err == nil {
t.Fatal("unexpected non-error")
}
if _, ok := router.FindServiceUnit("foo/TestService2"); ok {
t.Fatalf("unexpected second unit: %#v", router)
}
if r, ok := plugin.hostToRoute["www.example.com"]; !ok || r[0].Name != "test" {
t.Fatalf("unexpected claimed routes: %#v", r)
}
// attempt to remove the second route that is not being used, verify it is ignored
if err := plugin.HandleRoute(watch.Deleted, duplicateRoute); err == nil {
t.Fatal("unexpected non-error")
}
if _, ok := router.FindServiceUnit("foo/TestService2"); ok {
t.Fatalf("unexpected second unit: %#v", router)
}
if _, ok := router.FindServiceUnit("foo/TestService"); !ok {
t.Fatalf("unexpected first unit: %#v", router)
}
if r, ok := plugin.hostToRoute["www.example.com"]; !ok || r[0].Name != "test" {
t.Fatalf("unexpected claimed routes: %#v", r)
}
// add a second route with an older time, verify it takes effect
duplicateRoute.CreationTimestamp = util.Time{Time: original.Add(-time.Hour)}
if err := plugin.HandleRoute(watch.Added, duplicateRoute); err != nil {
t.Fatal("unexpected error")
}
otherSU, ok := router.FindServiceUnit("foo/TestService2")
if !ok {
t.Fatalf("missing second unit: %#v", router)
}
if len(actualSU.ServiceAliasConfigs) != 0 || len(otherSU.ServiceAliasConfigs) != 1 {
t.Errorf("incorrect router state: %#v", router)
}
if _, ok := actualSU.ServiceAliasConfigs[router.routeKey(route)]; ok {
t.Errorf("unexpected service alias config %s", router.routeKey(route))
}
//mod
route.Host = "www.example2.com"
if err := plugin.HandleRoute(watch.Modified, route); err != nil {
t.Fatal("unexpected error")
}
if !router.Committed {
t.Errorf("Expected router to be committed after HandleRoute call")
}
actualSU, ok = router.FindServiceUnit(serviceUnitKey)
//.........这里部分代码省略.........