use of org.eclipse.jkube.kit.config.image.ImageName in project jkube by eclipse.
the class OpenShiftBuildServiceUtilsTest method computeS2IBuildName_withImageNameAndEmptyBuildServiceConfig_shouldReturnName.
@Test
public void computeS2IBuildName_withImageNameAndEmptyBuildServiceConfig_shouldReturnName() {
// Given
final ImageName imageName = new ImageName("registry/name:tag");
// When
final String result = computeS2IBuildName(new BuildServiceConfig(), imageName);
// Then
assertThat(result).isEqualTo("name");
}
use of org.eclipse.jkube.kit.config.image.ImageName in project jkube by eclipse.
the class OpenShiftBuildServiceUtilsTest method computeS2IBuildName_withImageNameAndBuildServiceWithS2I_shouldReturnNameWithDefaultSuffix.
@Test
public void computeS2IBuildName_withImageNameAndBuildServiceWithS2I_shouldReturnNameWithDefaultSuffix() {
// Given
final BuildServiceConfig buildServiceConfig = BuildServiceConfig.builder().jKubeBuildStrategy(JKubeBuildStrategy.s2i).buildDirectory(temporaryFolder.getRoot().getAbsolutePath()).build();
final ImageName imageName = new ImageName("registry/name:tag");
// When
final String result = computeS2IBuildName(buildServiceConfig, imageName);
// Then
assertThat(result).isEqualTo("name-s2i");
}
use of org.eclipse.jkube.kit.config.image.ImageName in project jkube by eclipse.
the class KubernetesClientUtil method deleteOpenShiftEntities.
public static void deleteOpenShiftEntities(KubernetesClient kubernetes, String namespace, Collection<HasMetadata> entities, String s2iBuildNameSuffix, KitLogger log) {
// For OpenShift cluster, also delete s2i buildconfig
OpenShiftClient openshiftClient = OpenshiftHelper.asOpenShiftClient(kubernetes);
if (openshiftClient == null) {
return;
}
for (HasMetadata entity : entities) {
if ("ImageStream".equals(KubernetesHelper.getKind(entity))) {
ImageName imageName = new ImageName(entity.getMetadata().getName());
String buildName = getS2IBuildName(imageName, s2iBuildNameSuffix);
log.info("Deleting resource BuildConfig %s/%s and Builds", namespace, buildName);
openshiftClient.builds().inNamespace(namespace).withLabel("buildconfig", buildName).delete();
openshiftClient.buildConfigs().inNamespace(namespace).withName(buildName).delete();
}
}
}
use of org.eclipse.jkube.kit.config.image.ImageName in project jkube by eclipse.
the class OpenshiftBuildService method buildSingleImage.
@Override
public void buildSingleImage(ImageConfiguration imageConfig) throws JKubeServiceException {
initClient();
String buildName = null;
try {
final ImageConfiguration.ImageConfigurationBuilder applicableImageConfigBuilder = imageConfig.toBuilder();
if (imageConfig.getBuildConfiguration() != null && !imageConfig.getBuildConfiguration().isDockerFileMode() && imageConfig.getBuildConfiguration().getAssembly() != null) {
applicableImageConfigBuilder.build(imageConfig.getBuild().toBuilder().assembly(imageConfig.getBuildConfiguration().getAssembly().getFlattenedClone(jKubeServiceHub.getConfiguration())).build());
}
final ImageConfiguration applicableImageConfig = applicableImageConfigBuilder.build();
ImageName imageName = new ImageName(applicableImageConfig.getName());
File dockerTar = createBuildArchive(jKubeServiceHub, applicableImageConfig);
KubernetesListBuilder builder = new KubernetesListBuilder();
// Check for buildconfig / imagestream / pullSecret and create them if necessary
String openshiftPullSecret = buildServiceConfig.getOpenshiftPullSecret();
final boolean usePullSecret = checkOrCreatePullSecret(client, builder, openshiftPullSecret, applicableImageConfig);
if (usePullSecret) {
buildName = updateOrCreateBuildConfig(buildServiceConfig, client, builder, applicableImageConfig, openshiftPullSecret);
} else {
buildName = updateOrCreateBuildConfig(buildServiceConfig, client, builder, applicableImageConfig, null);
}
if (buildServiceConfig.getBuildOutputKind() == null || IMAGE_STREAM_TAG.equals(buildServiceConfig.getBuildOutputKind())) {
checkOrCreateImageStream(buildServiceConfig, client, builder, resolveImageStreamName(imageName));
applyBuild(buildName, dockerTar, builder);
// Create a file with generated image streams
addImageStreamToFile(getImageStreamFile(), imageName, client);
} else {
applyBuild(buildName, dockerTar, builder);
}
} catch (JKubeServiceException e) {
throw e;
} catch (Exception ex) {
// Log additional details in case of any IOException
if (ex.getCause() instanceof IOException) {
log.error("Build for %s failed: %s", buildName, ex.getCause().getMessage());
logBuildFailure(client, buildName);
} else {
throw new JKubeServiceException("Unable to build the image using the OpenShift build service", ex);
}
}
}
use of org.eclipse.jkube.kit.config.image.ImageName in project jkube by eclipse.
the class ContainerHandler method getImageName.
private String getImageName(ImageConfiguration imageConfiguration) {
if (StringUtils.isBlank(imageConfiguration.getName())) {
return null;
}
Properties props = getPropertiesWithSystemOverrides(this.configurationProperties);
String configuredRegistry = EnvUtil.firstRegistryOf(imageConfiguration.getRegistry(), props.getProperty("jkube.docker.pull.registry"), props.getProperty("jkube.docker.registry"));
return new ImageName(imageConfiguration.getName()).getFullName(configuredRegistry);
}
Aggregations