Skip to content

Commit

Permalink
Move stdout-scraping specification into ksonnet mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
hausdorff committed Jun 22, 2017
1 parent 0968a80 commit 9fd7217
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
3 changes: 2 additions & 1 deletion jsonnet/honeycomb-agent-ds-app.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ local custom = import "honeycomb-agent-ds-custom.libsonnet";
// Import Honeycomb agent DaemonSet, append volume to it. The output
// of this equivalent to `honeycomb-agent-ds-custom.json`.
honeycomb.base("honeycomb-agent-v1.1", "kube-system") +
custom.daemonSet.configVolumeMixin("config")
custom.daemonSet.addHostMountedPodLogs("varlog", "varlibdockercontainers")
// + custom.daemonSet.configVolumeMixin("config")
13 changes: 2 additions & 11 deletions jsonnet/honeycomb-agent-ds-base.libsonnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local k = import "ksonnet.beta.2/k.libsonnet";
local k = import "/Users/alex/src/go/src/github.com/ksonnet/ksonnet-lib/ksonnet.beta.2/k.libsonnet";

// Destructuring imports.
local ds = k.extensions.v1beta1.daemonSet;
Expand All @@ -18,10 +18,6 @@ local honeycombLabels = {
version: "v1.1",
};

local varlogVol = volume.fromHostPath("varlog", "/var/log");
local varlibVol =
volume.fromHostPath("varlibdockercontainers", "/var/lib/docker/containers");

local dsContainer =
container.new("honeycomb-agent", "honeycombio/fluentd-honeycomb:1.23") +
container.command([
Expand All @@ -31,10 +27,6 @@ local dsContainer =
]) +
container.mixin.resources.limits({memory: "200Mi"}) +
container.mixin.resources.requests({memory: "200Mi", cpu: "100m"}) +
container.volumeMounts([
volumeMount.new(varlogVol.name, varlogVol.hostPath.path),
volumeMount.new(varlibVol.name, varlibVol.hostPath.path, true)
]) +
container.env([
envVar.fromSecretRef("HONEYCOMB_WRITEKEY", "honeycomb-writekey", "key"),
envVar.new("HONEYCOMB_DATASET", "kubernetes"),
Expand All @@ -56,6 +48,5 @@ local dsContainer =
// Template.
ds.mixin.spec.template.metadata.labels(honeycombLabels) +
ds.mixin.spec.template.spec.containers(dsContainer) +
ds.mixin.spec.template.spec.terminationGracePeriodSeconds(30) +
ds.mixin.spec.template.spec.volumes([varlogVol, varlibVol])
ds.mixin.spec.template.spec.terminationGracePeriodSeconds(30)
}
34 changes: 32 additions & 2 deletions jsonnet/honeycomb-agent-ds-custom.libsonnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local k = import "ksonnet.beta.2/k.libsonnet";
local k = import "/Users/alex/src/go/src/github.com/ksonnet/ksonnet-lib/ksonnet.beta.2/k.libsonnet";

local ds = k.extensions.v1beta1.daemonSet;
local container = k.extensions.v1beta1.daemonSet.mixin.spec.template.spec.containersType;
Expand Down Expand Up @@ -32,6 +32,36 @@ local volumeMount = container.volumeMountsType;
function (c)
if containerSelector(c)
then c + container.volumeMounts([configMount])
else c)
else c),

// addhostMountedPodLogs takes a two volume names and produces a
// mixin that will mount the Kubernetes pod logs into a set of
// containers specified by `containerSelector`.
addHostMountedPodLogs(
varlogVolName, podLogVolName, containerSelector=function(c) true
)::
// Pod logs are located on the host at
// `/var/lib/docker/containers`. Define volumes and mounts for
// these paths, so the Honeytailer can access them.
local varlogVol = volume.fromHostPath(varlogVolName, "/var/log");
local varlogMount =
volumeMount.new(varlogVol.name, varlogVol.hostPath.path);
local podLogsVol =
volume.fromHostPath(
podLogVolName,
"/var/lib/docker/containers");
local podLogMount =
volumeMount.new(podLogsVol.name, podLogsVol.hostPath.path, true);

// Add volume to DaemonSet, and attach mounts to every
// container for which `containerSelector` is true.
ds.mixin.spec.template.spec.volumes([varlogVol, podLogsVol]) +

// Add volume mount to every container in the DaemonSet.
ds.mapContainers(
function (c)
if containerSelector(c)
then c + container.volumeMounts([varlogMount, podLogMount])
else c),
}
}
3 changes: 2 additions & 1 deletion jsonnet/honeycomb-agent-ds.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"volumeMounts": [
{
"mountPath": "/var/log",
"name": "varlog"
"name": "varlog",
"readOnly": false
},
{
"mountPath": "/var/lib/docker/containers",
Expand Down

0 comments on commit 9fd7217

Please sign in to comment.