Last active
July 12, 2022 13:27
-
-
Save steven-terrana/b7d3f5af4cf2dec1c5343e2aa6caacf9 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
/** | |
This step defines three agent drivers to be used: [ "docker", "kubernetes", "labels" ] | |
you set the default agent driver to use via: | |
libraries{ | |
sdp{ | |
agents{ | |
driver = "kubernetes" | |
} | |
} | |
} | |
The step is then invoked within a library like this: | |
void call(){ | |
agent("my-image"){ | |
println "do stuff" | |
} | |
} | |
----- | |
each individual library can optionally override the global configuration by setting agents.driver themselves. | |
Note that this now means that `agents` is a reserved library configuration that can't be used by other libraries. | |
I don't think this is a big deal. | |
libraries{ | |
sdp{ | |
agents{ | |
driver = "kubernetes" | |
} | |
} | |
someLibrary{ | |
agents{ | |
driver = "docker" | |
} | |
} | |
} | |
----- | |
each driver has its own configuration that defines defaults and can be | |
overridden from the global agent configuration and the library configuration. | |
these configurations are passed via a block within `agents` named after the driver. | |
so for example: | |
libraries{ | |
sdp{ | |
agents{ | |
driver = "kubernetes" | |
kubernetes{ | |
myGlobalConfigField = "whatever" | |
myOtherGlobalConfigField = "something else" | |
} | |
} | |
} | |
someLibrary{ | |
agents{ | |
driver = "kubernetes" | |
kubernetes{ | |
myOtherGlobalConfigField = "library override" | |
} | |
} | |
} | |
} | |
you could take this even further and let individual calls to `agent` | |
provide another level of overrides. | |
*/ | |
void call(String id, Closure body){ | |
String driver = body.config?.agents?.driver ?: config?.agents?.driver ?: "docker" | |
switch(config.agents.driver) { | |
case "docker": | |
dockerAgent(id, body) | |
break | |
case "kubernetes": | |
kubernetesAgent(id, body) | |
break | |
case "labels": | |
labelsBody(id, body) | |
break | |
} | |
} | |
/** | |
do whatever logic is needed for kubernetes based agents | |
*/ | |
void kubernetesAgent(String image, Closure body){ | |
Map defaults = [ | |
k1: 1, | |
k2: 2 | |
] | |
Map agentConfig = defaults + (config?.agents?.kubernetes ?: [:]) + (body.config?.agents?.kubernetes ?: [:]) | |
println "running agent with image ${image} on kubernetes with config: ${agentConfig}" | |
// you can get resources from the calling library via: body.resource("agent.yaml") | |
body() | |
} | |
/** | |
do whatever logic is needed for docker based agents | |
*/ | |
void dockerAgent(String image, Closure body){ | |
Map defaults = [ | |
d1: 1, | |
d2: 2 | |
] | |
Map agentConfig = defaults + (config?.agents?.docker ?: [:]) + (body.config?.agents?.docker ?: [:]) | |
println "running agent with image ${image} via docker with config: ${agentConfig}" | |
body() | |
} | |
/** | |
do whatever logic is needed for label based agents | |
*/ | |
void labelAgent(String label, Closure body){ | |
Map defaults = [ | |
l1: 1, | |
l2: 2 | |
] | |
Map agentConfig = defaults + (config?.agents?.labels ?: [:]) + (body.config?.agents?.labels ?: [:]) | |
println "running on node with label: ${label} with config: ${agentConfig}" | |
body() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment