use of io.fabric8.openshift.api.model.NamedTagEventList in project fabric8-maven-plugin by fabric8io.
the class ImageStreamService method findTagSha.
private String findTagSha(OpenShiftClient client, String imageStreamName, String namespace) throws MojoExecutionException {
ImageStream currentImageStream = null;
for (int i = 0; i < IMAGE_STREAM_TAG_RETRIES; i++) {
if (i > 0) {
log.info("Retrying to find tag on ImageStream %s", imageStreamName);
try {
Thread.sleep(IMAGE_STREAM_TAG_RETRY_TIMEOUT_IN_MILLIS);
} catch (InterruptedException e) {
log.debug("interrupted", e);
}
}
currentImageStream = client.imageStreams().withName(imageStreamName).get();
if (currentImageStream == null) {
continue;
}
ImageStreamStatus status = currentImageStream.getStatus();
if (status == null) {
continue;
}
List<NamedTagEventList> tags = status.getTags();
if (tags == null || tags.isEmpty()) {
continue;
}
// Iterate all imagestream tags and get the latest one by 'created' attribute
TagEvent latestTag = null;
TAG_EVENT_LIST: for (NamedTagEventList list : tags) {
List<TagEvent> items = list.getItems();
if (items == null || items.isEmpty()) {
continue TAG_EVENT_LIST;
}
for (TagEvent tag : items) {
latestTag = latestTag == null ? tag : newerTag(tag, latestTag);
}
}
if (latestTag != null && StringUtils.isNotBlank(latestTag.getImage())) {
String image = latestTag.getImage();
log.info("Found tag on ImageStream " + imageStreamName + " tag: " + image);
return image;
}
}
// No image found, even after several retries:
if (currentImageStream == null) {
throw new MojoExecutionException("Could not find a current ImageStream with name " + imageStreamName + " in namespace " + namespace);
} else {
throw new MojoExecutionException("Could not find a tag in the ImageStream " + imageStreamName);
}
}
use of io.fabric8.openshift.api.model.NamedTagEventList in project fabric8-maven-plugin by fabric8io.
the class ImageStreamServiceTest method lookupImageStream.
private ImageStream lookupImageStream(String sha) {
NamedTagEventList list = new NamedTagEventList();
TagEvent tag = new TagEvent();
tag.setImage(sha);
list.setItems(new ArrayList<TagEvent>(Arrays.asList(tag)));
return new ImageStreamBuilder().withNewStatus().addToTags(list).endStatus().build();
}
use of io.fabric8.openshift.api.model.NamedTagEventList in project jkube by eclipse.
the class ImageStreamService method findTagSha.
private String findTagSha(OpenShiftClient client, String imageStreamName, String namespace) {
ImageStream currentImageStream = null;
for (int i = 0; i < IMAGE_STREAM_TAG_RETRIES; i++) {
if (i > 0) {
log.info("Retrying to find tag on ImageStream %s", imageStreamName);
try {
Thread.sleep(IMAGE_STREAM_TAG_RETRY_TIMEOUT_IN_MILLIS);
} catch (InterruptedException e) {
log.debug("interrupted", e);
Thread.currentThread().interrupt();
}
}
currentImageStream = client.imageStreams().inNamespace(namespace).withName(imageStreamName).get();
if (currentImageStream == null) {
continue;
}
ImageStreamStatus status = currentImageStream.getStatus();
if (status == null) {
continue;
}
List<NamedTagEventList> tags = status.getTags();
if (tags == null || tags.isEmpty()) {
continue;
}
// Iterate all imagestream tags and get the latest one by 'created' attribute
TagEvent latestTag = null;
TAG_EVENT_LIST: for (NamedTagEventList list : tags) {
List<TagEvent> items = list.getItems();
if (items == null || items.isEmpty()) {
continue TAG_EVENT_LIST;
}
for (TagEvent tag : items) {
latestTag = latestTag == null ? tag : newerTag(tag, latestTag);
}
}
if (latestTag != null && StringUtils.isNotBlank(latestTag.getImage())) {
String image = latestTag.getImage();
log.info("Found tag on ImageStream " + imageStreamName + " tag: " + image);
return image;
}
}
// No image found, even after several retries:
if (currentImageStream == null) {
throw new IllegalStateException("Could not find a current ImageStream with name " + imageStreamName + " in namespace " + namespace);
} else {
throw new IllegalStateException("Could not find a tag in the ImageStream " + imageStreamName);
}
}
Aggregations