Skip to content

Commit

Permalink
Rewrite Honeycomb agent base in ksonnet
Browse files Browse the repository at this point in the history
This commit will introduce a version of the Honeycomb agent DaemonSet,
rewritten using ksonnet.
  • Loading branch information
hausdorff committed Jun 20, 2017
1 parent 982b6d3 commit a6d5837
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
8 changes: 4 additions & 4 deletions honeycomb-agent-ds-app.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local honeycomb = import "honeycomb-agent-ds.json";
local honeycomb = import "honeycomb-agent-ds-base.libsonnet";
local custom = import "honeycomb-agent-ds-custom.libsonnet";

// Import DaemonSet JSON, append volume to it. The output of this
// equivalent to `honeycomb-agent-ds-custom.json`.
honeycomb +
// 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")
61 changes: 61 additions & 0 deletions honeycomb-agent-ds-base.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
local k = import "ksonnet.beta.2/k.libsonnet";

// Destructuring imports.
local ds = k.extensions.v1beta1.daemonSet;
local container = k.extensions.v1beta1.daemonSet.mixin.spec.template.spec.containersType;
local envVar = container.envType;
local volume = ds.mixin.spec.template.spec.volumesType;
local keyToPath = volume.mixin.configMap.itemsType;
local volumeMount = container.volumeMountsType;

// ----------------------------------------------------------------------------
// Honeycomb agent parts. Containers, volumes, etc.
// ----------------------------------------------------------------------------

local honeycombLabels = {
"k8s-app": "honeycomb-agent",
"kubernetes.io/cluster-service": "true",
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([
"/bin/sh",
"-c",
"/usr/sbin/td-agent 2>&1 >> /var/log/fluentd.log",
]) +
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"),
]);

// ----------------------------------------------------------------------------
// App definition. Honeycomb agent DaemonDet
// ----------------------------------------------------------------------------

{
// base takes a name and a namespace and outputs the default
// DaemonSet for the Honeycomb agent.
base(name, namespace)::
ds.new() +
// Metadata.
ds.mixin.metadata.name(name) +
ds.mixin.metadata.namespace(namespace) +
ds.mixin.metadata.labels(honeycombLabels) +
// 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])
}

0 comments on commit a6d5837

Please sign in to comment.