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
/
logging.go
205 lines (186 loc) · 5.74 KB
/
logging.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package logging
import (
"github.com/caos/orbos/internal/operator/boom/api/latest"
"github.com/caos/orbos/internal/operator/boom/api/latest/k8s"
)
type Storage struct {
StorageClassName string
AccessModes []string
Storage string
}
type Config struct {
Name string
Namespace string
ControlNamespace string
Replicas int
NodeSelector map[string]string
Tolerations k8s.Tolerations
Fluentd *latest.Fluentd
FluentbitPVC *Storage
}
type Requests struct {
Storage string `yaml:"storage,omitempty"`
}
type Resources struct {
Requests *Requests `yaml:"requests,omitempty"`
}
type PvcSpec struct {
AccessModes []string `yaml:"accessModes,omitempty"`
Resources *Resources `yaml:"resources,omitempty"`
StorageClassName string `yaml:"storageClassName,omitempty"`
}
type Pvc struct {
PvcSpec *PvcSpec `yaml:"spec,omitempty"`
}
type KubernetesStorage struct {
Pvc *Pvc `yaml:"pvc,omitempty"`
}
type Scaling struct {
Replicas int `yaml:"replicas"`
}
type Fluentd struct {
Metrics *Metrics `yaml:"metrics,omitempty"`
BufferStorageVolume *KubernetesStorage `yaml:"bufferStorageVolume,omitempty"`
LogLevel string `yaml:"logLevel,omitempty"`
DisablePvc bool `yaml:"disablePvc"`
Scaling *Scaling `yaml:"scaling,omitempty"`
NodeSelector map[string]string `yaml:"nodeSelector,omitempty"`
Tolerations k8s.Tolerations `yaml:"tolerations,omitempty"`
Resources *k8s.Resources `yaml:"resources,omitempty"`
}
type Metrics struct {
Port int `yaml:"port"`
}
type Image struct {
PullPolicy string `yaml:"pullPolicy"`
Repository string `yaml:"repository"`
Tag string `yaml:"tag"`
}
type FilterKubernetes struct {
KubeTagPrefix string `yaml:"Kube_Tag_Prefix"`
}
type Fluentbit struct {
Metrics *Metrics `yaml:"metrics,omitempty"`
FilterKubernetes *FilterKubernetes `yaml:"filterKubernetes,omitempty"`
Image *Image `yaml:"image,omitempty"`
BufferStorageVolume *KubernetesStorage `yaml:"bufferStorageVolume,omitempty"`
NodeSelector map[string]string `yaml:"nodeSelector,omitempty"`
Tolerations k8s.Tolerations `yaml:"tolerations,omitempty"`
Resources *k8s.Resources `yaml:"resources,omitempty"`
}
type Spec struct {
Fluentd *Fluentd `yaml:"fluentd"`
Fluentbit *Fluentbit `yaml:"fluentbit"`
WatchNamespaces []string `yaml:"watchNamespaces"`
ControlNamespace string `yaml:"controlNamespace"`
EnableRecreateWorkloadOnImmutableFieldChange bool `yaml:"enableRecreateWorkloadOnImmutableFieldChange"`
FlowConfigCheckDisabled bool `yaml:"flowConfigCheckDisabled"`
}
type Metadata struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace"`
}
type Logging struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata *Metadata `yaml:"metadata"`
Spec *Spec `yaml:"spec"`
}
func New(spec *latest.LogCollection) *Logging {
values := &Logging{
APIVersion: "logging.banzaicloud.io/v1beta1",
Kind: "Logging",
Metadata: &Metadata{
Name: "logging",
Namespace: "caos-system",
},
Spec: &Spec{
FlowConfigCheckDisabled: true,
EnableRecreateWorkloadOnImmutableFieldChange: true,
ControlNamespace: "caos-system",
Fluentd: &Fluentd{
Metrics: &Metrics{
Port: 8080,
},
DisablePvc: true,
Tolerations: k8s.Tolerations{},
NodeSelector: map[string]string{},
Scaling: &Scaling{
Replicas: 1,
},
},
Fluentbit: &Fluentbit{
Metrics: &Metrics{
Port: 8080,
},
Image: &Image{
Repository: "fluent/fluent-bit",
Tag: "1.3.6",
PullPolicy: "IfNotPresent",
},
Tolerations: k8s.Tolerations{},
NodeSelector: map[string]string{},
},
},
}
if spec == nil {
return values
}
if spec.WatchNamespaces != nil {
values.Spec.WatchNamespaces = spec.WatchNamespaces
}
if spec.Fluentd != nil {
if spec.Fluentd.Replicas != nil {
values.Spec.Fluentd.Scaling.Replicas = *spec.Fluentd.Replicas
}
if spec.Fluentd.NodeSelector != nil {
for k, v := range spec.Fluentd.NodeSelector {
values.Spec.Fluentd.NodeSelector[k] = v
}
}
if spec.Fluentd.Tolerations != nil {
for _, tol := range spec.Fluentd.Tolerations {
values.Spec.Fluentd.Tolerations = append(spec.Fluentd.Tolerations, tol)
}
}
if spec.Fluentd.Resources != nil {
values.Spec.Fluentd.Resources = spec.Fluentd.Resources
}
if spec.Fluentd.PVC != nil {
values.Spec.Fluentd.DisablePvc = false
values.Spec.Fluentd.BufferStorageVolume = &KubernetesStorage{
Pvc: &Pvc{
PvcSpec: &PvcSpec{
StorageClassName: spec.Fluentd.PVC.StorageClass,
Resources: &Resources{
Requests: &Requests{
Storage: spec.Fluentd.PVC.Size,
},
},
AccessModes: []string{"ReadWriteOnce"},
},
},
}
if spec.Fluentd.PVC.AccessModes != nil {
values.Spec.Fluentd.BufferStorageVolume.Pvc.PvcSpec.AccessModes = spec.Fluentd.PVC.AccessModes
}
}
}
if spec.Fluentbit == nil {
return values
}
if spec.Fluentbit.Resources != nil {
values.Spec.Fluentbit.Resources = spec.Fluentbit.Resources
}
if spec.Fluentbit.NodeSelector != nil {
for k, v := range spec.Fluentbit.NodeSelector {
values.Spec.Fluentbit.NodeSelector[k] = v
}
}
if spec.Fluentbit.Tolerations != nil {
for _, tol := range spec.Fluentbit.Tolerations {
values.Spec.Fluentbit.Tolerations = append(spec.Fluentbit.Tolerations, tol)
}
}
return values
}