Skip to content

Commit 8d237a6

Browse files
committed
feat(k8sExporter): Options to allow disabling Events or Node Conditions
Both outputs are currently hardcoded to being enabled, this allows disabling one or the other. Defaults to both enabled to retain current behavior. Larger clusters can save some etcd I/O by skipping one of these outputs if they aren't being consumed. In our case we aren't consuming the Events so writing them just creates more churn.
1 parent 12a8f55 commit 8d237a6

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

cmd/options/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ type NodeProblemDetectorOptions struct {
6565
APIServerWaitInterval time.Duration
6666
// K8sExporterHeartbeatPeriod is the period at which the k8s exporter does forcibly sync with apiserver.
6767
K8sExporterHeartbeatPeriod time.Duration
68+
// K8sExporterWriteEvents determines whether to write Kubernetes Events for problems.
69+
K8sExporterWriteEvents bool
70+
// K8sExporterUpdateNodeConditions determines whether to update Kubernetes Node Conditions for problems.
71+
K8sExporterUpdateNodeConditions bool
6872

6973
// prometheusExporter options
7074
// PrometheusServerPort is the port to bind the Prometheus scrape endpoint. Use 0 to disable.
@@ -117,6 +121,8 @@ func (npdo *NodeProblemDetectorOptions) AddFlags(fs *pflag.FlagSet) {
117121
fs.DurationVar(&npdo.APIServerWaitTimeout, "apiserver-wait-timeout", time.Duration(5)*time.Minute, "The timeout on waiting for kube-apiserver to be ready. This is ignored if --enable-k8s-exporter is false.")
118122
fs.DurationVar(&npdo.APIServerWaitInterval, "apiserver-wait-interval", time.Duration(5)*time.Second, "The interval between the checks on the readiness of kube-apiserver. This is ignored if --enable-k8s-exporter is false.")
119123
fs.DurationVar(&npdo.K8sExporterHeartbeatPeriod, "k8s-exporter-heartbeat-period", 5*time.Minute, "The period at which k8s-exporter does forcibly sync with apiserver.")
124+
fs.BoolVar(&npdo.K8sExporterWriteEvents, "k8s-exporter-write-events", true, "Whether to write Kubernetes Event objects with event details.")
125+
fs.BoolVar(&npdo.K8sExporterUpdateNodeConditions, "k8s-exporter-update-node-conditions", true, "Whether to update Kubernetes Node conditions with event details.")
120126
fs.BoolVar(&npdo.PrintVersion, "version", false, "Print version information and quit")
121127
fs.StringVar(&npdo.HostnameOverride, "hostname-override",
122128
"", "Custom node name used to override hostname")

pkg/exporters/k8sexporter/k8s_exporter.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import (
3838
type k8sExporter struct {
3939
client problemclient.Client
4040
conditionManager condition.ConditionManager
41+
writeEvents bool
42+
updateConditions bool
4143
}
4244

4345
// NewExporterOrDie creates a exporter for Kubernetes apiserver exporting,
@@ -60,6 +62,8 @@ func NewExporterOrDie(ctx context.Context, npdo *options.NodeProblemDetectorOpti
6062
ke := k8sExporter{
6163
client: c,
6264
conditionManager: condition.NewConditionManager(c, clock.RealClock{}, npdo.K8sExporterHeartbeatPeriod),
65+
writeEvents: npdo.K8sExporterWriteEvents,
66+
updateConditions: npdo.K8sExporterUpdateNodeConditions,
6367
}
6468

6569
ke.startHTTPReporting(npdo)
@@ -69,11 +73,15 @@ func NewExporterOrDie(ctx context.Context, npdo *options.NodeProblemDetectorOpti
6973
}
7074

7175
func (ke *k8sExporter) ExportProblems(status *types.Status) {
72-
for _, event := range status.Events {
73-
ke.client.Eventf(util.ConvertToAPIEventType(event.Severity), status.Source, event.Reason, event.Message)
76+
if ke.writeEvents {
77+
for _, event := range status.Events {
78+
ke.client.Eventf(util.ConvertToAPIEventType(event.Severity), status.Source, event.Reason, event.Message)
79+
}
7480
}
75-
for _, cdt := range status.Conditions {
76-
ke.conditionManager.UpdateCondition(cdt)
81+
if ke.updateConditions {
82+
for _, cdt := range status.Conditions {
83+
ke.conditionManager.UpdateCondition(cdt)
84+
}
7785
}
7886
}
7987

0 commit comments

Comments
 (0)