From 24ea0acacfbab6f84ab791cf292f2b86901c8419 Mon Sep 17 00:00:00 2001 From: liz Date: Mon, 6 Nov 2017 17:29:06 -0500 Subject: [PATCH] Add a `make dev` to output a development manifest Refactor 20-pod.jsonnet to take a few parameters Signed-off-by: liz --- .gitignore | 3 + Makefile | 8 +- examples/ksonnet/components/20-pod.jsonnet | 113 +++++++++++++-------- examples/ksonnet/dev.jsonnet | 19 ++++ examples/ksonnet/quickstart.jsonnet | 2 +- 5 files changed, 99 insertions(+), 46 deletions(-) create mode 100644 examples/ksonnet/dev.jsonnet diff --git a/.gitignore b/.gitignore index 1b152d706..ed317b2d1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ # we output results to this directory by default /results + +# Development manifest +examples/dev.yaml diff --git a/Makefile b/Makefile index 79d946128..e7f19d1b4 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ EXAMPLE_FILES = $(wildcard examples/ksonnet/components/*.jsonnet) EXAMPLE_OUTPUT = examples/quickstart.yaml +DEV_OUTPUT = examples/dev.yaml KSONNET_BUILD_IMAGE = ksonnet/ksonnet-lib:beta.2 TARGET = sonobuoy @@ -98,7 +99,12 @@ clean: generate: latest-ksonnet $(EXAMPLE_OUTPUT) -$(EXAMPLE_OUTPUT): examples/ksonnet/*.jsonnet examples/ksonnet/components/*.jsonnet +$(EXAMPLE_OUTPUT): examples/ksonnet/quickstart.jsonnet examples/ksonnet/components/*.jsonnet + $(KUBECFG_CMD) + +dev: latest-ksonnet $(DEV_OUTPUT) + +$(DEV_OUTPUT): examples/ksonnet/dev.jsonnet examples/ksonnet/components/*.jsonnet $(KUBECFG_CMD) latest-ksonnet: diff --git a/examples/ksonnet/components/20-pod.jsonnet b/examples/ksonnet/components/20-pod.jsonnet index a330309c9..2bf56cd50 100644 --- a/examples/ksonnet/components/20-pod.jsonnet +++ b/examples/ksonnet/components/20-pod.jsonnet @@ -12,19 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -local k = import "ksonnet.beta.2/k.libsonnet"; -local conf = { +local k = import "ksonnet.beta.2/k.libsonnet"; +local values = std.extVar("values"); +local conf(opts) = { namespace: "heptio-sonobuoy", selector: { run: "sonobuoy-master", }, - labels: $.selector + { + labels: $.selector { component: $.pod.name, }, pod: { name: "sonobuoy", - labels: $.labels + { + labels: $.labels { tier: "analysis", }, restartPolicy: "Never", @@ -40,33 +41,42 @@ local conf = { type: "ClusterIP", }, master: { - name: "kube-sonobuoy", - command: ["/bin/bash", "-c", "/sonobuoy master --no-exit=true -v 3 --logtostderr"], - image: "gcr.io/heptio-images/sonobuoy:master", - imagePullPolicy: "Always", - volumeMounts: [ - { - name: $.volumes[0].name, - mountPath: "/etc/sonobuoy", - }, - { - name: $.volumes[1].name, - mountPath: "/plugins.d", - }, - { - name: $.volumes[2].name, - mountPath: "/tmp/sonobuoy", - }, - ], + name: "kube-sonobuoy", + image: "gcr.io/heptio-images/sonobuoy:master", + command: [ + "/bin/bash", + "-c", + std.join("", [ + "/sonobuoy master --no-exit=true -v ", + if opts.debug then "5" else "3", + " --logtostderr", + if opts.debug then " --debug" else "" + ]), + ], + imagePullPolicy: opts.pullPolicy, + volumeMounts: [ + { + name: $.volumes[0].name, + mountPath: "/etc/sonobuoy", + }, + { + name: $.volumes[1].name, + mountPath: "/plugins.d", + }, + { + name: $.volumes[2].name, + mountPath: "/tmp/sonobuoy", + }, + ], }, volumes: [ { name: "sonobuoy-config-volume", - configMap: {name: "sonobuoy-config-cm"}, + configMap: { name: "sonobuoy-config-cm" }, }, { name: "sonobuoy-plugins-volume", - configMap: {name: "sonobuoy-plugins-cm"}, + configMap: { name: "sonobuoy-plugins-cm" }, }, { name: "output-volume", @@ -76,25 +86,40 @@ local conf = { name: "sonobuoy", }; -local sonobuoyPod = local pod = k.core.v1.pod; - pod.new() + - pod.mixin.metadata.name(conf.pod.name) + - pod.mixin.metadata.namespace(conf.namespace) + - pod.mixin.metadata.labels(conf.pod.labels) + - pod.mixin.spec.restartPolicy(conf.pod.restartPolicy) + - pod.mixin.spec.serviceAccountName(conf.pod.serviceAccountName) + - pod.mixin.spec.containers([ - conf.master + - pod.mixin.spec.containersType.env([ - pod.mixin.spec.containersType.envType.fromFieldPath("SONOBUOY_ADVERTISE_IP", "status.podIP") - ]) - ]) + - pod.mixin.spec.volumes(conf.volumes); -local sonobuoyService = local svc = k.core.v1.service; - svc.new(conf.service.name, conf.selector, [conf.service.port],) + - svc.mixin.metadata.namespace(conf.namespace) + - svc.mixin.metadata.labels(conf.labels) + - svc.mixin.spec.type(conf.service.type); +{ + objects(pullPolicy="Always", debug=false) :: + local opts = { + pullPolicy: pullPolicy, + debug: debug, + }; + + local myconf = conf(opts); + local sonobuoyPod = + local pod = k.core.v1.pod; + pod.new() + + pod.mixin.metadata.name(myconf.pod.name) + + pod.mixin.metadata.namespace(myconf.namespace) + + pod.mixin.metadata.labels(myconf.pod.labels) + + pod.mixin.spec.restartPolicy(myconf.pod.restartPolicy) + + pod.mixin.spec.serviceAccountName(myconf.pod.serviceAccountName) + + pod.mixin.spec.containers([ + myconf.master + + pod.mixin.spec.containersType.env([ + pod.mixin.spec.containersType.envType.fromFieldPath("SONOBUOY_ADVERTISE_IP", "status.podIP"), + ]), + ]) + + pod.mixin.spec.volumes(myconf.volumes); + + local sonobuoyService = + local svc = k.core.v1.service; + svc.new(myconf.service.name, myconf.selector, [myconf.service.port],) + + svc.mixin.metadata.namespace(myconf.namespace) + + svc.mixin.metadata.labels(myconf.labels) + + svc.mixin.spec.type(myconf.service.type); + + k.core.v1.list.new([sonobuoyPod, sonobuoyService]) + + +} -k.core.v1.list.new([sonobuoyPod, sonobuoyService]) diff --git a/examples/ksonnet/dev.jsonnet b/examples/ksonnet/dev.jsonnet new file mode 100644 index 000000000..6fae1b59e --- /dev/null +++ b/examples/ksonnet/dev.jsonnet @@ -0,0 +1,19 @@ +# Copyright 2017 Heptio Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +local rbac = import "examples/ksonnet/components/00-rbac.jsonnet"; +local configmaps = import "examples/ksonnet/components/10-configmaps.jsonnet"; +local pod = import "examples/ksonnet/components/20-pod.jsonnet"; + +rbac + configmaps + pod.objects(pullPolicy="IfNotPresent", debug=true) diff --git a/examples/ksonnet/quickstart.jsonnet b/examples/ksonnet/quickstart.jsonnet index 818abac2a..99d8f4b87 100644 --- a/examples/ksonnet/quickstart.jsonnet +++ b/examples/ksonnet/quickstart.jsonnet @@ -16,4 +16,4 @@ local rbac = import "examples/ksonnet/components/00-rbac.jsonnet"; local configmaps = import "examples/ksonnet/components/10-configmaps.jsonnet"; local pod = import "examples/ksonnet/components/20-pod.jsonnet"; -rbac + configmaps + pod +rbac + configmaps + pod.objects()