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().getClusterConfiguration()); 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); } }
@Override protected synchronized void executeInternal(ServiceHub hub) throws MojoExecutionException { this.hub = hub; URL masterUrl = kubernetes.getMasterUrl(); KubernetesResourceUtil.validateKubernetesMasterUrl(masterUrl); File manifest; boolean isOpenshift = OpenshiftHelper.isOpenShift(kubernetes); if (isOpenshift) { manifest = openshiftManifest; } else { manifest = kubernetesManifest; } try { Set<HasMetadata> resources = KubernetesResourceUtil.loadResources(manifest); WatcherContext context = getWatcherContext(); WatcherManager.watch(getResolvedImages(), resources, context); } catch (KubernetesClientException ex) { KubernetesResourceUtil.handleKubernetesClientException(ex, this.log); } catch (Exception ex) { throw new MojoExecutionException("An error has occurred while while trying to watch the resources", ex); } }
/** * Save the images stream to a file * @param imageName name of the image for which the stream should be extracted * @param target file to store the image stream */ public void appendImageStreamResource(ImageName imageName, File target) throws MojoExecutionException { String tag = StringUtils.isBlank(imageName.getTag()) ? "latest" : imageName.getTag(); try { ImageStream is = new ImageStreamBuilder() .withNewMetadata() .withName(imageName.getSimpleName()) .endMetadata() .withNewSpec() .addNewTag() .withName(tag) .withNewFrom().withKind("ImageStreamImage").endFrom() .endTag() .endSpec() .build(); createOrUpdateImageStreamTag(client, imageName, is); appendImageStreamToFile(is, target); log.info("ImageStream %s written to %s", imageName.getSimpleName(), target); } catch (KubernetesClientException e) { KubernetesResourceUtil.handleKubernetesClientException(e, this.log); } catch (IOException e) { throw new MojoExecutionException(String.format("Cannot write ImageStream descriptor for %s to %s : %s", imageName.getFullName(), target.getAbsoluteFile(), e.getMessage()),e); } }
KubernetesResourceUtil.handleKubernetesClientException(e, this.log); } catch (MojoExecutionException e) { throw e;