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 ballerina by ballerina-lang.
the class DefaultBallerinaDockerClient method getImage.
/**
* {@inheritDoc}
*/
@Override
public String getImage(String imageName, String dockerEnv) {
DockerClient client = getDockerClient(dockerEnv);
List<Image> images = client.image().list().filter(imageName).endImages();
// No images found?
if (images == null || images.size() < 1) {
return null;
}
for (Image image : images) {
// Invalid tags found?
if (image.getRepoTags() == null) {
continue;
}
String currentImageName = image.getRepoTags().get(0);
if (currentImageName.equals(imageName + ":" + Constants.IMAGE_VERSION_LATEST) || currentImageName.equals(imageName)) {
return currentImageName;
}
}
return null;
}
Aggregations