forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.go
52 lines (43 loc) · 1.29 KB
/
application.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2023 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package status
// AppContext holds the data necessary to derive a status
// value for an application.
type AppContext struct {
IsCaas bool
AppStatus StatusInfo
UnitCtx []UnitContext
// These are only set for CAAS models.
OperatorStatus StatusInfo
}
// UnitContext holds the data necessary to derive a status
// // value for a unit.
type UnitContext struct {
WorkloadStatus StatusInfo
// These are only set for CAAS models.
ContainerStatus StatusInfo
}
// DisplayApplicationStatus returns the application status we show to the user.
// For CAAS models, this is a synthetic status based on
// the application status and the operator status.
func DisplayApplicationStatus(ctx AppContext) StatusInfo {
info := ctx.AppStatus
if info.Status == Unset {
unitStatus := make([]StatusInfo, len(ctx.UnitCtx))
for i, u := range ctx.UnitCtx {
if ctx.IsCaas {
unitStatus[i] = UnitDisplayStatus(u.WorkloadStatus, u.ContainerStatus)
} else {
unitStatus[i] = u.WorkloadStatus
}
}
info = DeriveStatus(unitStatus)
}
if info.Since == nil {
info.Since = ctx.AppStatus.Since
}
if ctx.OperatorStatus.Status == "" {
return info
}
return ApplicationDisplayStatus(info, ctx.OperatorStatus)
}