Search in sources :

Example 1 with TagEvent

use of io.fabric8.openshift.api.model.TagEvent 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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TagEvent(io.fabric8.openshift.api.model.TagEvent) ImageStream(io.fabric8.openshift.api.model.ImageStream) NamedTagEventList(io.fabric8.openshift.api.model.NamedTagEventList) ArrayList(java.util.ArrayList) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) NamedTagEventList(io.fabric8.openshift.api.model.NamedTagEventList) List(java.util.List) ImageStreamStatus(io.fabric8.openshift.api.model.ImageStreamStatus)

Example 2 with TagEvent

use of io.fabric8.openshift.api.model.TagEvent 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();
}
Also used : ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) TagEvent(io.fabric8.openshift.api.model.TagEvent) NamedTagEventList(io.fabric8.openshift.api.model.NamedTagEventList)

Example 3 with TagEvent

use of io.fabric8.openshift.api.model.TagEvent in project jkube by eclipse.

the class ImageStreamServiceTest method should_return_newer_tag.

@Test
public void should_return_newer_tag() {
    // GIVEN
    ImageStreamService service = new ImageStreamService(client, "default", log);
    TagEvent oldTag = new TagEvent("2018-03-09T03:27:05Z\n", null, null, null);
    TagEvent latestTag = new TagEvent("2018-03-09T03:28:05Z\n", null, null, null);
    // WHEN
    TagEvent resultedTag = service.newerTag(oldTag, latestTag);
    // THEN
    Assert.assertEquals(latestTag, resultedTag);
}
Also used : TagEvent(io.fabric8.openshift.api.model.TagEvent) Test(org.junit.Test)

Example 4 with TagEvent

use of io.fabric8.openshift.api.model.TagEvent in project fabric8-maven-plugin by fabric8io.

the class ImageStreamServiceTest method should_return_newer_tag.

@Test
public void should_return_newer_tag() throws Exception {
    // GIVEN
    ImageStreamService service = new ImageStreamService(client, log);
    TagEvent oldTag = new TagEvent("2018-03-09T03:27:05Z\n", null, null, null);
    TagEvent latestTag = new TagEvent("2018-03-09T03:28:05Z\n", null, null, null);
    // WHEN
    TagEvent resultedTag = service.newerTag(oldTag, latestTag);
    // THEN
    Assert.assertEquals(latestTag, resultedTag);
}
Also used : TagEvent(io.fabric8.openshift.api.model.TagEvent) Test(org.junit.Test)

Example 5 with TagEvent

use of io.fabric8.openshift.api.model.TagEvent in project fabric8-maven-plugin by fabric8io.

the class ImageStreamServiceTest method should_return_first_tag.

@Test
public void should_return_first_tag() throws Exception {
    // GIVEN
    ImageStreamService service = new ImageStreamService(client, log);
    TagEvent first = new TagEvent("2018-03-09T03:27:05Z\n", null, null, null);
    TagEvent latestTag = null;
    // WHEN
    TagEvent resultedTag = service.newerTag(first, latestTag);
    // THEN
    Assert.assertEquals(first, resultedTag);
}
Also used : TagEvent(io.fabric8.openshift.api.model.TagEvent) Test(org.junit.Test)

Aggregations

TagEvent (io.fabric8.openshift.api.model.TagEvent)7 Test (org.junit.Test)4 NamedTagEventList (io.fabric8.openshift.api.model.NamedTagEventList)3 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)2 ImageStream (io.fabric8.openshift.api.model.ImageStream)2 ImageStreamStatus (io.fabric8.openshift.api.model.ImageStreamStatus)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ImageStreamBuilder (io.fabric8.openshift.api.model.ImageStreamBuilder)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1