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