Skip to content

Commit

Permalink
Fixes fabric8io#1177 Minor changes to ImageTrigger generation
Browse files Browse the repository at this point in the history
Added fabric8.openshift.setDeploymentTriggerAutomatic flag which would
be able to enable/disable automatic deployments.
  • Loading branch information
rohanKanojia committed Mar 6, 2018
1 parent d776e16 commit d03d373
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
* Fix 1130: Added flag fabric8.openshift.trimImageInContainerSpec which would set the container image reference to "", this is done to handle weird
behavior of Openshift 3.7 in which subsequent rollouts lead to ImagePullErr.
* Feature 1174: ImageStreams use local lookup policy by default to simplify usage of Deployment or StatefulSet resources on Openshift
* Fix 1177: Added flag fabric8.openshift.enableAutomaticTrigger which would be able to enable/disable automatic deployments whenever there is new image
generated.

###3.5.34
* Feature 1003: Added suspend option to remote debugging
Expand Down
5 changes: 5 additions & 0 deletions doc/src/main/asciidoc/inc/goals/build/_fabric8-resource.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,8 @@ spec:
----

In case both the label in the resource fragment and also the flag is set then precedence will be given to flag. Like you have set the label to true and flag to false then it will not generate route.yml because flag is set to false.

| *fabric8.openshift.enableAutomaticTrigger*
| If the value is set to `false` then automatic deployments would be disabled.
| true
|===
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public DeploymentConfigOpenShiftConverter(Long openshiftDeployTimeoutSeconds) {
}

@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
if (item instanceof DeploymentConfig) {
DeploymentConfig resource = (DeploymentConfig) item;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public DeploymentOpenShiftConverter(PlatformMode mode, Long openshiftDeployTimeo
}

@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
Deployment resource = (Deployment) item;
DeploymentConfigBuilder builder = new DeploymentConfigBuilder();
builder.withMetadata(resource.getMetadata());
Expand Down Expand Up @@ -107,7 +107,9 @@ public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
}

// lets add a default trigger so that its triggered when we change its config
specBuilder.addNewTrigger().withType("ConfigChange").endTrigger();
if(enableAutomaticTrigger) {
specBuilder.addNewTrigger().withType("ConfigChange").endTrigger();
}

// add a new image change trigger for the build stream
if (containerToImageMap.size() != 0) {
Expand All @@ -119,10 +121,11 @@ public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
specBuilder.addNewTrigger()
.withType("ImageChange")
.withNewImageChangeParams()
.withAutomatic(true)
.withAutomatic(enableAutomaticTrigger)
.withNewFrom()
.withKind("ImageStreamTag")
.withName(image.getSimpleName() + ":" + tag)
.withNamespace(image.getUser())
.endFrom()
.withContainerNames(containerName)
.endImageChangeParams()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
*/
public interface KubernetesToOpenShiftConverter {

HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec);
HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public class NamespaceOpenShiftConverter implements KubernetesToOpenShiftConverter {
@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
return new ProjectRequestBuilder().withMetadata(item.getMetadata()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class ReplicSetOpenShiftConverter implements KubernetesToOpenShiftConverter {
@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
ReplicaSet resource = (ReplicaSet) item;
ReplicationControllerBuilder builder = new ReplicationControllerBuilder();
builder.withMetadata(resource.getMetadata());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ public class ResourceMojo extends AbstractResourceMojo {
@Parameter(property = "fabric8.openshift.generateRoute", defaultValue = "true")
private Boolean generateRoute;

@Parameter(property = "fabric8.openshift.enableAutomaticTrigger", defaultValue = "true")
private Boolean enableAutomaticTrigger;

@Parameter(property = "kompose.dir", defaultValue = "${user.home}/.kompose/bin")
private File komposeBinDir;

Expand Down Expand Up @@ -758,7 +761,7 @@ private HasMetadata convertKubernetesItemToOpenShift(HasMetadata item) {
}

KubernetesToOpenShiftConverter converter = openShiftConverters.get(item.getKind());
return converter != null ? converter.convert(item, trimImageInContainerSpec) : item;
return converter != null ? converter.convert(item, trimImageInContainerSpec, enableAutomaticTrigger) : item;
}

// ==================================================================================
Expand Down

0 comments on commit d03d373

Please sign in to comment.