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

Commit af0e677

Browse files
author
hrishin
authored
Merge pull request #1176 from rohanKanojia/issue1130
Fixes #1130 Application redeployment is getting failed on OpenShift v3.7.0
2 parents 690bd62 + fd9756f commit af0e677

8 files changed

+46
-6
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ We use semantic versioning in some slight variation until our feature set has st
1111
After this we will switch probably to real [Semantic Versioning 2.0.0](http://semver.org/)
1212

1313

14+
###3.5.35
15+
* Fix 1130: Added flag fabric8.openshift.trimImageInContainerSpec which would set the container image reference to "", this is done to handle weird
16+
behavior of Openshift 3.7 in which subsequent rollouts lead to ImagePullErr.
1417

1518
###3.5.34
1619
* Feature 1003: Added suspend option to remote debugging

doc/src/main/asciidoc/inc/goals/build/_fabric8-resource.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,8 @@ Resource goal also validates the generated resource descriptors using API specif
181181
| *fabric8.build.switchToDeployment*
182182
| If value is set to `true` then fabric8-maven-plugin would switch to Deployments rather than DeploymentConfig when not using ImageStreams on Openshift.
183183
| false
184+
185+
| *fabric8.openshift.trimImageInContainerSpec*
186+
| 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
187+
| false
184188
|===

plugin/src/main/java/io/fabric8/maven/plugin/converter/DeploymentConfigOpenShiftConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public DeploymentConfigOpenShiftConverter(Long openshiftDeployTimeoutSeconds) {
4949
}
5050

5151
@Override
52-
public HasMetadata convert(HasMetadata item) {
52+
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
5353
if (item instanceof DeploymentConfig) {
5454
DeploymentConfig resource = (DeploymentConfig) item;
5555

plugin/src/main/java/io/fabric8/maven/plugin/converter/DeploymentOpenShiftConverter.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public DeploymentOpenShiftConverter(PlatformMode mode, Long openshiftDeployTimeo
5050
}
5151

5252
@Override
53-
public HasMetadata convert(HasMetadata item) {
53+
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
5454
Deployment resource = (Deployment) item;
5555
DeploymentConfigBuilder builder = new DeploymentConfigBuilder();
5656
builder.withMetadata(resource.getMetadata());
@@ -129,6 +129,26 @@ public HasMetadata convert(HasMetadata item) {
129129
.endTrigger();
130130
}
131131
}
132+
if(trimImageInContainerSpec) {
133+
/*
134+
* In Openshift 3.7, update to container image is automatically triggering redeployments
135+
* and those subsequent rollouts lead to RC complaining about a missing image reference.
136+
*
137+
* See this : https://github.com/openshift/origin/issues/18406#issuecomment-364090247
138+
*
139+
* this the time it gets fixed. Do this:
140+
* Since we're using ImageTrigger here, set container image to " ". If there is any config
141+
* change never set to image else than " "; so doing oc apply/rollouts won't be creating
142+
* re-deployments again and again.
143+
*
144+
*/
145+
List<Container> containers = template.getSpec().getContainers();
146+
for (Integer nIndex = 0; nIndex < containers.size(); nIndex++) {
147+
containers.get(nIndex).setImage(" ");
148+
}
149+
template.getSpec().setContainers(containers);
150+
specBuilder.withTemplate(template);
151+
}
132152
}
133153

134154
specBuilder.endSpec();

plugin/src/main/java/io/fabric8/maven/plugin/converter/KubernetesToOpenShiftConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
*/
2525
public interface KubernetesToOpenShiftConverter {
2626

27-
HasMetadata convert(HasMetadata item);
27+
HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec);
2828

2929
}

plugin/src/main/java/io/fabric8/maven/plugin/converter/NamespaceOpenShiftConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
public class NamespaceOpenShiftConverter implements KubernetesToOpenShiftConverter {
2626
@Override
27-
public HasMetadata convert(HasMetadata item) {
27+
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
2828
return new ProjectRequestBuilder().withMetadata(item.getMetadata()).build();
2929
}
3030
}

plugin/src/main/java/io/fabric8/maven/plugin/converter/ReplicSetOpenShiftConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
public class ReplicSetOpenShiftConverter implements KubernetesToOpenShiftConverter {
3434
@Override
35-
public HasMetadata convert(HasMetadata item) {
35+
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec) {
3636
ReplicaSet resource = (ReplicaSet) item;
3737
ReplicationControllerBuilder builder = new ReplicationControllerBuilder();
3838
builder.withMetadata(resource.getMetadata());

plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ public class ResourceMojo extends AbstractResourceMojo {
243243
@Parameter(property = "fabric8.openshift.deployTimeoutSeconds", defaultValue = "3600")
244244
private Long openshiftDeployTimeoutSeconds;
245245

246+
/**
247+
* If set to true it would set the container image reference to "", this is done to handle weird
248+
* behavior of Openshift 3.7 in which subsequent rollouts lead to ImagePullErr
249+
*
250+
* Please see discussion at
251+
* <ul>
252+
* <li>https://github.com/openshift/origin/issues/18406</li>
253+
* <li>https://github.com/fabric8io/fabric8-maven-plugin/issues/1130</li>
254+
* </ul>
255+
*/
256+
@Parameter(property = "fabric8.openshift.trimImageInContainerSpec", defaultValue = "false")
257+
private Boolean trimImageInContainerSpec;
258+
246259
@Parameter(property = "kompose.dir", defaultValue = "${user.home}/.kompose/bin")
247260
private File komposeBinDir;
248261

@@ -744,7 +757,7 @@ private HasMetadata convertKubernetesItemToOpenShift(HasMetadata item) {
744757
}
745758

746759
KubernetesToOpenShiftConverter converter = openShiftConverters.get(item.getKind());
747-
return converter != null ? converter.convert(item) : item;
760+
return converter != null ? converter.convert(item, trimImageInContainerSpec) : item;
748761
}
749762

750763
// ==================================================================================

0 commit comments

Comments
 (0)