-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[issue 80] - Adding the EAP 7 legacy s2i template-based build provisi…
…oner
- Loading branch information
Showing
7 changed files
with
251 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...org/jboss/intersmash/tools/provision/openshift/Eap7LegacyS2iBuildTemplateProvisioner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.jboss.intersmash.tools.provision.openshift; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
import org.jboss.intersmash.tools.application.openshift.Eap7LegacyS2iBuildTemplateApplication; | ||
import org.slf4j.event.Level; | ||
|
||
import cz.xtf.core.event.helpers.EventHelper; | ||
import cz.xtf.core.openshift.OpenShiftWaiters; | ||
import cz.xtf.core.waiting.failfast.FailFastCheck; | ||
import io.fabric8.kubernetes.api.model.KubernetesList; | ||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.openshift.api.model.BuildConfig; | ||
import io.fabric8.openshift.api.model.Template; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Provisioner used process and deploy eap-s2i-build template to OpenShift Container Platform cluster. | ||
* | ||
* @see Eap7LegacyS2iBuildTemplateApplication | ||
*/ | ||
@Slf4j | ||
public class Eap7LegacyS2iBuildTemplateProvisioner implements OpenShiftProvisioner<Eap7LegacyS2iBuildTemplateApplication> { | ||
// we can parametrize this one once required, but its location should be static | ||
private String EAP_S2I_BUILD = "https://raw.githubusercontent.com/jboss-container-images/jboss-eap-openshift-templates/master/eap-s2i-build.yaml"; | ||
private KubernetesList deployedResources; | ||
private Eap7LegacyS2iBuildTemplateApplication application; | ||
private FailFastCheck ffCheck = () -> false; | ||
private Template template; | ||
|
||
public Eap7LegacyS2iBuildTemplateProvisioner(Eap7LegacyS2iBuildTemplateApplication application) { | ||
this.application = application; | ||
} | ||
|
||
@Override | ||
public Eap7LegacyS2iBuildTemplateApplication getApplication() { | ||
return application; | ||
} | ||
|
||
@Override | ||
public void deploy() { | ||
ffCheck = FailFastUtils.getFailFastCheck(EventHelper.timeOfLastEventBMOrTestNamespaceOrEpoch(), | ||
application.getName()); | ||
|
||
if (application.getParameters().getOrDefault("APPLICATION_IMAGE", "null") != application.getName()) { | ||
throw new IllegalArgumentException("APPLICATION_IMAGE template parameters has to match the application name!"); | ||
} | ||
try { | ||
template = openShift.templates().load(new URL(EAP_S2I_BUILD)).get(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to load eap-s2i-build template from " + EAP_S2I_BUILD, e); | ||
} | ||
template.setApiVersion("template.openshift.io/v1"); | ||
openShift.createTemplate(template); | ||
deployedResources = openShift.processTemplate(template.getMetadata().getName(), | ||
application.getParameters()); | ||
// add additional environment variables to the build config resources | ||
deployedResources.getItems().stream() | ||
.filter(hasMetadata -> hasMetadata.getKind().equals(BuildConfig.class.getSimpleName())) | ||
.forEach(hasMetadata -> setEnvToBuildConfig((BuildConfig) hasMetadata)); | ||
openShift.createResources(deployedResources); | ||
|
||
// two build configs has to be built (builder/runtime) in order to proceed | ||
waitForBuilds(); | ||
} | ||
|
||
private void setEnvToBuildConfig(BuildConfig buildConfig) { | ||
// Update Git based build config | ||
if (buildConfig.getSpec().getStrategy().getSourceStrategy() != null) { | ||
if (buildConfig.getSpec().getStrategy().getSourceStrategy().getEnv() == null) { | ||
buildConfig.getSpec().getStrategy().getSourceStrategy().setEnv(application.getEnvVars()); | ||
} else { | ||
buildConfig.getSpec().getStrategy().getSourceStrategy().getEnv().addAll(application.getEnvVars()); | ||
} | ||
} | ||
// Update dockerile based build config | ||
if (buildConfig.getSpec().getStrategy().getDockerStrategy() != null) { | ||
if (buildConfig.getSpec().getStrategy().getDockerStrategy().getEnv() == null) { | ||
buildConfig.getSpec().getStrategy().getDockerStrategy().setEnv(application.getEnvVars()); | ||
} else { | ||
buildConfig.getSpec().getStrategy().getDockerStrategy().getEnv().addAll(application.getEnvVars()); | ||
} | ||
} | ||
} | ||
|
||
private void waitForBuilds() { | ||
OpenShiftWaiters.get(openShift, ffCheck).hasBuildCompleted(application.getName() + "-build-artifacts") | ||
.level(Level.DEBUG) | ||
.waitFor(); | ||
OpenShiftWaiters.get(openShift, ffCheck).hasBuildCompleted(application.getName()) | ||
.level(Level.DEBUG) | ||
.waitFor(); | ||
} | ||
|
||
@Override | ||
public void undeploy() { | ||
openShift.deleteResources(deployedResources); | ||
openShift.deleteTemplate(template); | ||
} | ||
|
||
@Override | ||
public URL getURL() { | ||
throw new UnsupportedOperationException("No route for eap-s2i-build template instance."); | ||
} | ||
|
||
@Override | ||
public List<Pod> getPods() { | ||
throw new UnsupportedOperationException( | ||
"eap-s2i-build does not provide any running pods - all pods are completed once builds are done."); | ||
} | ||
|
||
@Override | ||
public void scale(int replicas, boolean wait) { | ||
throw new UnsupportedOperationException("eap-s2i-build template is not suppose to be scaled - no running pods."); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ss/intersmash/tools/provision/openshift/Eap7LegacyS2iBuildTemplateProvisionerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.jboss.intersmash.tools.provision.openshift; | ||
|
||
import org.jboss.intersmash.tools.application.Application; | ||
import org.jboss.intersmash.tools.application.openshift.Eap7LegacyS2iBuildTemplateApplication; | ||
import org.jboss.intersmash.tools.provision.ProvisionerFactory; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class Eap7LegacyS2iBuildTemplateProvisionerFactory implements ProvisionerFactory<Eap7LegacyS2iBuildTemplateProvisioner> { | ||
|
||
@Override | ||
public Eap7LegacyS2iBuildTemplateProvisioner getProvisioner(Application application) { | ||
if (Eap7LegacyS2iBuildTemplateApplication.class.isAssignableFrom(application.getClass())) | ||
return new Eap7LegacyS2iBuildTemplateProvisioner((Eap7LegacyS2iBuildTemplateApplication) application); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters