-
Notifications
You must be signed in to change notification settings - Fork 140
/
conf.go
101 lines (94 loc) · 2.44 KB
/
conf.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
package fluentd
import (
"encoding/json"
"errors"
"fmt"
"github.com/openshift/cluster-logging-operator/internal/generator"
"net/url"
logging "github.com/openshift/cluster-logging-operator/apis/logging/v1"
corev1 "k8s.io/api/core/v1"
)
var (
ErrNoValidInputs = errors.New("No valid inputs found in ClusterLogForwarder")
ErrNoOutputs = errors.New("No outputs defined in ClusterLogForwarder")
ErrInvalidOutputURL = func(o logging.OutputSpec) error {
return fmt.Errorf("Invalid URL in %s output in ClusterLogForwarder", o.Name)
}
ErrInvalidInput = errors.New("Invalid Input")
)
//nolint:govet // using declarative style
func Conf(clspec *logging.ClusterLoggingSpec, secrets map[string]*corev1.Secret, clfspec *logging.ClusterLogForwarderSpec, op generator.Options) []generator.Section {
return []generator.Section{
{
Header(op),
`Generated fluentd conf Header`,
},
{
Sources(clspec, clfspec, op),
"Set of all input sources",
},
{
Concat(clfspec, op),
`Concat pipeline section`,
},
{
Ingress(clfspec, op),
"Ingress pipeline",
},
// input ends
// give a hook here
{
InputsToPipeline(clfspec, op),
"Inputs go to pipelines",
},
{
PipelineToOutputs(clfspec, op),
"Pipeline to Outputs",
},
// output begins here
// give a hook here
{
Outputs(clspec, secrets, clfspec, op),
"Outputs",
},
}
}
func Header(op generator.Options) []generator.Element {
const Header = `
{{define "header" -}}
## CLO GENERATED CONFIGURATION ###
# This file is a copy of the fluentd configuration entrypoint
# which should normally be supplied in a configmap.
<system>
log_level "#{ENV['LOG_LEVEL'] || 'warn'}"
</system>
{{end}}
`
return []generator.Element{
generator.ConfLiteral{
TemplateName: "header",
TemplateStr: Header,
},
}
}
func Verify(clspec *logging.ClusterLoggingSpec, secrets map[string]*corev1.Secret, clfspec *logging.ClusterLogForwarderSpec, op generator.Options) error {
var err error
types := generator.GatherSources(clfspec, op)
if !types.HasAny(logging.InputNameApplication, logging.InputNameInfrastructure, logging.InputNameAudit) {
return ErrNoValidInputs
}
if len(clfspec.Outputs) == 0 {
return ErrNoOutputs
}
for _, p := range clfspec.Pipelines {
if _, err := json.Marshal(p.Labels); err != nil {
return ErrInvalidInput
}
}
for _, o := range clfspec.Outputs {
if _, err := url.Parse(o.URL); err != nil {
return ErrInvalidOutputURL(o)
}
}
return err
}