Last active
May 26, 2016 09:59
-
-
Save ant31/bb28fb9ab5fdc924d817c4cb37dc8b64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
seq(i):: ( | |
[x for x in std.range(1, i)] | |
), | |
shards(s, target):: ( | |
if std.type(target) == 'null' then | |
s | |
else if std.type(target) == "object" then | |
std.mergePatch(s, target) | |
else if std.type(target) == "array" then | |
target | |
else if std.type(target) == "number" then | |
[{name: x} for x in self.seq(target)] | |
else | |
error "Bad shard type: %s (%s)" % [target, std.type(target)] | |
), | |
shard_count(n):: ([{name: x} for x in std.range(1, n)]), | |
shard_list(shard, shards):: ( | |
if shard == "true" || std.type(shard) == "boolean" then | |
shards | |
else if std.type(shard) == "string" then | |
if std.type(shards[shard]) == "number" then | |
self.shard_count(shards[shard]) | |
else | |
shards[shard] | |
else if std.type(shard) == "number" then | |
self.shard_count(shard) | |
else | |
error "Unknow shard value: %s (%s)" % [shard, std.type(shard)] | |
), | |
// NEW | |
template(resource):: ( | |
resource + {template: resource.template % resource.variables} | |
), | |
// NEW | |
sharded_resource(resource, shards, variables):: ( | |
local resource_shards = self.shard_list(resource.sharded, shards); | |
[ | |
local extra = { | |
shard: shard.name, | |
name: "%s-%s" % [resource.name, shard.name], | |
}; | |
local var = if std.objectHas(shard, "variables") == true then | |
{variables: variables + extra + | |
shard.variables + {shards: resource_shards}} | |
else | |
{variables: variables + extra + {shards: resource_shards}}; | |
local r = resource + extra + var; | |
self.template(r) for shard in resource_shards] | |
), | |
// NEW | |
templated_resource(resource, shards, variables):: ( | |
self.template(resource + {variables: variables}) | |
), | |
// NEW | |
resources(resources, shards, variables):: ( | |
[ | |
if std.objectHas(resource, "sharded") then | |
self.sharded_resource(resource, shards, variables) | |
else | |
self.templated_resource(resource, shards, variables) | |
for resource in resources] | |
) | |
// NEW | |
variables(vars, target):: ( | |
std.mergePatch(vars, target) | |
), | |
// NEW | |
deploy(dep):: ( | |
dep | |
), | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local kpm = import "kpm.libjsonnet"; | |
function( | |
namespace="default", | |
variables={namespace: namespace}, | |
shards=null, | |
patch={}, | |
) | |
{ | |
package: { | |
author: 'Antoine Legrand', | |
version: '3.5.6-1', | |
description: 'rabbitmq', | |
license: 'MIT', | |
name: 'rabbitmq/rabbitmq', | |
}, | |
variables: kpm.variables({ | |
image: "quay.io/ant31/kubernetes-rabbitmq", | |
cookie: "Dffds9342", | |
data_volume: { emptyDir: { medium: '' }, name: 'varlibrabbitmq' }, | |
}, variables), | |
shards: kpm.shards({ | |
rmq: [ | |
{ name: 'bunny' }, | |
{ name: 'hare' }, | |
{ name: 'bunny', | |
variables: { args: ['--ram'] } }, | |
], | |
etcd: 5 | |
}, shards), | |
resources: kpm.resources([{ | |
type: "svc", | |
protected: true, | |
sharded: 'rmq', | |
name: "rabbitmq", | |
file: "rabbitmq-svc.yaml", | |
template: (importstr "templates/rabbitmq-svc.yaml"), | |
}, | |
{ | |
type: "rc", | |
sharded: 'rmq', | |
name: "rabbitmq", | |
file: "rabbitmq-rc.yaml", | |
template: (importstr "templates/rabbitmq-rc.yaml"), | |
}, | |
{ | |
type: "svc", | |
name: "rabbitmq", | |
file: "rabbitmq-all-svc.yaml", | |
template: (importstr "templates/rabbitmq-all-svc.yaml") | |
}, | |
{ | |
type: "svc", | |
name: "rabbitmq-mgt", | |
file: "rabbitmq-management-svc.yaml", | |
template: (importstr "templates/rabbitmq-management-svc.yaml") | |
}], $.shards, $.variables), | |
deploy: kpm.deploy([ | |
{ | |
name: '$self', | |
}, | |
{ | |
name: 'coreos/etcd', | |
shards: $.shards.etcd, | |
}]), | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
package: | |
name: rabbitmq/rabbitmq | |
author: Antoine Legrand | |
version: 3.5.6 | |
description: rabbitmq | |
license: MIT | |
variables: | |
namespace: default | |
image: quay.io/ant31/kubernetes-rabbitmq | |
cookie: "Dffds9342" | |
data_volume: | |
name: varlibrabbitmq | |
emptyDir: | |
medium: "" | |
resources: | |
- file: rabbitmq-svc.yaml | |
type: svc | |
name: rabbitmq | |
sharded: rmq | |
protected: true | |
- file: rabbitmq-all-svc.yaml | |
type: svc | |
name: rabbitmq | |
- file: rabbitmq-management-svc.yaml | |
type: svc | |
name: rabbitmq-mgt | |
- file: rabbitmq-rc.yaml | |
type: rc | |
name: rabbitmq | |
sharded: rmq | |
shards: | |
rmq: [ { name: "s" }, | |
{ name: "hare" }, | |
{ name: "bunny", variables: {args: ["--ram"]}} | |
] | |
etcd: 5 | |
deploy: | |
- name: $self | |
- name: coreos/etcd | |
shards: "{{$.shards.etcd}}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment