Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Fixes #1130 Application redeployment is getting failed on OpenShift v…
Browse files Browse the repository at this point in the history
…3.7.0

+ Added a workaround to deal with ImageTriggers.
+ Added flag fabric8.openshift.trimImageInContainerSpec which would trim
  image in container spec
+ Updated documentation related to flag.
  • Loading branch information
rohanKanojia committed Feb 10, 2018
1 parent e685fa3 commit fd9756f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ We use semantic versioning in some slight variation until our feature set has st
After this we will switch probably to real [Semantic Versioning 2.0.0](http://semver.org/)


###3.5.35
* 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.

###3.5.34
* Feature 1003: Added suspend option to remote debugging
Expand Down
4 changes: 4 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 @@ -181,4 +181,8 @@ Resource goal also validates the generated resource descriptors using API specif
| *fabric8.build.switchToDeployment*
| If value is set to `true` then fabric8-maven-plugin would switch to Deployments rather than DeploymentConfig when not using ImageStreams on Openshift.
| false

| *fabric8.openshift.trimImageInContainerSpec*
| If value is set to `true` then it 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
| false
|===
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) {
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
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) {
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
Deployment resource = (Deployment) item;
DeploymentConfigBuilder builder = new DeploymentConfigBuilder();
builder.withMetadata(resource.getMetadata());
Expand Down Expand Up @@ -129,6 +129,26 @@ public HasMetadata convert(HasMetadata item) {
.endTrigger();
}
}
if(trimImageInContainerSpec) {
/*
* In Openshift 3.7, update to container image is automatically triggering redeployments
* and those subsequent rollouts lead to RC complaining about a missing image reference.
*
* See this : https://github.com/openshift/origin/issues/18406#issuecomment-364090247
*
* this the time it gets fixed. Do this:
* Since we're using ImageTrigger here, set container image to " ". If there is any config
* change never set to image else than " "; so doing oc apply/rollouts won't be creating
* re-deployments again and again.
*
*/
List<Container> containers = template.getSpec().getContainers();
for (Integer nIndex = 0; nIndex < containers.size(); nIndex++) {
containers.get(nIndex).setImage(" ");
}
template.getSpec().setContainers(containers);
specBuilder.withTemplate(template);
}
}

specBuilder.endSpec();
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);
HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec);

}
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) {
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
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) {
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
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 @@ -243,6 +243,19 @@ public class ResourceMojo extends AbstractResourceMojo {
@Parameter(property = "fabric8.openshift.deployTimeoutSeconds", defaultValue = "3600")
private Long openshiftDeployTimeoutSeconds;

/**
* If set to true it 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
*
* Please see discussion at
* <ul>
* <li>https://github.com/openshift/origin/issues/18406</li>
* <li>https://github.com/fabric8io/fabric8-maven-plugin/issues/1130</li>
* </ul>
*/
@Parameter(property = "fabric8.openshift.trimImageInContainerSpec", defaultValue = "false")
private Boolean trimImageInContainerSpec;

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

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

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

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

0 comments on commit fd9756f

Please sign in to comment.