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

Use ksonnet to generate examples #9

Closed
wants to merge 3 commits into from
Closed
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
31 changes: 30 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# does not yet publish a released e2e container
# https://github.com/kubernetes/kubernetes/issues/47920

EXAMPLE_FILES = $(wildcard examples/quickstart/*.jsonnet)
EXAMPLE_OUTPUT = $(patsubst examples/quickstart/%.jsonnet,examples/quickstart/%.json,$(EXAMPLE_FILES))

TARGET = sonobuoy
GOTARGET = github.com/heptio/$(TARGET)
REGISTRY ?= gcr.io/heptio-images
Expand Down Expand Up @@ -43,16 +46,42 @@ local:
$(BUILD)

container: cbuild
<<<<<<< HEAD
$(DOCKER) build -t $(REGISTRY)/$(TARGET):latest -t $(REGISTRY)/$(TARGET):$(VERSION) .

cbuild:
$(DOCKER) run --rm -v $(DIR):$(BUILDMNT) -w $(BUILDMNT) $(BUILD_IMAGE) /bin/sh -c '$(BUILD) && $(TEST)'

push:
gcloud docker -- push $(REGISTRY)/$(TARGET):$(VERSION)
=======
$(MAKE) -C build/sonobuoy container

push:
$(MAKE) -C build/sonobuoy push
>>>>>>> testing

.PHONY: all container push
.PHONY: all container push generate-examples

clean:
rm -f $(TARGET)
$(DOCKER) rmi $(REGISTRY)/$(TARGET):latest $(REGISTRY)/$(TARGET):$(VERSION) || true
rm -f /examples/quickstart/*.json

generate-examples: $(EXAMPLE_OUTPUT)

examples/quickstart/%.json: examples/quickstart/%.jsonnet
jsonnet -J /usr/local/lib/jsonnet/ksonnet-lib -o $@ $<
<<<<<<< HEAD
=======

clean:
$(MAKE) -C build/sonobuoy clean
$(MAKE) -C build/kube-conformance clean
$(MAKE) -C build/systemd-logs clean
<<<<<<< HEAD
rm -f /examples/quickstart/*.json
=======
rm -f ./examples/quickstart/*.json
>>>>>>> e68ddf3... testing
>>>>>>> testing
5 changes: 4 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
## Setting Up
* [Build From Scratch](build-from-scratch.md)
* [Configuration](configuration.md)
* [YAML templates](/examples)
* [JSON templates](/examples)

## Use Cases
* [Conformance Testing](conformance-testing.md)
* [Plugins](plugins.md)

## Developing Examples
* [Generating Example JSON](building-examples.md)
9 changes: 9 additions & 0 deletions docs/building-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Examples

## Quickstart

The quickstart example is built with [ksonnet][0].

The JSON files are generated with the `make generate-examples` command. To get this to work you must have ksonnet-lib installed in `/usr/local/lib/jsonnet/ksonnet-lib`. After that, `make generate-examples` will build the JSON files that are checked into this repository.

0: http://ksonnet.heptio.com
70 changes: 70 additions & 0 deletions examples/quickstart/00-rbac.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"apiVersion": "v1",
"items": [
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "heptio-sonobuoy"
}
},
{
"apiVersion": "v1",
"kind": "ServiceAccount",
"metadata": {
"labels": {
"component": "sonobuoy"
},
"name": "sonobuoy-serviceaccount",
"namespace": "heptio-sonobuoy"
}
},
{
"apiVersion": "rbac.authorization.k8s.io/v1beta1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we somehow option wrap rbac with a default of true but allow for disabled generation per other issue filed?

Choose a reason for hiding this comment

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

It's not easy right now, but it's certainly on the roadmap for the CLI.

One way to do it right now is to use ext vars, which are passed in via command line. Your build process would involve interrogating the API server, getting capabilities, and passing a flag --ext-str with a value to indicate as such.

"kind": "ClusterRoleBinding",
"metadata": {
"labels": {
"component": "sonobuoy"
},
"name": "sonobuoy-serviceaccount"
},
"roleRef": {
"apiGroup": "rbac.authorization.k8s.io",
"kind": "ClusterRole",
"name": "sonobuoy-serviceaccount"
},
"subjects": [
{
"kind": "ServiceAccount",
"name": "sonobuoy-serviceaccount",
"namespace": "heptio-sonobuoy"
}
]
},
{
"apiVersion": "rbac.authorization.k8s.io/v1beta1",
"kind": "ClusterRole",
"metadata": {
"labels": {
"component": "sonobuoy"
},
"name": "sonobuoy-serviceaccount",
"namespace": "heptio-sonobuoy"
},
"rules": [
{
"apiGroups": [
"*"
],
"resources": [
"*"
],
"verbs": [
"*"
]
}
]
}
],
"kind": "List"
}
75 changes: 75 additions & 0 deletions examples/quickstart/00-rbac.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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 k = import "ksonnet.beta.2/k.libsonnet";

local conf = {
namespace: "heptio-sonobuoy",
labels: {
component: "sonobuoy",
},
serviceAccount: {
name: "sonobuoy-serviceaccount",
},

# shared metadata
metadata: {
name: $.serviceAccount.name,
labels: $.labels,
},

};

local namespace =
local ns = k.core.v1.namespace;
ns.new() +
ns.mixin.metadata.name(conf.namespace);

local serviceaccount =
local sa = k.core.v1.serviceAccount;
sa.new() +
sa.mixin.metadata.mixinInstance(conf.metadata) +
sa.mixin.metadata.namespace(conf.namespace);

local clusterRoleBinding =
local crb = k.rbac.v1beta1.clusterRoleBinding;
crb.new() +
crb.mixin.metadata.mixinInstance(conf.metadata) +
# TODO: replace with `crb.mixinroleRef.kind("ClusterRole") when https://github.com/ksonnet/ksonnet-lib/issues/53 closes.
{roleRef: {kind: "ClusterRole"}} +
crb.mixin.roleRef.apiGroup("rbac.authorization.k8s.io") +
crb.mixin.roleRef.name(conf.serviceAccount.name) +
crb.subjects([
# TODO: replace with `crb.subjectsType.kind("ServiceAccount")` when https://github.com/ksonnet/ksonnet-lib/issues/43 closes.
{kind: "ServiceAccount"} +
crb.subjectsType.name(conf.serviceAccount.name) +
crb.subjectsType.namespace(conf.namespace),
]);

local clusterRole =
local cr = k.rbac.v1beta1.clusterRole;
cr.new() +
cr.mixin.metadata.mixinInstance(conf.metadata) +
cr.mixin.metadata.namespace(conf.namespace) +
cr.rules([
cr.rulesType.apiGroups("*") +
cr.rulesType.resources("*") +
cr.rulesType.verbs("*"),
]);

k.core.v1.list.new([
namespace,
serviceaccount,
clusterRoleBinding,
clusterRole,])
60 changes: 0 additions & 60 deletions examples/quickstart/00-rbac.yaml

This file was deleted.

35 changes: 35 additions & 0 deletions examples/quickstart/10-configmaps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"apiVersion": "v1",
"items": [
{
"apiVersion": "v1",
"data": {
"config.json": "{\"Description\": \"EXAMPLE\", \"Filters\": {\"LabelSelector\": \"\", \"Namespaces\": \".*\"}, \"PluginNamespace\": \"heptio-sonobuoy\", \"Plugins\": [{\"name\": \"systemd_logs\"}, {\"name\": \"e2e\"}], \"Resources\": [\"CertificateSigningRequests\", \"ClusterRoleBindings\", \"ClusterRoles\", \"ComponentStatuses\", \"Nodes\", \"PersistentVolumes\", \"PodSecurityPolicies\", \"ServerVersion\", \"StorageClasses\", \"ThirdPartyResources\", \"ConfigMaps\", \"DaemonSets\", \"Deployments\", \"Endpoints\", \"Events\", \"HorizontalPodAutoscalers\", \"Ingresses\", \"Jobs\", \"LimitRanges\", \"PersistentVolumeClaims\", \"Pods\", \"PodLogs\", \"PodDisruptionBudgets\", \"PodPresets\", \"PodTemplates\", \"ReplicaSets\", \"ReplicationControllers\", \"ResourceQuotas\", \"RoleBindings\", \"Roles\", \"ServiceAccounts\", \"Services\", \"StatefulSets\"], \"ResultsDir\": \"/tmp/sonobuoy\", \"Server\": {\"advertiseaddress\": \"sonobuoy-master:8080\", \"bindaddress\": \"0.0.0.0\", \"bindport\": 8080, \"timeoutseconds\": 3600}, \"Version\": \"v0.8.0\"}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This almost makes it unreadable...

Choose a reason for hiding this comment

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

I would use kubecfg here, and generate YAML instead of JSON. kubecfg natively emits multi-line strings all prettified.

},
"kind": "ConfigMap",
"metadata": {
"labels": {
"component": "sonobuoy"
},
"name": "sonobuoy-config-cm",
"namespace": "heptio-sonobuoy"
}
},
{
"apiVersion": "v1",
"data": {
"e2e.json": "{\"driver\": \"Job\", \"name\": \"e2e\", \"resultType\": \"e2e\", \"spec\": {\"containers\": [{\"env\": [{\"name\": \"E2E_FOCUS\", \"value\": \"Pods should be submitted and removed\"}], \"image\": \"gcr.io/heptio-images/kube-conformance:latest\", \"imagePullPolicy\": \"Always\", \"name\": \"e2e\", \"volumeMounts\": [{\"mountPath\": \"/tmp/results\", \"name\": \"results\"}]}, {\"command\": [\"sh\", \"-c\", \"/sonobuoy worker global -v 5 --logtostderr\"], \"env\": [{\"name\": \"NODE_NAME\", \"valueFrom\": {\"fieldPath\": \"spec.nodeName\", \"fieldRef\": {\"apiVersion\": \"v1\"}}}, {\"name\": \"RESULTS_DIR\", \"value\": \"/tmp/results\"}], \"image\": \"gcr.io/heptio-images/sonobuoy:latest\", \"imagePullPolicy\": \"Always\", \"name\": \"sonobuoy-worker\", \"volumeMounts\": [{\"mountPath\": \"/etc/sonobuoy\", \"name\": \"config\"}, {\"mountPath\": \"/tmp/results\", \"name\": \"results\"}]}], \"restartPolicy\": \"Never\", \"serviceAccountName\": \"sonobuoy-serviceaccount\", \"tolerations\": [{\"effect\": \"NoSchedule\", \"key\": \"node-role.kubernetes.io/master\", \"operator\": \"Exists\"}, {\"key\": \"CriticalAddonsOnly\", \"operator\": \"Exists\"}]}, \"volumes\": [{\"emptyDir\": \"{}\", \"name\": \"results\"}, {\"configMap\": {\"name\": \"__SONOBUOY_CONFIGMAP__\"}, \"name\": \"config\"}]}",
"systemdlogs.json": "{\"driver\": \"DaemonSet\", \"name\": \"systemd_logs\", \"resultType\": \"systemd_logs\", \"spec\": {\"containers\": [{\"command\": [\"sh\", \"-c\", \"/get_systemd_logs.sh && sleep 3600\"], \"env\": [{\"name\": \"NODE_NAME\", \"valueFrom\": {\"fieldPath\": \"spec.nodeName\", \"fieldRef\": {\"apiVersion\": \"v1\"}}}, {\"name\": \"RESULTS_DIR\", \"value\": \"/tmp/results\"}, {\"name\": \"CHROOT_DIR\", \"value\": \"/node\"}], \"image\": \"gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest\", \"imagePullPolicy\": \"Always\", \"name\": \"systemd-logs\", \"securityContext\": {\"privileged\": \"true\"}, \"volumeMounts\": [{\"mountPath\": \"/node\", \"name\": \"root\"}, {\"mountPath\": \"/tmp/results\", \"name\": \"results\"}, {\"mountPath\": \"/etc/sonobuoy\", \"name\": \"config\"}]}, {\"command\": [\"sh\", \"-c\", \"/sonobuoy worker single-node -v 5 --logtostderr && sleep 3600\"], \"env\": [{\"name\": \"NODE_NAME\", \"valueFrom\": {\"fieldPath\": \"spec.nodeName\", \"fieldRef\": {\"apiVersion\": \"v1\"}}}, {\"name\": \"RESULTS_DIR\", \"value\": \"/tmp/results\"}], \"image\": \"gcr.io/heptio-images/sonobuoy:latest\", \"imagePullPolicy\": \"Always\", \"name\": \"sonobuoy-worker\", \"securityContext\": {\"privileged\": \"true\"}, \"volumeMounts\": [{\"mountPath\": \"/tmp/results\", \"name\": \"results\"}, {\"mountPath\": \"/etc/sonobuoy\", \"name\": \"config\"}]}], \"dnsPolicy\": \"ClusterFirstWithHostNet\", \"hostIPC\": \"true\", \"hostNetwork\": \"true\", \"hostPID\": \"true\", \"tolerations\": [{\"effect\": \"NoSchedule\", \"key\": \"node-role.kubernetes.io/master\", \"operator\": \"Exists\"}, {\"key\": \"CriticalAddonsOnly\", \"operator\": \"Exists\"}]}, \"volumes\": [{\"hostPath\": {\"path\": \"/\"}, \"name\": \"root\"}, {\"emptyDir\": \"{}\", \"name\": \"results\"}, {\"configMap\": {\"name\": \"__SONOBUOY_CONFIGMAP__\"}, \"name\": \"config\"}]}"
},
"kind": "ConfigMap",
"metadata": {
"labels": {
"component": "sonobuoy"
},
"name": "sonobuoy-plugins-cm",
"namespace": "heptio-sonobuoy"
}
}
],
"kind": "List"
}
Loading