Skip to content

Commit

Permalink
Add annotate to OpenShift DSL
Browse files Browse the repository at this point in the history
Adds openshift.selector("foo").annotate([k1:"v1", k2:"v2"], "--overwrite")

Fixes openshift#83
  • Loading branch information
coreydaley authored and gabemontero committed Feb 8, 2018
1 parent 3ea1fbc commit e19e406
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
5 changes: 5 additions & 0 deletions examples/jenkins-image-sample.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ try {
// Output the url of the currently selected cluster
echo "Using project ${openshift.project()} in cluster with url ${openshift.cluster()}"

// Test selector.annotate
//def railsTemplate = openshift.create("https://raw.githubusercontent.com/openshift/rails-ex/master/openshift/templates/rails-postgresql.json")
//railsTemplate.annotate([key1:"value1", key2:"value2"])
//railsTemplate.delete()

def saSelector1 = openshift.selector( "serviceaccount" )
saSelector1.describe()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,12 +975,12 @@ class OpenShiftDSL implements Serializable {
}

@NonCPS
private ArrayList<String> flattenLabels(Map labels) {
private ArrayList<String> flattenMap(Map pairs) {
ArrayList<String> args = new ArrayList<>();
if (labels == null) {
if (pairs == null) {
return args;
}
Iterator<Map.Entry> i = labels.entrySet().iterator();
Iterator<Map.Entry> i = pairs.entrySet().iterator();
while (i.hasNext()) {
Map.Entry e = i.next();
// TODO: handle quotes, newlines, etc?
Expand Down Expand Up @@ -1019,26 +1019,34 @@ class OpenShiftDSL implements Serializable {
return objectList != null && objectList.size() == 0;
}

public Result label(Map newLabels, Object... ouserArgs) throws AbortException {
private Result runSubVerb(String action, Map pairs, Object... ouserArgs) throws AbortException {
String[] userArgs = toStringArray(ouserArgs);
List verbArgs = selectionArgs();
if (kind != null && labels==null) {
verbArgs.add("--all");
}
verbArgs.addAll(flattenLabels(newLabels));
Result r = new Result("label");
verbArgs.addAll(flattenMap(pairs));
Result r = new Result(action);

if (_isEmptyStatic()) {
return r;
}

r.actions.add(
(OcAction.OcActionResult)script._OcAction(buildCommonArgs("label", verbArgs, userArgs))
(OcAction.OcActionResult)script._OcAction(buildCommonArgs(action, verbArgs, userArgs))
);
r.failIf("Error during label");
r.failIf("Error during " + action);
return r;

}

public Result label(Map newLabels, Object... ouserArgs) throws AbortException {
return runSubVerb("label", newLabels, ouserArgs);
}

public Result annotate(Map newAnnotations, Object... ouserArgs) throws AbortException {
return runSubVerb("annotate", newAnnotations, ouserArgs);
}

public Result describe(Object... ouserArgs) throws AbortException {
String[] userArgs = toStringArray(ouserArgs);
Expand Down Expand Up @@ -1343,7 +1351,6 @@ class OpenShiftDSL implements Serializable {
(expandedKind+"s").equals(k)) {
newList.add(name);
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,30 @@
</li>
</ul>
</dd>
<dt>
<a name="Selector_annotate"/>
<code>Selector.annotate(annotations:Map, [args...:String]):Result</code><br />
</dt>
<dd>
<p>
<p style="margin-left: 1em; color:#657383;">
Example:<br />
<code>
openshift.selector("pods").annotate([ k1:'v1', k2:'v2' ], "--overwrite")<br />
</code>
</p>
<br />
Adds the specified annotations to the objects selected by the receiver.
<ul>
<li>
<b>annotations</b> - A map of annotations to apply (e.g. [ annotation1 : 'value1', annotation2 : 'value2' ])
</li>
<li>
<b>args...</b> - An optional list of arguments which will be appended directly to the annotate invocation.
</li>
</ul>
</p>
</dd>
<dt>
<code id="Selector_startBuild">Selector.startBuild([args...:String]):StaticSelector</code><br />
</dt>
Expand Down

0 comments on commit e19e406

Please sign in to comment.