use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class DependencyEnricher method processArtifactSetResources.
private void processArtifactSetResources(Set<URL> artifactSet, Function<List<HasMetadata>, Void> function) {
for (URL url : artifactSet) {
try {
InputStream is = url.openStream();
if (is != null) {
log.debug("Processing Kubernetes YAML in at: %s", url);
KubernetesList resources = new ObjectMapper(new YAMLFactory()).readValue(is, KubernetesList.class);
List<HasMetadata> items = notNullList(resources.getItems());
if (items.size() == 0 && Objects.equals("Template", resources.getKind())) {
is = url.openStream();
Template template = new ObjectMapper(new YAMLFactory()).readValue(is, Template.class);
if (template != null) {
items.add(template);
}
}
for (HasMetadata item : items) {
KubernetesResourceUtil.setSourceUrlAnnotationIfNotSet(item, url.toString());
log.debug(" found %s %s", getKind(item), KubernetesHelper.getName(item));
}
function.apply(items);
}
} catch (IOException e) {
getLog().debug("Skipping %s: %s", url, e);
}
}
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class AbstractArtifactSearchMojo method findManifestValue.
protected static <T> T findManifestValue(Object manifest, Function<HasMetadata, T> function) {
if (manifest instanceof HasMetadata) {
HasMetadata metadata = (HasMetadata) manifest;
T answer = function.apply(metadata);
if (answer != null)
return answer;
}
if (manifest instanceof KubernetesList) {
KubernetesList list = (KubernetesList) manifest;
return findManifestValueFromList(list.getItems(), function);
}
if (manifest instanceof Template) {
Template template = (Template) manifest;
return findManifestValueFromList(template.getObjects(), function);
}
return null;
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class DockerImageWatcher method updateImageName.
private boolean updateImageName(HasMetadata entity, PodTemplateSpec template, String imagePrefix, String imageName) {
boolean answer = false;
PodSpec spec = template.getSpec();
if (spec != null) {
List<Container> containers = spec.getContainers();
if (containers != null) {
for (Container container : containers) {
String image = container.getImage();
if (image != null && image.startsWith(imagePrefix)) {
container.setImage(imageName);
log.info("Updating " + getKind(entity) + " " + KubernetesHelper.getName(entity) + " to use image: " + imageName);
answer = true;
}
}
}
}
return answer;
}
use of io.fabric8.openshift.api.model.Template in project fabric8 by fabric8io.
the class Controller method doCreateTemplate.
protected void doCreateTemplate(Template entity, String namespace, String sourceName) {
OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.TEMPLATE)) {
LOG.info("Creating a Template from " + sourceName + " namespace " + namespace + " name " + getName(entity));
try {
Object answer = openShiftClient.templates().inNamespace(namespace).create(entity);
logGeneratedEntity("Created Template: ", namespace, entity, answer);
} catch (Exception e) {
onApplyError("Failed to Template entity from " + sourceName + ". " + e + ". " + entity, e);
}
}
}
use of io.fabric8.openshift.api.model.Template in project fabric8 by fabric8io.
the class Controller method installTemplate.
/**
* Installs the template into the namespace without processing it
*/
public void installTemplate(Template entity, String sourceName) {
OpenShiftClient openShiftClient = getOpenShiftClientOrNull();
if (openShiftClient == null || !openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.TEMPLATE)) {
// lets not install the template on Kubernetes!
return;
}
if (!isProcessTemplatesLocally()) {
String namespace = getNamespace();
String id = getName(entity);
Objects.notNull(id, "No name for " + entity + " " + sourceName);
Template old = openShiftClient.templates().inNamespace(namespace).withName(id).get();
if (isRunning(old)) {
if (UserConfigurationCompare.configEqual(entity, old)) {
LOG.info("Template has not changed so not doing anything");
} else {
boolean recreateMode = isRecreateMode();
// TODO seems you can't update templates right now
recreateMode = true;
if (recreateMode) {
openShiftClient.templates().inNamespace(namespace).withName(id).delete();
doCreateTemplate(entity, namespace, sourceName);
} else {
LOG.info("Updating a Template from " + sourceName);
try {
Object answer = openShiftClient.templates().inNamespace(namespace).withName(id).replace(entity);
LOG.info("Updated Template: " + answer);
} catch (Exception e) {
onApplyError("Failed to update Template from " + sourceName + ". " + e + ". " + entity, e);
}
}
}
} else {
if (!isAllowCreate()) {
LOG.warn("Creation disabled so not creating a Template from " + sourceName + " namespace " + namespace + " name " + getName(entity));
} else {
doCreateTemplate(entity, namespace, sourceName);
}
}
}
}
Aggregations