本文整理匯總了Golang中k8s/io/kubernetes/pkg/api/unversioned.Time類的典型用法代碼示例。如果您正苦於以下問題:Golang Time類的具體用法?Golang Time怎麽用?Golang Time使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Time類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RecordConfigEvent
// RecordConfigEvent records an event for the deployment config referenced by the
// deployment.
func RecordConfigEvent(client kclient.EventNamespacer, deployment *kapi.ReplicationController, decoder runtime.Decoder, eventType, reason, msg string) {
t := unversioned.Time{Time: time.Now()}
var obj runtime.Object = deployment
if config, err := deployutil.DecodeDeploymentConfig(deployment, decoder); err == nil {
obj = config
} else {
glog.Errorf("Unable to decode deployment config from %s/%s: %v", deployment.Namespace, deployment.Name, err)
}
ref, err := kapi.GetReference(obj)
if err != nil {
glog.Errorf("Unable to get reference for %#v: %v", obj, err)
return
}
event := &kapi.Event{
ObjectMeta: kapi.ObjectMeta{
Name: fmt.Sprintf("%v.%x", ref.Name, t.UnixNano()),
Namespace: ref.Namespace,
},
InvolvedObject: *ref,
Reason: reason,
Message: msg,
Source: kapi.EventSource{
Component: deployutil.DeployerPodNameFor(deployment),
},
FirstTimestamp: t,
LastTimestamp: t,
Count: 1,
Type: eventType,
}
if _, err := client.Events(ref.Namespace).Create(event); err != nil {
glog.Errorf("Could not create event '%#v': %v", event, err)
}
}
示例2: Convert_string_slice_To_unversioned_Time
// Convert_string_slice_To_unversioned_Time allows converting a URL query parameter value
func Convert_string_slice_To_unversioned_Time(input *[]string, out *unversioned.Time, s conversion.Scope) error {
str := ""
if len(*input) > 0 {
str = (*input)[0]
}
return out.UnmarshalQueryParameter(str)
}
示例3: emitEvent
func (e *HookExecutor) emitEvent(deployment *kapi.ReplicationController, eventType, reason, msg string) {
t := unversioned.Time{Time: time.Now()}
var ref *kapi.ObjectReference
if config, err := deployutil.DecodeDeploymentConfig(deployment, e.decoder); err != nil {
glog.Errorf("Unable to decode deployment %s/%s to replication contoller: %v", deployment.Namespace, deployment.Name, err)
if ref, err = kapi.GetReference(deployment); err != nil {
glog.Errorf("Unable to get reference for %#v: %v", deployment, err)
return
}
} else {
if ref, err = kapi.GetReference(config); err != nil {
glog.Errorf("Unable to get reference for %#v: %v", config, err)
return
}
}
event := &kapi.Event{
ObjectMeta: kapi.ObjectMeta{
Name: fmt.Sprintf("%v.%x", ref.Name, t.UnixNano()),
Namespace: ref.Namespace,
},
InvolvedObject: *ref,
Reason: reason,
Message: msg,
FirstTimestamp: t,
LastTimestamp: t,
Count: 1,
Type: eventType,
}
if _, err := e.events.Create(event); err != nil {
glog.Errorf("Could not send event '%#v': %v", event, err)
}
}
示例4: GetDeletionTimestamp
func (u *Unstructured) GetDeletionTimestamp() *unversioned.Time {
var timestamp unversioned.Time
timestamp.UnmarshalQueryParameter(getNestedString(u.Object, "metadata", "deletionTimestamp"))
if timestamp.IsZero() {
return nil
}
return ×tamp
}
示例5: containerRestartedRecently
func containerRestartedRecently(status kapi.ContainerStatus, now unversioned.Time) bool {
if status.RestartCount == 0 {
return false
}
if status.LastTerminationState.Terminated != nil && now.Sub(status.LastTerminationState.Terminated.FinishedAt.Time) < RestartRecentDuration {
return true
}
return false
}
示例6: hasIngressBeenTouched
// hasIngressBeenTouched returns true if the route appears to have been touched since the last time
func (a *StatusAdmitter) hasIngressBeenTouched(route *routeapi.Route, lastTouch *unversioned.Time) bool {
glog.V(4).Infof("has last touch %v for %s/%s", lastTouch, route.Namespace, route.Name)
if lastTouch.IsZero() {
return false
}
old, ok := a.expected.Get(route.UID)
if !ok || old.(time.Time).Equal(lastTouch.Time) {
return false
}
return true
}
示例7: deepCopy_unversioned_Time
func deepCopy_unversioned_Time(in unversioned.Time, out *unversioned.Time, c *conversion.Cloner) error {
if newVal, err := c.DeepCopy(in.Time); err != nil {
return err
} else {
out.Time = newVal.(time.Time)
}
return nil
}
示例8: 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 := unversioned.Time{}
if lastSuccessfulBuild != nil {
passTime = buildTimestamp(lastSuccessfulBuild.Build)
}
failTime := unversioned.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
}
示例9: printImageStream
func printImageStream(stream *imageapi.ImageStream, w io.Writer, opts kctl.PrintOptions) error {
name := formatResourceName(opts.Kind, stream.Name, opts.WithKind)
tags := ""
const numOfTagsShown = 3
var latest unversioned.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 opts.WithNamespace {
if _, err := fmt.Fprintf(w, "%s\t", stream.Namespace); err != nil {
return err
}
}
repo := stream.Spec.DockerImageRepository
if len(repo) == 0 {
repo = stream.Status.DockerImageRepository
}
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s", name, repo, tags, latestTime); err != nil {
return err
}
if err := appendItemLabels(stream.Labels, w, opts.ColumnLabels, opts.ShowLabels); err != nil {
return err
}
return nil
}
示例10: makeEvent
func (recorder *recorderImpl) makeEvent(ref *api.ObjectReference, reason, message string) *api.Event {
t := unversioned.Time{recorder.clock.Now()}
namespace := ref.Namespace
if namespace == "" {
namespace = api.NamespaceDefault
}
return &api.Event{
ObjectMeta: api.ObjectMeta{
Name: fmt.Sprintf("%v.%x", ref.Name, t.UnixNano()),
Namespace: namespace,
},
InvolvedObject: *ref,
Reason: reason,
Message: message,
FirstTimestamp: t,
LastTimestamp: t,
Count: 1,
}
}
示例11: describeBuildPhase
func describeBuildPhase(build *buildapi.Build, t *unversioned.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("build #%d", 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)
}
}
示例12: makeEvent
func (f *FakeRecorder) makeEvent(ref *v1.ObjectReference, eventtype, reason, message string) *v1.Event {
fmt.Println("make event")
t := unversioned.Time{Time: f.clock.Now()}
namespace := ref.Namespace
if namespace == "" {
namespace = v1.NamespaceDefault
}
return &v1.Event{
ObjectMeta: v1.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,
}
}
示例13: hasIngressBeenTouched
// hasIngressBeenTouched returns true if the route appears to have been touched since the last time
func (a *StatusAdmitter) hasIngressBeenTouched(route *routeapi.Route, lastTouch *unversioned.Time) bool {
glog.V(4).Infof("has last touch %v for %s/%s", lastTouch, route.Namespace, route.Name)
if lastTouch.IsZero() {
return false
}
old, ok := a.expected.Get(route.UID)
if ok && old.(time.Time).Before(nowFn().Add(-a.contentionInterval)) {
// throw out cache entries from before the contention interval, in case this is no longer valid
// (e.g. the previous updater no longer exists due to scale down)
glog.V(4).Infof("expired cached last touch of %s", old.(time.Time))
a.expected.Remove(route.UID)
ok = false
}
if !ok || old.(time.Time).Equal(lastTouch.Time) {
glog.V(4).Infof("missing or equal cached last touch")
return false
}
glog.V(4).Infof("different cached last touch of %s", old.(time.Time))
return true
}
示例14: printImageStream
func printImageStream(stream *imageapi.ImageStream, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
tags := ""
const numOfTagsShown = 3
var latest unversioned.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
}
}
repo := stream.Spec.DockerImageRepository
if len(repo) == 0 {
repo = stream.Status.DockerImageRepository
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", stream.Name, repo, tags, latestTime)
return err
}
示例15: SetDeletionTimestamp
func (u *Unstructured) SetDeletionTimestamp(timestamp *unversioned.Time) {
ts, _ := timestamp.MarshalQueryParameter()
u.setNestedField(ts, "metadata", "deletionTimestamp")
}