use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class MergeResourceTest method testMergeDeploymentTemplateMetadata.
@Test
public void testMergeDeploymentTemplateMetadata() throws Exception {
Deployment resource = new DeploymentBuilder().withNewMetadata().withName("cheese").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withImage("cheese-image").endContainer().endSpec().withNewMetadata().addToAnnotations("overwriteKey", "originalValue").addToAnnotations("unchangedKey", "shouldNotChange").addToAnnotations("unchangedBlankKey", "").addToAnnotations("deletedKey", "shouldBeDeleted").endMetadata().endTemplate().endSpec().build();
Deployment override = new DeploymentBuilder().withNewMetadata().withName("cheese").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().addToEnv(new EnvVarBuilder().withName("ENV_FOO").withValue("FOO_VALUE").build()).endContainer().endSpec().withNewMetadata().addToAnnotations("overwriteKey", "newValue").addToAnnotations("deletedKey", "").endMetadata().endTemplate().endSpec().build();
HasMetadata answer = KubernetesResourceUtil.mergeResources(resource, override, log, false);
assertNotNull(answer);
log.info("Override metadata on Deployment generated: " + KubernetesHelper.toYaml(answer));
assertThat(answer).describedAs("mergeResult").isInstanceOf(Deployment.class);
Deployment deployment = (Deployment) answer;
Map<String, String> annotations = deployment.getSpec().getTemplate().getMetadata().getAnnotations();
assertDataModified(annotations, "Deployment.spec.template.metadata.annotations");
assertDataNotModified(resource.getSpec().getTemplate().getMetadata().getAnnotations(), "Original Deployment.spec.template.metadata.annotations");
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class ProfileUtilTest method mergeProfiles.
@Test
public void mergeProfiles() throws Exception {
Profile profile = ProfileUtil.findProfile("merge-1", getProfileDir());
assertFalse(profile.getEnricherConfig().use("fmp-project"));
assertTrue(profile.getEnricherConfig().use("fmp-image"));
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method extractImageUser.
private static String extractImageUser(String image, MavenProject project) {
ImageName name = new ImageName(image);
String imageUser = name.getUser();
return imageUser != null ? imageUser : project.getGroupId();
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method logBuildBuildFailedDetails.
private void logBuildBuildFailedDetails(OpenShiftClient client, String buildName) {
try {
BuildConfig build = client.buildConfigs().withName(buildName).get();
ObjectReference ref = build.getSpec().getStrategy().getSourceStrategy().getFrom();
String kind = ref.getKind();
String name = ref.getName();
if ("DockerImage".equals(kind)) {
log.error("Please, ensure that the Docker image '%s' exists and is accessible by OpenShift", name);
} else if ("ImageStreamTag".equals(kind)) {
String namespace = ref.getNamespace();
String namespaceInfo = "current";
String namespaceParams = "";
if (namespace != null && !namespace.isEmpty()) {
namespaceInfo = "'" + namespace + "'";
namespaceParams = " -n " + namespace;
}
log.error("Please, ensure that the ImageStream Tag '%s' exists in the %s namespace (with 'oc get is%s')", name, namespaceInfo, namespaceParams);
}
} catch (Exception ex) {
log.error("Unable to get detailed information from the BuildServiceConfig: " + ex.getMessage());
}
}
use of io.fabric8.docker.api.model.Image in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method build.
@Override
public void build(ImageConfiguration imageConfig) throws Fabric8ServiceException {
try {
ImageName imageName = new ImageName(imageConfig.getName());
File dockerTar = createBuildArchive(imageConfig);
KubernetesListBuilder builder = new KubernetesListBuilder();
// Check for buildconfig / imagestream and create them if necessary
String buildName = updateOrCreateBuildConfig(config, client, builder, imageConfig);
checkOrCreateImageStream(config, client, builder, getImageStreamName(imageName));
applyResourceObjects(config, client, builder);
// Start the actual build
Build build = startBuild(client, dockerTar, buildName);
// Wait until the build finishes
waitForOpenShiftBuildToComplete(client, build);
// Create a file with generated image streams
addImageStreamToFile(getImageStreamFile(config), imageName, client);
} catch (Fabric8ServiceException e) {
throw e;
} catch (Exception ex) {
throw new Fabric8ServiceException("Unable to build the image using the OpenShift build service", ex);
}
}
Aggregations