use of io.fabric8.karaf.checks.Check 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);
}
}
use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.
the class ContainerHandlerTest method imagePullPolicyWithoutPolicySetTest.
@Test
public void imagePullPolicyWithoutPolicySetTest() {
// project with version and ending in SNAPSHOT
project1.setVersion("3.5-SNAPSHOT");
// project with version but not ending in SNAPSHOT
project2.setVersion("3.5-NEW");
// creating container Handler for two
ContainerHandler handler1 = new ContainerHandler(project1, envVarHandler, probeHandler);
ContainerHandler handler2 = new ContainerHandler(project2, envVarHandler, probeHandler);
// project without version
ContainerHandler handler3 = new ContainerHandler(project, envVarHandler, probeHandler);
images.clear();
images.add(imageConfiguration1);
// check if policy is not set then both in case of version is set or not
ResourceConfig config2 = new ResourceConfig.Builder().imagePullPolicy("").build();
containers = handler1.getContainers(config2, images);
assertEquals("PullAlways", containers.get(0).getImagePullPolicy());
containers = handler2.getContainers(config2, images);
assertEquals("", containers.get(0).getImagePullPolicy());
containers = handler3.getContainers(config2, images);
assertEquals("", containers.get(0).getImagePullPolicy());
}
use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.
the class ProfileUtil method findProfile.
/**
* Find a profile. Profiles are looked up at various locations:
*
* <ul>
* <li>A given directory with the name profiles.yml (and variations, {@link #findProfile(String, File)}</li>
* </ul>
* @param profileArg the profile's name
* @param resourceDir a directory to check for profiles.
* @return the profile found or the default profile if none of this name is given
* @throws IOException
*/
public static Profile findProfile(String profileArg, File resourceDir) throws IOException {
try {
String profile = profileArg == null ? DEFAULT_PROFILE : profileArg;
Profile profileFound = lookup(profile, resourceDir);
if (profileFound != null) {
return profileFound;
} else {
throw new IllegalArgumentException("No profile '" + profile + "' defined");
}
} catch (IOException e) {
throw new IOException("Error while looking up profile " + profileArg + ": " + e.getMessage(), e);
}
}
use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method executeInternal.
public void executeInternal() throws MojoExecutionException, MojoFailureException {
clusterAccess = new ClusterAccess(namespace);
try {
KubernetesClient kubernetes = clusterAccess.createDefaultClient(log);
URL masterUrl = kubernetes.getMasterUrl();
File manifest;
if (KubernetesHelper.isOpenShift(kubernetes)) {
manifest = openshiftManifest;
} else {
manifest = kubernetesManifest;
}
if (!Files.isFile(manifest)) {
if (failOnNoKubernetesJson) {
throw new MojoFailureException("No such generated manifest file: " + manifest);
} else {
log.warn("No such generated manifest file %s for this project so ignoring", manifest);
return;
}
}
String clusterKind = "Kubernetes";
if (KubernetesHelper.isOpenShift(kubernetes)) {
clusterKind = "OpenShift";
}
KubernetesResourceUtil.validateKubernetesMasterUrl(masterUrl);
log.info("Using %s at %s in namespace %s with manifest %s ", clusterKind, masterUrl, clusterAccess.getNamespace(), manifest);
Controller controller = createController();
controller.setAllowCreate(createNewResources);
controller.setServicesOnlyMode(servicesOnly);
controller.setIgnoreServiceMode(ignoreServices);
controller.setLogJsonDir(jsonLogDir);
controller.setBasedir(getRootProjectFolder());
controller.setIgnoreRunningOAuthClients(ignoreRunningOAuthClients);
controller.setProcessTemplatesLocally(processTemplatesLocally);
controller.setDeletePodsOnReplicationControllerUpdate(deletePodsOnReplicationControllerUpdate);
controller.setRollingUpgrade(rollingUpgrades);
controller.setRollingUpgradePreserveScale(isRollingUpgradePreserveScale());
boolean openShift = KubernetesHelper.isOpenShift(kubernetes);
if (openShift) {
getLog().info("OpenShift platform detected");
} else {
disableOpenShiftFeatures(controller);
}
// lets check we have created the namespace
String namespace = clusterAccess.getNamespace();
controller.applyNamespace(namespace);
controller.setNamespace(namespace);
Set<HasMetadata> entities = KubernetesResourceUtil.loadResources(manifest);
if (createExternalUrls) {
if (controller.getOpenShiftClientOrNull() != null) {
createRoutes(controller, entities);
} else {
createIngress(controller, kubernetes, entities);
}
}
applyEntities(controller, kubernetes, namespace, manifest.getName(), entities);
} 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.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.
the class ImportMojo method ensureNamespaceExists.
private void ensureNamespaceExists(KubernetesClient kubernetes, String name) {
name = convertToValidDnsLabel(name);
// lets check namespace exists
Namespace namespace = kubernetes.namespaces().withName(name).get();
if (namespace == null) {
Map<String, String> labels = new HashMap<>();
labels.put("provider", "fabric8");
labels.put("kind", "secrets");
namespace = new NamespaceBuilder().withNewMetadata().withName(name).withLabels(labels).endMetadata().build();
if (KubernetesHelper.isOpenShift(kubernetes)) {
ProjectRequest projectRequest = new ProjectRequestBuilder().withMetadata(namespace.getMetadata()).build();
OpenShiftClient openShiftClient = asOpenShiftClient(kubernetes);
log.info("Creating ProjectRequest " + name + " with labels: " + labels);
openShiftClient.projectrequests().create(projectRequest);
} else {
log.info("Creating Namespace " + name + " with labels: " + labels);
kubernetes.namespaces().withName(name).create(namespace);
}
}
}
Aggregations