github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/application/applications/logcollection/logging/logging.go (about) 1 package logging 2 3 import ( 4 "github.com/caos/orbos/internal/operator/boom/api/latest" 5 "github.com/caos/orbos/pkg/kubernetes/k8s" 6 ) 7 8 type Storage struct { 9 StorageClassName string 10 AccessModes []string 11 Storage string 12 } 13 14 type Config struct { 15 Name string 16 Namespace string 17 ControlNamespace string 18 Replicas int 19 NodeSelector map[string]string 20 Tolerations k8s.Tolerations 21 Fluentd *latest.Fluentd 22 FluentbitPVC *Storage 23 } 24 25 type Requests struct { 26 Storage string `yaml:"storage,omitempty"` 27 } 28 type Resources struct { 29 Requests *Requests `yaml:"requests,omitempty"` 30 } 31 type PvcSpec struct { 32 AccessModes []string `yaml:"accessModes,omitempty"` 33 Resources *Resources `yaml:"resources,omitempty"` 34 StorageClassName string `yaml:"storageClassName,omitempty"` 35 } 36 type Pvc struct { 37 PvcSpec *PvcSpec `yaml:"spec,omitempty"` 38 } 39 type KubernetesStorage struct { 40 Pvc *Pvc `yaml:"pvc,omitempty"` 41 } 42 type Scaling struct { 43 Replicas int `yaml:"replicas"` 44 } 45 type Fluentd struct { 46 Metrics *Metrics `yaml:"metrics,omitempty"` 47 BufferStorageVolume *KubernetesStorage `yaml:"bufferStorageVolume,omitempty"` 48 LogLevel string `yaml:"logLevel,omitempty"` 49 DisablePvc bool `yaml:"disablePvc"` 50 Scaling *Scaling `yaml:"scaling,omitempty"` 51 NodeSelector map[string]string `yaml:"nodeSelector,omitempty"` 52 Tolerations k8s.Tolerations `yaml:"tolerations,omitempty"` 53 Resources *k8s.Resources `yaml:"resources,omitempty"` 54 } 55 56 type Metrics struct { 57 Port int `yaml:"port"` 58 } 59 type Image struct { 60 PullPolicy string `yaml:"pullPolicy"` 61 Repository string `yaml:"repository"` 62 Tag string `yaml:"tag"` 63 } 64 65 type FilterKubernetes struct { 66 KubeTagPrefix string `yaml:"Kube_Tag_Prefix"` 67 } 68 69 type Fluentbit struct { 70 Metrics *Metrics `yaml:"metrics,omitempty"` 71 FilterKubernetes *FilterKubernetes `yaml:"filterKubernetes,omitempty"` 72 Image *Image `yaml:"image,omitempty"` 73 BufferStorageVolume *KubernetesStorage `yaml:"bufferStorageVolume,omitempty"` 74 NodeSelector map[string]string `yaml:"nodeSelector,omitempty"` 75 Tolerations k8s.Tolerations `yaml:"tolerations,omitempty"` 76 Resources *k8s.Resources `yaml:"resources,omitempty"` 77 } 78 type Spec struct { 79 Fluentd *Fluentd `yaml:"fluentd"` 80 Fluentbit *Fluentbit `yaml:"fluentbit"` 81 WatchNamespaces []string `yaml:"watchNamespaces"` 82 ControlNamespace string `yaml:"controlNamespace"` 83 EnableRecreateWorkloadOnImmutableFieldChange bool `yaml:"enableRecreateWorkloadOnImmutableFieldChange"` 84 FlowConfigCheckDisabled bool `yaml:"flowConfigCheckDisabled"` 85 } 86 type Metadata struct { 87 Name string `yaml:"name"` 88 Namespace string `yaml:"namespace"` 89 } 90 type Logging struct { 91 APIVersion string `yaml:"apiVersion"` 92 Kind string `yaml:"kind"` 93 Metadata *Metadata `yaml:"metadata"` 94 Spec *Spec `yaml:"spec"` 95 } 96 97 func New(spec *latest.LogCollection) *Logging { 98 values := &Logging{ 99 APIVersion: "logging.banzaicloud.io/v1beta1", 100 Kind: "Logging", 101 Metadata: &Metadata{ 102 Name: "logging", 103 Namespace: "caos-system", 104 }, 105 Spec: &Spec{ 106 FlowConfigCheckDisabled: true, 107 EnableRecreateWorkloadOnImmutableFieldChange: true, 108 ControlNamespace: "caos-system", 109 Fluentd: &Fluentd{ 110 Metrics: &Metrics{ 111 Port: 8080, 112 }, 113 DisablePvc: true, 114 Tolerations: k8s.Tolerations{}, 115 NodeSelector: map[string]string{}, 116 Scaling: &Scaling{ 117 Replicas: 1, 118 }, 119 }, 120 Fluentbit: &Fluentbit{ 121 Metrics: &Metrics{ 122 Port: 8080, 123 }, 124 Image: &Image{ 125 Repository: "fluent/fluent-bit", 126 Tag: "1.3.6", 127 PullPolicy: "IfNotPresent", 128 }, 129 Tolerations: k8s.Tolerations{}, 130 NodeSelector: map[string]string{}, 131 }, 132 }, 133 } 134 135 if spec == nil { 136 return values 137 } 138 139 if spec.WatchNamespaces != nil { 140 values.Spec.WatchNamespaces = spec.WatchNamespaces 141 } 142 143 if spec.Fluentd != nil { 144 if spec.Fluentd.Replicas != nil { 145 values.Spec.Fluentd.Scaling.Replicas = *spec.Fluentd.Replicas 146 } 147 if spec.Fluentd.NodeSelector != nil { 148 for k, v := range spec.Fluentd.NodeSelector { 149 values.Spec.Fluentd.NodeSelector[k] = v 150 } 151 } 152 153 if spec.Fluentd.Tolerations != nil { 154 for _, tol := range spec.Fluentd.Tolerations { 155 values.Spec.Fluentd.Tolerations = append(spec.Fluentd.Tolerations, tol) 156 } 157 } 158 159 if spec.Fluentd.Resources != nil { 160 values.Spec.Fluentd.Resources = spec.Fluentd.Resources 161 } 162 163 if spec.Fluentd.PVC != nil { 164 values.Spec.Fluentd.DisablePvc = false 165 values.Spec.Fluentd.BufferStorageVolume = &KubernetesStorage{ 166 Pvc: &Pvc{ 167 PvcSpec: &PvcSpec{ 168 StorageClassName: spec.Fluentd.PVC.StorageClass, 169 Resources: &Resources{ 170 Requests: &Requests{ 171 Storage: spec.Fluentd.PVC.Size, 172 }, 173 }, 174 AccessModes: []string{"ReadWriteOnce"}, 175 }, 176 }, 177 } 178 if spec.Fluentd.PVC.AccessModes != nil { 179 values.Spec.Fluentd.BufferStorageVolume.Pvc.PvcSpec.AccessModes = spec.Fluentd.PVC.AccessModes 180 } 181 } 182 } 183 184 if spec.Fluentbit == nil { 185 return values 186 } 187 188 if spec.Fluentbit.Resources != nil { 189 values.Spec.Fluentbit.Resources = spec.Fluentbit.Resources 190 } 191 192 if spec.Fluentbit.NodeSelector != nil { 193 for k, v := range spec.Fluentbit.NodeSelector { 194 values.Spec.Fluentbit.NodeSelector[k] = v 195 } 196 } 197 198 if spec.Fluentbit.Tolerations != nil { 199 for _, tol := range spec.Fluentbit.Tolerations { 200 values.Spec.Fluentbit.Tolerations = append(spec.Fluentbit.Tolerations, tol) 201 } 202 } 203 204 return values 205 }