Skip to content

Instantly share code, notes, and snippets.

@teyckmans
Last active May 26, 2019 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teyckmans/0e1c18b7e6409425191ee7c3bbd80d51 to your computer and use it in GitHub Desktop.
Save teyckmans/0e1c18b7e6409425191ee7c3bbd80d51 to your computer and use it in GitHub Desktop.
KubeRig resourcesHelper extension function
package example
import io.k8s.api.core.v1.ContainerDsl
fun ContainerDsl.resourcesHelper(cpuRequest: String = "", memoryRequest: String = "", cpuLimit: String = "", memoryLimit: String = "") {
resources {
if (cpuRequest != "" || memoryRequest != "") {
requests {
if (cpuRequest != "") {
request("cpu") {
quantity(cpuRequest)
}
}
if (memoryRequest != "") {
request("memory") {
quantity(memoryRequest)
}
}
}
}
if (cpuLimit != "" || memoryLimit != "") {
limits {
if (cpuLimit != "") {
limit("cpu") {
quantity(cpuLimit)
}
}
if (memoryLimit != "") {
limit("memory") {
quantity(memoryLimit)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment