blob: c9f7939de5d6c8ab3f7df56d19e941034c6c841d [file] [log] [blame]
giof8acc612025-04-26 08:20:55 +04001package status
2
3import (
4 "fmt"
5)
6
7type Status int
8
9const (
10 StatusNoStatus Status = iota
11 StatusNotFound
12 StatusPending
13 StatusProcessing
14 StatusSuccess
15 StatusFailure
16)
17
18func IsStatusTerminal(s Status) bool {
19 return s == StatusSuccess || s == StatusFailure
20}
21
22func StatusString(s Status) string {
23 switch s {
24 case StatusNoStatus:
25 return "no_status"
26 case StatusNotFound:
27 return "not_found"
28 case StatusPending:
29 return "pending"
30 case StatusProcessing:
31 return "processing"
32 case StatusSuccess:
33 return "success"
34 case StatusFailure:
35 return "failure"
36 default:
37 panic("MUST NOT REACH!")
38 }
39}
40
41type ResourceType int
42
43const (
44 ResourceHelmRelease ResourceType = iota
gioea6d9122025-05-22 17:57:18 +040045 ResourceIngress
giof8acc612025-04-26 08:20:55 +040046)
47
48type ResourceRef struct {
gioda708652025-04-30 14:57:38 +040049 Id string
giof8acc612025-04-26 08:20:55 +040050 Name string
51 Namespace string
52}
53
54type Resource struct {
55 ResourceRef
56 Type ResourceType
57}
58
59type Monitor interface {
60 Get(r Resource) (Status, error)
61}
62
63type ResourceMonitor interface {
64 Get(r ResourceRef) (Status, error)
65}
66
67type delegatingMonitor struct {
68 m map[ResourceType]ResourceMonitor
69}
70
71func NewDelegatingMonitor(kubeconfig string) (Monitor, error) {
72 helm, err := NewHelmReleaseMonitor(kubeconfig)
73 if err != nil {
74 return nil, err
75 }
gioea6d9122025-05-22 17:57:18 +040076 ingress, err := NewIngressMonitor(kubeconfig)
77 if err != nil {
78 return nil, err
79 }
giof8acc612025-04-26 08:20:55 +040080 return delegatingMonitor{
81 map[ResourceType]ResourceMonitor{
82 ResourceHelmRelease: helm,
gioea6d9122025-05-22 17:57:18 +040083 ResourceIngress: ingress,
giof8acc612025-04-26 08:20:55 +040084 },
85 }, nil
86}
87
88func (m delegatingMonitor) Get(r Resource) (Status, error) {
89 if rm, ok := m.m[r.Type]; !ok {
90 return StatusNoStatus, fmt.Errorf("unknown resource type: %d", r.Type)
91 } else {
92 return rm.Get(r.ResourceRef)
93 }
94}