carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import "sort"
4
5// DeploymentVersion is one version reported by an app's owned routes.
6type DeploymentVersion struct {
7 Version string
8 Count int
9}
10
11// DeploymentStatus describes observed adoption independently of channel
12// pointers. A pointer says what a route should adopt; Route.Version says what
13// that address actually reports serving.
14type DeploymentStatus struct {
15 RouteCount int
16 ReportableCount int
17 ReportedCount int
18 UnknownCount int
19 Versions []DeploymentVersion
20}
21
22func (d DeploymentStatus) HasRoutes() bool { return d.RouteCount > 0 }
23
24func (d DeploymentStatus) HasReportable() bool { return d.ReportableCount > 0 }
25
26func (d DeploymentStatus) HasReportedVersion() bool { return d.ReportedCount > 0 }
27
28func (d DeploymentStatus) Mixed() bool { return len(d.Versions) > 1 }
29
30// UniformVersion is non-empty only when every reported route agrees. Unknown
31// routes do not manufacture disagreement: callers use UnknownCount to expose
32// that the observation is partial.
33func (d DeploymentStatus) UniformVersion() string {
34 if len(d.Versions) == 1 {
35 return d.Versions[0].Version
36 }
37 return ""
38}
39
40// observedDeployment folds only routes owned by the viewed account. Assemble
41// groups routes by app name across accounts, so this is a tenant boundary.
42func observedDeployment(routes []RouteView, acct string) DeploymentStatus {
43 counts := make(map[string]int)
44 var d DeploymentStatus
45 for _, rt := range routes {
46 if rt.Account != acct || rt.Platform {
47 continue
48 }
49 d.RouteCount++
50 if rt.Kind != "" && rt.Kind != "instance" {
51 continue
52 }
53 d.ReportableCount++
54 if rt.Version == "" {
55 d.UnknownCount++
56 continue
57 }
58 d.ReportedCount++
59 counts[rt.Version]++
60 }
61 versions := make([]string, 0, len(counts))
62 for version := range counts {
63 versions = append(versions, version)
64 }
65 sort.Strings(versions)
66 for _, version := range versions {
67 d.Versions = append(d.Versions, DeploymentVersion{Version: version, Count: counts[version]})
68 }
69 return d
70}
71