Skip to content
This repository has been archived by the owner on Jun 12, 2020. It is now read-only.

Commit

Permalink
fix(pvc): added config for fluentd buffer pvc
Browse files Browse the repository at this point in the history
  • Loading branch information
stebenz committed Jan 29, 2020
1 parent 3fbde64 commit a71c2e5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 15 deletions.
3 changes: 2 additions & 1 deletion api/v1beta1/logging-operator.go
Original file line number Diff line number Diff line change
@@ -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"`
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
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"`
}
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"`
Expand All @@ -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"`
Expand All @@ -56,19 +79,22 @@ type Logging struct {
}

func New(conf *Config) *Logging {
return &Logging{
values := &Logging{
APIVersion: "logging.banzaicloud.io/v1beta1",
Kind: "Logging",
Metadata: &Metadata{
Name: conf.Name,
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{
Expand All @@ -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
}
13 changes: 11 additions & 2 deletions internal/bundle/application/applications/loki/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit a71c2e5

Please sign in to comment.