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());
}
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);
}
}
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;
}
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());
}
};
}
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)));
}
Aggregations