/
add-on-fluentd.go
125 lines (113 loc) · 5.19 KB
/
add-on-fluentd.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package eksconfig
import (
"errors"
"github.com/aws/aws-k8s-tester/pkg/timeutil"
)
// AddOnFluentd defines parameters for EKS cluster
// add-on Fluentd.
// Publishes worker nodes logs to:
// - /aws/containerinsights/[CLUSTER-NAME]/application
// - /aws/containerinsights/[CLUSTER-NAME]/dataplane
// - /aws/containerinsights/[CLUSTER-NAME]/host
type AddOnFluentd struct {
// Enable is 'true' to create this add-on.
Enable bool `json:"enable"`
// Created is true when the resource has been created.
// Used for delete operations.
Created bool `json:"created" read-only:"true"`
TimeFrameCreate timeutil.TimeFrame `json:"time-frame-create" read-only:"true"`
TimeFrameDelete timeutil.TimeFrame `json:"time-frame-delete" read-only:"true"`
// Namespace is the namespace to create objects in.
Namespace string `json:"namespace"`
// RepositoryBusyboxAccountID is the account ID for tester ECR image.
// e.g. "busybox" for "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/busybox"
RepositoryBusyboxAccountID string `json:"repository-busybox-account-id,omitempty"`
// RepositoryBusyboxRegion is the ECR repository region to pull from.
RepositoryBusyboxRegion string `json:"repository-busybox-region,omitempty"`
// RepositoryBusyboxName is the repositoryName for tester ECR image.
// e.g. "busybox" for "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/busybox"
RepositoryBusyboxName string `json:"repository-busybox-name,omitempty"`
// RepositoryBusyboxImageTag is the image tag for tester ECR image.
// e.g. "latest" for image URI "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/busybox:latest"
RepositoryBusyboxImageTag string `json:"repository-busybox-image-tag,omitempty"`
// Threads is the number of threads for fluentd.
// ref. https://docs.fluentd.org/v/0.12/output#num_threads
Threads int `json:"threads"`
// MetadataLogLevel is the log level for "@type kubernetes_metadata".
// ref. https://docs.fluentd.org/deployment/system-config
// ref. https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter
MetadataLogLevel string `json:"metadata-log-level"`
// MetadataCacheSize is the size of the cache of Kubernetes metadata
// to reduce the requests to the kube-apiserver.
// ref. "@type kubernetes_metadata"
// ref. https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter
MetadataCacheSize int `json:"metadata-cache-size"`
// MetadataWatch is true to enable watch on pods on the kube-apiserver
// for updates to the metadata.
// ref. "@type kubernetes_metadata"
// ref. https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter
MetadataWatch bool `json:"metadata-watch"`
// MetadataSkipLabels is true to skip all label fields from the metadata.
// ref. "@type kubernetes_metadata"
// ref. https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter
MetadataSkipLabels bool `json:"metadata-skip-labels"`
// MetadataSkipMasterURL is true to skip "master_url" field from the metadata.
// ref. "@type kubernetes_metadata"
// ref. https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter
MetadataSkipMasterURL bool `json:"metadata-skip-master-url"`
// MetadataSkipContainerMetadata is true to skip some container data of the metadata.
// For example, if true, it skips container image and image ID fields.
// ref. "@type kubernetes_metadata"
// ref. https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter
MetadataSkipContainerMetadata bool `json:"metadata-skip-container-metadata"`
// MetadataSkipNamespaceMetadata is true to skip "namespace_id" field from the metadata.
// If true, the plugin will be faster with less CPU consumption.
// ref. "@type kubernetes_metadata"
// ref. https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter
MetadataSkipNamespaceMetadata bool `json:"metadata-skip-namespace-metadata"`
}
// EnvironmentVariablePrefixAddOnFluentd is the environment variable prefix used for "eksconfig".
const EnvironmentVariablePrefixAddOnFluentd = AWS_K8S_TESTER_EKS_PREFIX + "ADD_ON_FLUENTD_"
// IsEnabledAddOnFluentd returns true if "AddOnFluentd" is enabled.
// Otherwise, nil the field for "omitempty".
func (cfg *Config) IsEnabledAddOnFluentd() bool {
if cfg.AddOnFluentd == nil {
return false
}
if cfg.AddOnFluentd.Enable {
return true
}
cfg.AddOnFluentd = nil
return false
}
func getDefaultAddOnFluentd() *AddOnFluentd {
return &AddOnFluentd{
Enable: false,
Threads: 8,
MetadataLogLevel: "warn",
MetadataCacheSize: 20000,
MetadataWatch: false,
MetadataSkipLabels: true,
MetadataSkipMasterURL: true,
MetadataSkipContainerMetadata: true,
MetadataSkipNamespaceMetadata: true,
}
}
func (cfg *Config) GetAddOnFluentdRepositoryBusyboxRegion() string {
if !cfg.IsEnabledAddOnFluentd() {
return cfg.Region
}
return cfg.AddOnFluentd.RepositoryBusyboxRegion
}
func (cfg *Config) validateAddOnFluentd() error {
if !cfg.IsEnabledAddOnFluentd() {
return nil
}
if !cfg.IsEnabledAddOnNodeGroups() && !cfg.IsEnabledAddOnManagedNodeGroups() {
return errors.New("AddOnFluentd.Enable true but no node group is enabled")
}
if cfg.AddOnFluentd.Namespace == "" {
cfg.AddOnFluentd.Namespace = cfg.Name + "-fluentd"
}
return nil
}