From a71c2e58523bd8e8c926c273d7d6354512bceae0 Mon Sep 17 00:00:00 2001 From: Stefan Benz Date: Wed, 29 Jan 2020 16:13:38 +0100 Subject: [PATCH] fix(pvc): added config for fluentd buffer pvc --- api/v1beta1/logging-operator.go | 3 +- .../loggingoperator/logging/logging.go | 78 ++++++++++++++++--- .../applications/loki/logs/logs.go | 13 +++- 3 files changed, 79 insertions(+), 15 deletions(-) diff --git a/api/v1beta1/logging-operator.go b/api/v1beta1/logging-operator.go index bca2029..28a690e 100644 --- a/api/v1beta1/logging-operator.go +++ b/api/v1beta1/logging-operator.go @@ -1,5 +1,6 @@ package v1beta1 type LoggingOperator struct { - Deploy bool `json:"deploy,omitempty"` + Deploy bool `json:"deploy,omitempty"` + FluentdPVC *StorageSpec `json:"fluentdStorage,omitempty" yaml:"fluentdStorage,omitempty"` } diff --git a/internal/bundle/application/applications/loggingoperator/logging/logging.go b/internal/bundle/application/applications/loggingoperator/logging/logging.go index ef820d9..574fd4a 100644 --- a/internal/bundle/application/applications/loggingoperator/logging/logging.go +++ b/internal/bundle/application/applications/loggingoperator/logging/logging.go @@ -1,9 +1,18 @@ package logging +type Storage struct { + StorageClassName string + AccessModes []string + Storage string +} + type Config struct { Name string Namespace string ControlNamespace string + Replicas int + FluentdPVC *Storage + FluentbitPVC *Storage } type Requests struct { Storage string `yaml:"storage,omitempty"` @@ -11,15 +20,26 @@ type Requests struct { type Resources struct { Requests *Requests `yaml:"requests,omitempty"` } -type FluentdPvcSpec struct { +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"` - FluentdPvcSpec *FluentdPvcSpec `yaml:"fluentdPvcSpec,omitempty"` - LogLevel string `yaml:"logLevel,omitempty"` + Metrics *Metrics `yaml:"metrics,omitempty"` + BufferStorageVolume *KubernetesStorage `yaml:"bufferStorageVolume,omitempty"` + LogLevel string `yaml:"logLevel,omitempty"` + DisablePvc bool `yaml:"disablePvc"` + Scaling *Scaling `yaml:"scaling,omitempty"` } type Metrics struct { Port int `yaml:"port"` @@ -35,14 +55,17 @@ type Image struct { } type Fluentbit struct { - Metrics *Metrics `yaml:"metrics,omitempty"` - FilterKubernetes *FilterKubernetes `yaml:"filterKubernetes,omitempty"` - Image *Image `yaml:"image,omitempty"` + Metrics *Metrics `yaml:"metrics,omitempty"` + FilterKubernetes *FilterKubernetes `yaml:"filterKubernetes,omitempty"` + Image *Image `yaml:"image,omitempty"` + BufferStorageVolume *KubernetesStorage `yaml:"bufferStorageVolume,omitempty"` } type Spec struct { - Fluentd *Fluentd `yaml:"fluentd"` - Fluentbit *Fluentbit `yaml:"fluentbit"` - ControlNamespace string `yaml:"controlNamespace"` + 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"` @@ -56,7 +79,7 @@ type Logging struct { } func New(conf *Config) *Logging { - return &Logging{ + values := &Logging{ APIVersion: "logging.banzaicloud.io/v1beta1", Kind: "Logging", Metadata: &Metadata{ @@ -64,11 +87,14 @@ func New(conf *Config) *Logging { Namespace: conf.Namespace, }, Spec: &Spec{ - ControlNamespace: conf.ControlNamespace, + FlowConfigCheckDisabled: true, + EnableRecreateWorkloadOnImmutableFieldChange: true, + ControlNamespace: conf.ControlNamespace, Fluentd: &Fluentd{ Metrics: &Metrics{ Port: 8080, }, + DisablePvc: true, }, Fluentbit: &Fluentbit{ Metrics: &Metrics{ @@ -82,4 +108,32 @@ func New(conf *Config) *Logging { }, }, } + 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.Replicas != 0 { + values.Spec.Fluentd.Scaling = &Scaling{ + Replicas: conf.Replicas, + } + } + return values } diff --git a/internal/bundle/application/applications/loki/logs/logs.go b/internal/bundle/application/applications/loki/logs/logs.go index 29653ec..37809d0 100644 --- a/internal/bundle/application/applications/loki/logs/logs.go +++ b/internal/bundle/application/applications/loki/logs/logs.go @@ -31,19 +31,28 @@ func GetAllResources(toolsetCRDSpec *toolsetsv1beta1.ToolsetSpec) []interface{} } //logging resource so that fluentd and fluentbit are deployed - ret = append(ret, getLogging()) + ret = append(ret, getLogging(toolsetCRDSpec)) } return ret } -func getLogging() *logging.Logging { +func getLogging(toolsetCRDSpec *toolsetsv1beta1.ToolsetSpec) *logging.Logging { conf := &logging.Config{ Name: "logging", Namespace: "caos-system", ControlNamespace: "caos-system", } + if toolsetCRDSpec.LoggingOperator.FluentdPVC != nil { + conf.FluentdPVC = &logging.Storage{ + StorageClassName: toolsetCRDSpec.LoggingOperator.FluentdPVC.StorageClass, + Storage: toolsetCRDSpec.LoggingOperator.FluentdPVC.Size, + } + if toolsetCRDSpec.LoggingOperator.FluentdPVC.AccessModes != nil { + conf.FluentdPVC.AccessModes = toolsetCRDSpec.LoggingOperator.FluentdPVC.AccessModes + } + } return logging.New(conf) }