blob: ebec72f931a50f52d43c732b312398e26fa8d71d [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
45)
46
47type ResourceRef struct {
48 Name string
49 Namespace string
50}
51
52type Resource struct {
53 ResourceRef
54 Type ResourceType
55}
56
57type Monitor interface {
58 Get(r Resource) (Status, error)
59}
60
61type ResourceMonitor interface {
62 Get(r ResourceRef) (Status, error)
63}
64
65type delegatingMonitor struct {
66 m map[ResourceType]ResourceMonitor
67}
68
69func NewDelegatingMonitor(kubeconfig string) (Monitor, error) {
70 helm, err := NewHelmReleaseMonitor(kubeconfig)
71 if err != nil {
72 return nil, err
73 }
74 return delegatingMonitor{
75 map[ResourceType]ResourceMonitor{
76 ResourceHelmRelease: helm,
77 },
78 }, nil
79}
80
81func (m delegatingMonitor) Get(r Resource) (Status, error) {
82 if rm, ok := m.m[r.Type]; !ok {
83 return StatusNoStatus, fmt.Errorf("unknown resource type: %d", r.Type)
84 } else {
85 return rm.Get(r.ResourceRef)
86 }
87}