Skip to content

Commit

Permalink
Add a make dev to output a development manifest
Browse files Browse the repository at this point in the history
Refactor 20-pod.jsonnet to take a few parameters

Signed-off-by: liz <liz@heptio.com>
  • Loading branch information
liztio committed Nov 7, 2017
1 parent a30e220 commit 24ea0ac
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# we output results to this directory by default
/results

# Development manifest
examples/dev.yaml
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
113 changes: 69 additions & 44 deletions examples/ksonnet/components/20-pod.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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])
19 changes: 19 additions & 0 deletions examples/ksonnet/dev.jsonnet
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion examples/ksonnet/quickstart.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 24ea0ac

Please sign in to comment.