blob: 124bc8fa36781ddb40f6f5434dbf5b312f6a7d6f [file] [log] [blame]
#!/bin/bash
# This script uses jq to create the envoy JSON config file `simple.json`
# from kubernetes services data. Then it uses merge_envoy to merge
# `simple.json` with 'envoy-starter.json' to create `computed.json`.
# jq is available via apt get.
#
# The jq part of the script strips out all Services that don't have a
# skia.org.domain annotation.
#
# Selects all Services that have a port named "http"
#
# And then removes all Service ports that aren't named "http".
kubectl get services -o json | jq '{
static_resources: {
listeners: [
{
filter_chains: {
filters: [
{
typed_config: {
route_config: {
virtual_hosts: [
.items[]
| select(.metadata.annotations["skia.org.domain"] != null)
| select(.spec.ports[].name == "http")
| del(.spec.ports[] | select(.name != "http"))
| {
name: .metadata.annotations["skia.org.domain"],
domains: .metadata.annotations["skia.org.domain"],
routes: [
{
match: { prefix: "/" },
route: {
cluster: .metadata.name,
timeout: {
seconds: 600
}
}
}
]
}
]
}
}
}
]
}
}
],
clusters: [
.items[]
| select(.metadata.annotations["skia.org.domain"] != null)
| select(.spec.ports[].name == "http")
| del(.spec.ports[] | select(.name != "http"))
| {
name: .metadata.name,
type: "STRICT_DNS",
connect_timeout: {
seconds: 1
},
load_assignment: {
cluster_name: .metadata.name,
endpoints: [
{
lb_endpoints: [
{
endpoint: {
address: {
socket_address: {
address: .metadata.name,
port_value: .spec.ports[0].port
}
}
}
}
]
}
]
}
}
]}}' > simple.json
merge_envoy envoy-starter.json simple.json > computed.json
update_probers