This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
crd.go
103 lines (84 loc) · 2.07 KB
/
crd.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package crd
import (
"errors"
toolsetsv1beta2 "github.com/caos/orbos/internal/operator/boom/api/v1beta2"
"github.com/caos/orbos/internal/operator/boom/bundle"
bundleconfig "github.com/caos/orbos/internal/operator/boom/bundle/config"
"github.com/caos/orbos/internal/operator/boom/crd/config"
"github.com/caos/orbos/internal/operator/boom/metrics"
"github.com/caos/orbos/internal/operator/boom/name"
"github.com/caos/orbos/internal/utils/clientgo"
"github.com/caos/orbos/mntr"
)
const (
version name.Version = "v1beta2"
)
type Crd struct {
bundle *bundle.Bundle
monitor mntr.Monitor
status error
}
func (c *Crd) GetStatus() error {
return c.status
}
func (c *Crd) SetBackStatus() {
c.status = nil
}
func (c *Crd) CleanUp() {
if c.GetStatus() != nil {
return
}
c.status = c.bundle.CleanUp()
}
func GetVersion() name.Version {
return version
}
func New(conf *config.Config) *Crd {
crdMonitor := conf.Monitor.WithFields(map[string]interface{}{
"version": GetVersion(),
})
return &Crd{
monitor: crdMonitor,
status: nil,
}
}
func (c *Crd) SetBundle(conf *bundleconfig.Config) {
if c.GetStatus() != nil {
return
}
bundle := bundle.New(conf)
c.status = bundle.AddApplicationsByBundleName(conf.BundleName)
if c.status != nil {
return
}
c.bundle = bundle
}
func (c *Crd) GetBundle() *bundle.Bundle {
return c.bundle
}
func (c *Crd) Reconcile(currentResourceList []*clientgo.Resource, toolsetCRD *toolsetsv1beta2.Toolset) {
if c.GetStatus() != nil {
return
}
logFields := map[string]interface{}{
"CRD": toolsetCRD.Metadata.Name,
"action": "reconciling",
}
monitor := c.monitor.WithFields(logFields)
if toolsetCRD == nil {
c.status = errors.New("ToolsetCRD is nil")
monitor.Error(c.status)
return
}
if c.bundle == nil {
c.status = errors.New("No bundle for crd")
monitor.Error(c.status)
return
}
c.status = c.bundle.Reconcile(currentResourceList, toolsetCRD.Spec)
if c.status != nil {
metrics.FailureReconcilingBundle(c.bundle.GetPredefinedBundle())
return
}
metrics.SuccessfulReconcilingBundle(c.bundle.GetPredefinedBundle())
}