api: Hide UpdateStatus when it is not present
When UpdateStatus was not present, the empty values of the timestamps
would be present:
"UpdateStatus": {
"StartedAt": "0001-01-01T00:00:00Z",
"CompletedAt": "0001-01-01T00:00:00Z"
}
To fix this, make the timestamps pointers, so they can be set to nil
when they should not be shown.
Also make UpdateStatus itself a pointer, so an empty object does not
show up when there is no UpdateStatus.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Upstream-commit: 8a379d7bce
Component: cli
This commit is contained in:
@ -28,7 +28,9 @@ Service Mode:
|
||||
{{- if .HasUpdateStatus }}
|
||||
UpdateStatus:
|
||||
State: {{ .UpdateStatusState }}
|
||||
{{- if .HasUpdateStatusStarted }}
|
||||
Started: {{ .UpdateStatusStarted }}
|
||||
{{- end }}
|
||||
{{- if .UpdateIsCompleted }}
|
||||
Completed: {{ .UpdateStatusCompleted }}
|
||||
{{- end }}
|
||||
@ -172,23 +174,27 @@ func (ctx *serviceInspectContext) ModeReplicatedReplicas() *uint64 {
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) HasUpdateStatus() bool {
|
||||
return ctx.Service.UpdateStatus.State != ""
|
||||
return ctx.Service.UpdateStatus != nil && ctx.Service.UpdateStatus.State != ""
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) UpdateStatusState() swarm.UpdateState {
|
||||
return ctx.Service.UpdateStatus.State
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) HasUpdateStatusStarted() bool {
|
||||
return ctx.Service.UpdateStatus.StartedAt != nil
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) UpdateStatusStarted() string {
|
||||
return units.HumanDuration(time.Since(ctx.Service.UpdateStatus.StartedAt))
|
||||
return units.HumanDuration(time.Since(*ctx.Service.UpdateStatus.StartedAt))
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) UpdateIsCompleted() bool {
|
||||
return ctx.Service.UpdateStatus.State == swarm.UpdateStateCompleted
|
||||
return ctx.Service.UpdateStatus.State == swarm.UpdateStateCompleted && ctx.Service.UpdateStatus.CompletedAt != nil
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) UpdateStatusCompleted() string {
|
||||
return units.HumanDuration(time.Since(ctx.Service.UpdateStatus.CompletedAt))
|
||||
return units.HumanDuration(time.Since(*ctx.Service.UpdateStatus.CompletedAt))
|
||||
}
|
||||
|
||||
func (ctx *serviceInspectContext) UpdateStatusMessage() string {
|
||||
|
||||
@ -74,9 +74,9 @@ func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time)
|
||||
},
|
||||
},
|
||||
},
|
||||
UpdateStatus: swarm.UpdateStatus{
|
||||
StartedAt: now,
|
||||
CompletedAt: now,
|
||||
UpdateStatus: &swarm.UpdateStatus{
|
||||
StartedAt: &now,
|
||||
CompletedAt: &now,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user