From 72a9f8727fd1e83052408a35dc33947a8ded4e27 Mon Sep 17 00:00:00 2001
From: Benjamin <benjamin@yunify.com>
Date: Fri, 31 May 2019 13:15:17 +0800
Subject: [PATCH] Add prometheus toleration example

Signed-off-by: Benjamin <benjamin@yunify.com>
---
 examples/tolerations.libsonnet | 38 ++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 examples/tolerations.libsonnet

diff --git a/examples/tolerations.libsonnet b/examples/tolerations.libsonnet
new file mode 100644
index 00000000..c717daf9
--- /dev/null
+++ b/examples/tolerations.libsonnet
@@ -0,0 +1,38 @@
+local k = import 'ksonnet/ksonnet.beta.3/k.libsonnet';
+local statefulSet = k.apps.v1beta2.statefulSet;
+local toleration = statefulSet.mixin.spec.template.spec.tolerationsType;
+
+{
+  _config+:: {
+    tolerations+:: [
+      {
+        key: 'key1',
+        operator: 'Equal',
+        value: 'value1',
+        effect: 'NoSchedule',
+      },
+      {
+        key: 'key2',
+        operator: 'Exists',
+      },
+    ]
+  },
+
+  local withTolerations() = {
+    tolerations: [
+      toleration.new() + (
+      if std.objectHas(t, 'key') then toleration.withKey(t.key) else toleration) + (
+      if std.objectHas(t, 'operator') then toleration.withOperator(t.operator) else toleration) + (
+      if std.objectHas(t, 'value') then toleration.withValue(t.value) else toleration) + (
+      if std.objectHas(t, 'effect') then toleration.withEffect(t.effect) else toleration),
+      for t in $._config.tolerations
+    ],
+  },
+
+  prometheus+: {
+    prometheus+: {
+      spec+:
+        withTolerations(),
+    },
+  },
+}
\ No newline at end of file
-- 
GitLab