Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ You may either build from source using maven (mvn clean package) which, using th

Compatibility
---------
Versions of this client known to be compatible with origin
Versions of this client known to be compatible with OpenShift

| Client Version | OpenShift Origin Server |
|--------------------------|-------------------------|
| 5.0.0-SNAPSHOT | latest, v1.3.0-alpha.2 |
| | v1.3.0-alpha.3 |


Usage
Expand Down Expand Up @@ -73,3 +74,11 @@ The client as well as resources supported by OpenShift may have certain capabili
}, null);

Various examples of using the capabilities may be found in the integration tests.

Testing
-------

To run the integration tests:
1. Define a user with cluster admin privilege
1. Download the oc binary
1. Run the tests: `mvn integration-test -Pintegration-tests -DserverURL=https://localhost:8443 -Ddefault.cluster.admin=foo -Ddefault.cluster.password=bar -Ddefault.openshift.location=/tmp/oc`
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
import com.openshift.internal.restclient.model.build.DockerBuildStrategy;
import com.openshift.internal.restclient.model.build.GitBuildSource;
import com.openshift.internal.restclient.model.build.ImageChangeTrigger;
import com.openshift.internal.restclient.model.build.STIBuildStrategy;
import com.openshift.internal.restclient.model.build.SourceBuildStrategy;
import com.openshift.internal.restclient.model.build.WebhookTrigger;
import com.openshift.restclient.IClient;
import com.openshift.restclient.images.DockerImageURI;
import com.openshift.restclient.model.IBuildConfig;
import com.openshift.restclient.model.IObjectReference;
import com.openshift.restclient.model.build.BuildSourceType;
Expand All @@ -37,7 +35,6 @@
import com.openshift.restclient.model.build.IDockerBuildStrategy;
import com.openshift.restclient.model.build.IGitBuildSource;
import com.openshift.restclient.model.build.IImageChangeTrigger;
import com.openshift.restclient.model.build.ISTIBuildStrategy;
import com.openshift.restclient.model.build.ISourceBuildStrategy;
import com.openshift.restclient.model.build.IWebhookTrigger;

Expand All @@ -59,10 +56,6 @@ public class BuildConfig extends KubernetesResource implements IBuildConfig {
public static final String BUILDCONFIG_DOCKER_NOCACHE = "spec.strategy.dockerStrategy.noCache";
public static final String BUILDCONFIG_DOCKER_BASEIMAGE = "spec.strategy.dockerStrategy.baseImage";
private static final String BUILDCONFIG_OUTPUT_REPO = "spec.output.to.name";
private static final String BUILDCONFIG_STI_IMAGE = "spec.strategy.sourceStrategy.from.name";
private static final String BUILDCONFIG_STI_SCRIPTS = "spec.strategy.sourceStrategy.scripts";
private static final String BUILDCONFIG_STI_INCREMENTAL = "spec.strategy.sourceStrategy.incremental";
private static final String BUILDCONFIG_STI_ENV = "spec.strategy.sourceStrategy.env";
private static final String BUILDCONFIG_TRIGGERS = "spec.triggers";
private static final String BUILD_CONFIG_WEBHOOK_GITHUB_SECRET = "github.secret";
private static final String BUILD_CONFIG_WEBHOOK_GENERIC_SECRET = "generic.secret";
Expand All @@ -79,12 +72,9 @@ public BuildConfig(ModelNode node, IClient client, Map<String, String []> overri

@Override
public IObjectReference getBuildOutputReference() {
ModelNode node = get("spec.output.to");
if(!node.isDefined()) return null;
return new ObjectReference(node);
return new ObjectReference(get("spec.output.to"));
}


@Override
public List<IBuildTrigger> getBuildTriggers() {
List<IBuildTrigger> triggers = new ArrayList<IBuildTrigger>();
Expand All @@ -93,16 +83,13 @@ public List<IBuildTrigger> getBuildTriggers() {
for (ModelNode node : list) {
String type = node.get(TYPE).asString();
switch(type){
case BuildTriggerType.generic:
case BuildTriggerType.GENERIC:
triggers.add(new WebhookTrigger(BuildTriggerType.GENERIC,
asString(node, BUILD_CONFIG_WEBHOOK_GENERIC_SECRET), url));
break;
case BuildTriggerType.github:
case BuildTriggerType.GITHUB:
triggers.add(new WebhookTrigger(BuildTriggerType.GITHUB, asString(node, BUILD_CONFIG_WEBHOOK_GITHUB_SECRET), url));
break;
case BuildTriggerType.imageChange:
case BuildTriggerType.IMAGE_CHANGE:
triggers.add(new ImageChangeTrigger(BuildTriggerType.IMAGE_CHANGE,
asString(node, BUILD_CONFIG_IMAGECHANGE_IMAGE),
Expand All @@ -123,23 +110,20 @@ public void addBuildTrigger(IBuildTrigger trigger) {
ModelNode triggers = get(BUILDCONFIG_TRIGGERS);
ModelNode triggerNode = triggers.add();
switch(trigger.getType()) {
case BuildTriggerType.generic:
case BuildTriggerType.GENERIC:
if(!(trigger instanceof IWebhookTrigger)) {
throw new IllegalArgumentException("IBuildTrigger of type generic does not implement IWebhookTrigger");
}
IWebhookTrigger generic = (IWebhookTrigger)trigger;
triggerNode.get(getPath(BUILD_CONFIG_WEBHOOK_GENERIC_SECRET)).set(generic.getSecret());
break;
case BuildTriggerType.github:
case BuildTriggerType.GITHUB:
if(!(trigger instanceof IWebhookTrigger)) {
throw new IllegalArgumentException("IBuildTrigger of type github does not implement IWebhookTrigger");
}
IWebhookTrigger github = (IWebhookTrigger)trigger;
triggerNode.get(getPath(BUILD_CONFIG_WEBHOOK_GITHUB_SECRET)).set(github.getSecret());
break;
case BuildTriggerType.imageChange:
case BuildTriggerType.IMAGE_CHANGE:{
if(!(trigger instanceof IImageChangeTrigger)) {
throw new IllegalArgumentException("IBuildTrigger of type imageChange does not implement IImageChangeTrigger");
Expand Down Expand Up @@ -211,22 +195,6 @@ public void setBuildStrategy(IBuildStrategy strategy) {
setEnvMap(BUILDCONFIG_CUSTOM_ENV, custom.getEnvironmentVariables());
}
break;
case BuildStrategyType.STI:
if ( !(strategy instanceof ISTIBuildStrategy)) {
throw new IllegalArgumentException("IBuildStrategy of type Custom does not implement ISTIBuildStrategy");
}
ISTIBuildStrategy sti = (ISTIBuildStrategy)strategy;
if(sti.getImage() != null) {
set(BUILDCONFIG_STI_IMAGE, sti.getImage().toString());
}
if(sti.getScriptsLocation() != null) {
set(BUILDCONFIG_STI_SCRIPTS, sti.getScriptsLocation());
}
set(BUILDCONFIG_STI_INCREMENTAL, sti.incremental());
if(sti.getEnvironmentVariables() != null) {
setEnvMap(BUILDCONFIG_STI_ENV, sti.getEnvironmentVariables());
}
break;
case BuildStrategyType.SOURCE:
ISourceBuildStrategy source = (ISourceBuildStrategy) strategy;
get(SOURCE_STRATEGY).set(ModelNode.fromJSONString(source.toString()));
Expand All @@ -248,13 +216,6 @@ public void setBuildStrategy(IBuildStrategy strategy) {

set(BUILDCONFIG_TYPE, strategy.getType());
}

public void setOutput(DockerImageURI imageUri){
//FIXME
// ModelNode output = getNode().get(new String []{"parameters","output"});
// output.get("imageTag").set(imageUri.getUriWithoutHost());
// output.get("registry").set(imageUri.getRepositoryHost());
}

@SuppressWarnings("unchecked")
@Override
Expand All @@ -266,7 +227,6 @@ public <T extends IBuildStrategy> T getBuildStrategy() {
asBoolean(BUILDCONFIG_CUSTOM_EXPOSEDOCKERSOCKET),
getEnvMap(BUILDCONFIG_CUSTOM_ENV)
);
case BuildStrategyType.STI:
case BuildStrategyType.SOURCE:
return (T) new SourceBuildStrategy(get(SOURCE_STRATEGY), getPropertyKeys());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public Map<String, String> getLabels() {
}

/*---------- utility methods ------*/
protected boolean has(String key) {
return node.has(getPath(key));
}

protected ModelNode get(String key){
return get(node, key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@
******************************************************************************/
package com.openshift.internal.restclient.model.build;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.jboss.dmr.ModelNode;

import com.openshift.internal.restclient.model.BuildConfig;
import com.openshift.internal.util.JBossDmrExtentions;
import com.openshift.restclient.IClient;
import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.images.DockerImageURI;
import com.openshift.restclient.model.IBuildConfig;
import com.openshift.restclient.model.IEnvironmentVariable;
import com.openshift.restclient.model.IObjectReference;
import com.openshift.restclient.model.build.BuildTriggerType;
import com.openshift.restclient.model.build.IBuildConfigBuilder;


/**
* Impl of a builder to create buildconfigs
* @author jeff.cantrill
*
*/
public class BuildConfigBuilder implements IBuildConfigBuilder {

private SourceStrategyBuilder sourceStrategyBuilder;
Expand Down Expand Up @@ -77,11 +81,13 @@ public IBuildConfig build() {
bc.setBuildSource(gitSourceBuilder.build());
}


//TODO move into bc
ModelNode node = bc.getNode();
JBossDmrExtentions.set(node, Collections.emptyMap(), "spec.output.to.kind", ResourceKind.IMAGE_STREAM_TAG);
JBossDmrExtentions.set(node, Collections.emptyMap(), "spec.output.to.name", imageStreamTagOutput);
DockerImageURI uri = new DockerImageURI(imageStreamTagOutput);
IObjectReference outRef = bc.getBuildOutputReference();
outRef.setKind(ResourceKind.IMAGE_STREAM_TAG);
outRef.setName(uri.getNameAndTag());
if(StringUtils.isNotBlank(uri.getUserName())) {
outRef.setNamespace(uri.getUserName());
}

bc.addBuildTrigger(new WebhookTrigger(BuildTriggerType.GENERIC, UUID.randomUUID().toString(), null));
if(buildOnImageChange) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface IBuildConfig extends IResource{
/**
* To defines an optional location to push the output of this build to.
* Kind must be one of 'ImageStreamTag' or 'DockerImage'.
* @return
* @return a mutable object reference
*/
IObjectReference getBuildOutputReference();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ public interface IObjectReference {
* @return
*/
String getKind();

/**
* The obj ref kind
* @param kind
*/
void setKind(String kind);

/**
* returns the api version of this resource
* @return
*/
String getApiVersion();

/**
* returns the resource version of this resource
* @return
Expand All @@ -41,12 +47,24 @@ public interface IObjectReference {
* @return
*/
String getName();

/**
* The name of the obj ref
* @param name
*/
void setName(String name);

/**
* Returns the scope of this resource
* @return
*/
String getNamespace();

/**
* The namespace for the object ref
* @param namespace
*/
void setNamespace(String namespace);

String getFieldPath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.openshift.restclient.model.IBuildConfig;
import com.openshift.restclient.model.IEnvironmentVariable;
import com.openshift.restclient.model.IResourceBuilder;
import com.openshift.restclient.model.build.IBuildConfigBuilder.IGitSourceBuilder;

public interface IBuildConfigBuilder extends IResourceBuilder<IBuildConfig, IBuildConfigBuilder>, ICapability {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testBuild() {
.fromImageStreamTag("builder:latest")
.inNamespace("other")
.end()
.toImageStreamTag("target:latest")
.toImageStreamTag("foo/target:latest")
.build();

List<String> triggerTypes = Arrays.asList(BuildTriggerType.CONFIG_CHANGE,
Expand All @@ -96,6 +96,7 @@ public void testBuild() {
IObjectReference out = bc.getBuildOutputReference();
assertEquals(ResourceKind.IMAGE_STREAM_TAG, out.getKind());
assertEquals("target:latest", out.getName());
assertEquals("foo", out.getNamespace());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import static org.junit.Assert.*;

import org.jboss.dmr.ModelNode;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;

import com.openshift.internal.restclient.model.ObjectReference;
import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.model.IObjectReference;
import com.openshift.restclient.utils.Samples;

Expand All @@ -23,26 +24,49 @@
*/
public class ObjectRefTest {

private static IObjectReference objRef;
private static final String CONTENT = Samples.V1_OBJECT_REF.getContentAsString();
private IObjectReference objRef;
private ModelNode node;

@BeforeClass
public static void setup(){
ModelNode node = ModelNode.fromJSONString(Samples.V1_OBJECT_REF.getContentAsString());
@Before
public void setup(){
node = ModelNode.fromJSONString(CONTENT);
objRef = new ObjectReference(node);
}

@Test
public void testGetKind(){
assertEquals("ServiceAccount", objRef.getKind());
}

@Test
public void testSetKind() {
objRef.setKind(ResourceKind.BUILD);
assertEquals(ResourceKind.BUILD, new ObjectReference(node.clone()).getKind());
}

@Test
public void testGetNamespace(){
assertEquals("test", objRef.getNamespace());
}

@Test
public void testSetNamespace() {
objRef.setNamespace("newnamespace");
assertEquals("newnamespace", new ObjectReference(node.clone()).getNamespace());
}

@Test
public void testGetName(){
assertEquals("builder", objRef.getName());
}

@Test
public void testSetName() {
objRef.setName("newname");
assertEquals("newname", new ObjectReference(node.clone()).getName());
}

@Test
public void testGetUID(){
assertEquals("ce20b132-7986-11e5-b1e5-080027bdffff", objRef.getUID());
Expand Down