github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/application/applications/logcollection/logging/output.go (about) 1 package logging 2 3 type ConfigOutput struct { 4 Name string 5 Namespace string 6 URL string 7 ClusterOutput bool 8 RemoveKeys []string 9 Labels map[string]string 10 ExtraLabels map[string]string 11 ExtractKubernetesLabels bool 12 ConfigureKubernetesLabels bool 13 EnabledNamespaces []string 14 Username *SecretKeyRef 15 Password *SecretKeyRef 16 } 17 18 type Buffer struct { 19 Timekey string `yaml:"timekey"` 20 TimekeyWait string `yaml:"timekey_wait"` 21 TimekeyUseUtc bool `yaml:"timekey_use_utc"` 22 } 23 24 type Loki struct { 25 URL string `yaml:"url"` 26 ConfigureKubernetesLabels bool `yaml:"configure_kubernetes_labels,omitempty"` 27 ExtractKubernetesLabels bool `yaml:"extract_kubernetes_labels,omitempty"` 28 ExtraLabels map[string]string `yaml:"extra_labels,omitempty"` 29 Labels map[string]string `yaml:"labels,omitempty"` 30 RemoveKeys []string `yaml:"remove_keys,omitempty"` 31 Username *Value `yaml:"username,omitempty"` 32 Password *Value `yaml:"password,omitempty"` 33 Buffer *Buffer `yaml:"buffer"` 34 } 35 36 type Value struct { 37 ValueFrom *ValueFrom `yaml:"valueFrom,omitempty"` 38 } 39 40 type ValueFrom struct { 41 SecretKeyRef *SecretKeyRef `yaml:"secretKeyRef,omitempty"` 42 } 43 44 type SecretKeyRef struct { 45 Key string `yaml:"key,omitempty"` 46 Name string `yaml:"name,omitempty"` 47 } 48 49 type OutputSpec struct { 50 Loki *Loki `yaml:"loki"` 51 EnabledNamespaces []string `yaml:"enabledNamespaces,omitempty"` 52 } 53 54 type Output struct { 55 APIVersion string `yaml:"apiVersion"` 56 Kind string `yaml:"kind"` 57 Metadata *Metadata `yaml:"metadata"` 58 Spec *OutputSpec `yaml:"spec"` 59 } 60 61 func NewOutput(clusterOutput bool, conf *ConfigOutput) *Output { 62 kind := "Output" 63 meta := &Metadata{ 64 Name: conf.Name, 65 Namespace: conf.Namespace, 66 } 67 if clusterOutput { 68 kind = "ClusterOutput" 69 meta.Namespace = "" 70 } 71 72 ret := &Output{ 73 APIVersion: "logging.banzaicloud.io/v1beta1", 74 Kind: kind, 75 Metadata: meta, 76 Spec: &OutputSpec{ 77 Loki: &Loki{ 78 URL: conf.URL, 79 ExtractKubernetesLabels: conf.ExtractKubernetesLabels, 80 ConfigureKubernetesLabels: conf.ConfigureKubernetesLabels, 81 Buffer: &Buffer{ 82 Timekey: "1m", 83 TimekeyWait: "30s", 84 TimekeyUseUtc: true, 85 }, 86 }, 87 }, 88 } 89 90 if conf.EnabledNamespaces != nil { 91 ret.Spec.EnabledNamespaces = conf.EnabledNamespaces 92 } 93 if conf.Username != nil { 94 ret.Spec.Loki.Username = &Value{ 95 ValueFrom: &ValueFrom{ 96 SecretKeyRef: &SecretKeyRef{ 97 Key: conf.Username.Key, 98 Name: conf.Username.Name, 99 }, 100 }, 101 } 102 } 103 if conf.Password != nil { 104 ret.Spec.Loki.Password = &Value{ 105 ValueFrom: &ValueFrom{ 106 SecretKeyRef: &SecretKeyRef{ 107 Key: conf.Password.Key, 108 Name: conf.Password.Name, 109 }, 110 }, 111 } 112 } 113 if conf.ExtraLabels != nil { 114 ret.Spec.Loki.ExtraLabels = conf.ExtraLabels 115 } 116 117 if conf.Labels != nil { 118 ret.Spec.Loki.Labels = conf.Labels 119 } 120 if conf.RemoveKeys != nil { 121 ret.Spec.Loki.RemoveKeys = conf.RemoveKeys 122 } 123 return ret 124 }