Skip to content

Commit

Permalink
Fixes fabric8io#1130 Application redeployment is getting failed on Op…
Browse files Browse the repository at this point in the history
…enShift v3.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.

Backporting changes to accomodate:
OSFUSE-718: [OSO][OCP 3.7] f-m-p redeployments failing to deploy
  • Loading branch information
rohanKanojia authored and valdar committed Feb 16, 2018
1 parent 62816bc commit 18d76ff
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
14 changes: 14 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 @@ -77,3 +77,17 @@ The following subelements are possible for `<labels>` and `<annotations>` :
| *service*
| Labels and annotations applied to `Service` objects.
|===

[[resource-validation]]
=== Resource Validation
Resource goal also validates the generated resource descriptors using API specification of https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json[Kubernetes] and https://raw.githubusercontent.com/openshift/origin/master/api/swagger-spec/openshift-openapi-spec.json[OpenShift].

.Validation Configuration
[cols="1,6,1"]
|===
| Configuration | Description | Default

| *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 @@ -48,7 +48,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 @@ -111,6 +111,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 @@ -224,6 +224,19 @@ public class ResourceMojo extends AbstractResourceMojo {
@Parameter(property = "fabric8.openshift.deployTimeoutSeconds")
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;

// Access for creating OpenShift binary builds
private ClusterAccess clusterAccess;

Expand Down Expand Up @@ -704,7 +717,7 @@ private HasMetadata convertKubernetesItemToOpenShift(HasMetadata item) {
return dependencyResource;
}
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 18d76ff

Please sign in to comment.