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
161 lines (150 loc) · 4.64 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
package logging
import corev1 "k8s.io/api/core/v1"
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 []corev1.Toleration
FluentdPVC *Storage
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 []corev1.Toleration `yaml:"tolerations,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"`
Tolerations []corev1.Toleration `yaml:"tolerations,omitempty"`
}
type Spec struct {
Fluentd *Fluentd `yaml:"fluentd"`
Fluentbit *Fluentbit `yaml:"fluentbit"`
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(conf *Config) *Logging {
values := &Logging{
APIVersion: "logging.banzaicloud.io/v1beta1",
Kind: "Logging",
Metadata: &Metadata{
Name: conf.Name,
Namespace: conf.Namespace,
},
Spec: &Spec{
FlowConfigCheckDisabled: true,
EnableRecreateWorkloadOnImmutableFieldChange: true,
ControlNamespace: conf.ControlNamespace,
Fluentd: &Fluentd{
Metrics: &Metrics{
Port: 8080,
},
Tolerations: []corev1.Toleration{},
DisablePvc: true,
NodeSelector: map[string]string{},
},
Fluentbit: &Fluentbit{
Metrics: &Metrics{
Port: 8080,
},
Image: &Image{
Repository: "fluent/fluent-bit",
Tag: "1.3.6",
PullPolicy: "IfNotPresent",
},
Tolerations: []corev1.Toleration{},
},
},
}
if conf.FluentdPVC != nil {
values.Spec.Fluentd.BufferStorageVolume = &KubernetesStorage{
Pvc: &Pvc{
PvcSpec: &PvcSpec{
StorageClassName: conf.FluentdPVC.StorageClassName,
Resources: &Resources{
Requests: &Requests{
Storage: conf.FluentdPVC.Storage,
},
},
},
},
}
values.Spec.Fluentd.DisablePvc = false
if conf.FluentdPVC.AccessModes != nil {
values.Spec.Fluentd.BufferStorageVolume.Pvc.PvcSpec.AccessModes = conf.FluentdPVC.AccessModes
} else {
values.Spec.Fluentd.BufferStorageVolume.Pvc.PvcSpec.AccessModes = []string{"ReadWriteOnce"}
}
}
if conf.NodeSelector != nil {
for k, v := range conf.NodeSelector {
values.Spec.Fluentd.NodeSelector[k] = v
}
}
if conf.Tolerations != nil {
values.Spec.Fluentbit.Tolerations = append(values.Spec.Fluentbit.Tolerations, conf.Tolerations...)
values.Spec.Fluentd.Tolerations = append(values.Spec.Fluentd.Tolerations, conf.Tolerations...)
}
if conf.Replicas != 0 {
values.Spec.Fluentd.Scaling = &Scaling{
Replicas: conf.Replicas,
}
}
return values
}