Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a make dev to output a development manifest #131

Merged
merged 1 commit into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
111 changes: 67 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,38 @@ 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 pod = k.core.v1.pod;
local sonobuoyPod =
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 svc = k.core.v1.service;
local sonobuoyService =
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we pass a var in from Make targets vs. default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way because I don't like the idea of storing configuration in our Makefile.

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()