Search in sources :

Example 41 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.

the class ImageStreamServiceTest method simple.

@Test
public void simple() throws IOException, MojoExecutionException {
    ImageStreamService service = new ImageStreamService(client, log);
    final ImageStream lookedUpIs = lookupImageStream("ab12cd");
    setupClientMock(lookedUpIs, "test");
    ImageName name = new ImageName("test:1.0");
    File target = File.createTempFile("ImageStreamServiceTest", ".yml");
    service.appendImageStreamResource(name, target);
    assertTrue(target.exists());
    Map result = readImageStreamDescriptor(target);
    Yaml yaml;
    System.out.println(result.toString());
    assertNotNull(result);
    List<Map> items = getItemsList(result);
    assertEquals(1, items.size());
    Map isRead = (Map<String, Object>) items.get(0);
    assertNotNull(isRead);
    assertEquals("ImageStream", isRead.get("kind"));
    Map spec = (Map<String, Object>) isRead.get("spec");
    assertNotNull(spec);
    List tags = (List) spec.get("tags");
    assertNotNull(tags);
    assertEquals(1, tags.size());
    Map tag = (Map) tags.get(0);
    Map from = (Map) tag.get("from");
    assertEquals("ImageStreamImage", from.get("kind"));
    assertEquals("test@ab12cd", from.get("name"));
    assertEquals("default", from.get("namespace"));
    // Add a second image stream
    ImageStream secondIs = lookupImageStream("secondIS");
    setupClientMock(secondIs, "second-test");
    ImageName name2 = new ImageName("second-test:1.0");
    service.appendImageStreamResource(name2, target);
    result = readImageStreamDescriptor(target);
    System.out.println(result.toString());
    items = getItemsList(result);
    assertEquals(2, items.size());
    Set<String> names = new HashSet<>(Arrays.asList("second-test", "test"));
    for (Map item : items) {
        assertTrue(names.remove(((Map) item.get("metadata")).get("name")));
    }
    assertTrue(names.isEmpty());
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) Yaml(org.yaml.snakeyaml.Yaml) Test(org.junit.Test)

Example 42 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project fabric8-maven-plugin by fabric8io.

the class DockerImageWatcher method restartContainer.

protected void restartContainer(WatchService.ImageWatcher watcher, Set<HasMetadata> resources) throws MojoExecutionException {
    ImageConfiguration imageConfig = watcher.getImageConfiguration();
    String imageName = imageConfig.getName();
    try {
        ClusterAccess clusterAccess = new ClusterAccess(getContext().getNamespace());
        KubernetesClient client = clusterAccess.createDefaultClient(log);
        String namespace = clusterAccess.getNamespace();
        String imagePrefix = getImagePrefix(imageName);
        for (HasMetadata entity : resources) {
            updateImageName(client, namespace, entity, imagePrefix, imageName);
        }
    } catch (KubernetesClientException e) {
        KubernetesResourceUtil.handleKubernetesClientException(e, this.log);
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ClusterAccess(io.fabric8.maven.core.access.ClusterAccess) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 43 with ImageName

use of io.fabric8.maven.docker.util.ImageName 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;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) PodSpec(io.fabric8.kubernetes.api.model.PodSpec)

Example 44 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.

the class CopyMojoTest method thenImageIsPulled.

private void thenImageIsPulled(ImageConfiguration image, String pullRegistry, boolean imageExists) throws DockerAccessException, MojoExecutionException {
    new Verifications() {

        {
            final String imageName;
            final RegistryConfig registryConfig;
            registryService.pullImageWithPolicy(imageName = withCapture(), (ImagePullManager) any, registryConfig = withCapture(), image.getBuildConfiguration());
            times = 1;
            assertEquals(image.getName(), imageName);
            assertNotNull(registryConfig);
            assertEquals(pullRegistry, registryConfig.getRegistry());
        }
    };
}
Also used : RegistryConfig(io.fabric8.maven.docker.service.RegistryService.RegistryConfig) Verifications(mockit.Verifications)

Example 45 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.

the class UrlBuilderTest method tagContainer.

@Test
public void tagContainer() throws URISyntaxException {
    UrlBuilder builder = new UrlBuilder("", "1.0");
    assertEquals(new URI("/1.0/images/t1%3Alatest/tag?force=1&repo=new&tag=tag1"), new URI(builder.tagContainer(new ImageName("t1:latest"), new ImageName("new:tag1"), true)));
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) UrlBuilder(io.fabric8.maven.docker.access.UrlBuilder) Test(org.junit.Test)

Aggregations

ImageName (io.fabric8.maven.docker.util.ImageName)20 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)11 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)10 File (java.io.File)9 IOException (java.io.IOException)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)6 Container (io.fabric8.kubernetes.api.model.Container)5 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 CopyConfiguration (io.fabric8.maven.docker.config.CopyConfiguration)4 Container (io.fabric8.maven.docker.model.Container)4 Test (org.junit.Test)4 DockerClient (io.fabric8.docker.client.DockerClient)3 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)3 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)3 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)3 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)2 Controller (io.fabric8.kubernetes.api.Controller)2