Created
September 25, 2016 08:27
-
-
Save welshstew/8cf0ef53903a0360c7d4fa050e46d83c to your computer and use it in GitHub Desktop.
simple bit of groovy to show how to execute an "oc patch"
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
import groovy.json.JsonOutput | |
import groovy.json.JsonSlurper | |
//Simple example to show patching a container with new environment variables - need to have oc login before... :) | |
def dcToUpdate = "kie-app-postgresql" | |
def newEnvVars = [[name:"GROOVY_ROCKS", value: "true"], [name: "LOVE_OPENSHIFT", value: "of course"]] | |
def currentDC = new JsonSlurper().parseText(["oc", "get" , "dc" , dcToUpdate ,"-o" ,"json"].execute().text) | |
def containers = currentDC.spec.template.spec.containers | |
//add new env vars to container definition | |
newEnvVars.each { containers[0].env.add(it) } | |
def patcher = [spec:[template:[spec:["containers":containers]]]] | |
//generate patch command | |
def patchCmd = ["oc", "patch", "dc", dcToUpdate, "-p", JsonOutput.toJson(patcher)] | |
println patchCmd.join(" ") | |
def patchProc = patchCmd.execute() | |
def patchProcStream = new StringBuffer(); | |
//different execution style in case of err | |
patchProc.waitForProcessOutput(patchProcStream, System.err); | |
println(patchProcStream.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! This was an immense help