Search in sources :

Example 91 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClient method startContainer.

@Override
public void startContainer(String containerId) throws DockerAccessException {
    try {
        String url = urlBuilder.startContainer(containerId);
        log.verbose(Logger.LogVerboseCategory.API, API_LOG_FORMAT_POST, url);
        delegate.post(url, HTTP_NO_CONTENT, HTTP_OK);
    } catch (IOException e) {
        throw new DockerAccessException(e, "Unable to start container id [%s]", containerId);
    }
}
Also used : DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException)

Example 92 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project docker-maven-plugin by fabric8io.

the class RegistryService method pushImages.

/**
 * Push a set of images to a registry
 *
 * @param imageConfigs images to push (but only if they have a build configuration)
 * @param retries how often to retry
 * @param registryConfig a global registry configuration
 * @param skipTag flag to skip pushing tagged images
 * @throws DockerAccessException
 * @throws MojoExecutionException
 */
public void pushImages(Collection<ImageConfiguration> imageConfigs, int retries, RegistryConfig registryConfig, boolean skipTag) throws DockerAccessException, MojoExecutionException {
    for (ImageConfiguration imageConfig : imageConfigs) {
        BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
        String name = imageConfig.getName();
        if (buildConfig != null) {
            if (buildConfig.skipPush()) {
                log.info("%s : Skipped pushing", imageConfig.getDescription());
                continue;
            }
            String configuredRegistry = EnvUtil.firstRegistryOf(new ImageName(imageConfig.getName()).getRegistry(), imageConfig.getRegistry(), registryConfig.getRegistry());
            AuthConfig authConfig = createAuthConfig(true, new ImageName(name).getUser(), configuredRegistry, registryConfig);
            long start = System.currentTimeMillis();
            docker.pushImage(name, authConfig, configuredRegistry, retries);
            log.info("Pushed %s in %s", name, EnvUtil.formatDurationTill(start));
            if (!skipTag) {
                for (String tag : imageConfig.getBuildConfiguration().getTags()) {
                    if (tag != null) {
                        docker.pushImage(new ImageName(name, tag).getFullName(), authConfig, configuredRegistry, retries);
                    }
                }
            }
        }
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 93 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project flink by apache.

the class Fabric8FlinkKubeClient method createJobManagerComponent.

@Override
public void createJobManagerComponent(KubernetesJobManagerSpecification kubernetesJMSpec) {
    final Deployment deployment = kubernetesJMSpec.getDeployment();
    final List<HasMetadata> accompanyingResources = kubernetesJMSpec.getAccompanyingResources();
    // create Deployment
    LOG.debug("Start to create deployment with spec {}{}", System.lineSeparator(), KubernetesUtils.tryToGetPrettyPrintYaml(deployment));
    final Deployment createdDeployment = this.internalClient.apps().deployments().create(deployment);
    // Note that we should use the uid of the created Deployment for the OwnerReference.
    setOwnerReference(createdDeployment, accompanyingResources);
    this.internalClient.resourceList(accompanyingResources).createOrReplace();
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment)

Example 94 with Start

use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by fabric8io.

the class SessionListener method start.

public void start(@Observes final Start event, KubernetesClient client, Controller controller, Configuration configuration) throws Exception {
    Objects.requireNonNull(client, "KubernetesClient most not be null!");
    Session session = event.getSession();
    final Logger log = session.getLogger();
    String namespace = session.getNamespace();
    System.setProperty(Constants.KUBERNETES_NAMESPACE, namespace);
    log.status("Using Kubernetes at: " + client.getMasterUrl());
    log.status("Creating kubernetes resources inside namespace: " + namespace);
    log.info("if you use OpenShift then type this switch namespaces:     oc project " + namespace);
    log.info("if you use kubernetes then type this to switch namespaces: kubectl namespace " + namespace);
    clearTestResultDirectories(session);
    controller.setNamespace(namespace);
    controller.setThrowExceptionOnError(true);
    controller.setRecreateMode(true);
    controller.setIgnoreRunningOAuthClients(true);
    if (configuration.isCreateNamespaceForTest()) {
        createNamespace(client, controller, session);
    } else {
        String namespaceToUse = configuration.getNamespace();
        checkNamespace(client, controller, session, configuration);
        updateConfigMapStatus(client, session, Constants.RUNNING_STATUS);
        namespace = namespaceToUse;
        controller.setNamespace(namespace);
    }
    List<KubernetesList> kubeConfigs = new LinkedList<>();
    shutdownHook = new ShutdownHook(client, controller, configuration, session, kubeConfigs);
    Runtime.getRuntime().addShutdownHook(shutdownHook);
    try {
        URL configUrl = configuration.getEnvironmentConfigUrl();
        List<String> dependencies = !configuration.getEnvironmentDependencies().isEmpty() ? configuration.getEnvironmentDependencies() : resolver.resolve(session);
        if (configuration.isEnvironmentInitEnabled()) {
            for (String dependency : dependencies) {
                log.info("Found dependency: " + dependency);
                loadDependency(log, kubeConfigs, dependency, controller, configuration, namespace);
            }
            OpenShiftClient openShiftClient = controller.getOpenShiftClientOrNull();
            if (configUrl == null) {
                // lets try find the default configuration generated by the new fabric8-maven-plugin
                String resourceName = "kubernetes.yml";
                if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.IMAGE) && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.ROUTE)) {
                    resourceName = "openshift.yml";
                }
                configUrl = findConfigResource("/META-INF/fabric8/" + resourceName);
            }
            if (configUrl != null) {
                log.status("Applying kubernetes configuration from: " + configUrl);
                String configText = readAsString(configUrl);
                Object dto = null;
                String configPath = configUrl.getPath();
                if (configPath.endsWith(".yml") || configPath.endsWith(".yaml")) {
                    dto = loadYaml(configText, KubernetesResource.class);
                } else {
                    dto = loadJson(configText);
                }
                dto = expandTemplate(controller, configuration, log, namespace, configUrl.toString(), dto);
                KubernetesList kubeList = KubernetesHelper.asKubernetesList(dto);
                List<HasMetadata> items = kubeList.getItems();
                kubeConfigs.add(kubeList);
            }
            // Lets also try to load the image stream for the project.
            if (openShiftClient != null && openShiftClient.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.IMAGE)) {
                File targetDir = new File(System.getProperty("basedir", ".") + "/target");
                if (targetDir.exists() && targetDir.isDirectory()) {
                    File[] files = targetDir.listFiles();
                    if (files != null) {
                        for (File file : files) {
                            if (file.getName().endsWith("-is.yml")) {
                                loadDependency(log, kubeConfigs, file.toURI().toURL().toString(), controller, configuration, namespace);
                            }
                        }
                    }
                }
            // 
            }
        }
        if (!configuration.isEnvironmentInitEnabled() || applyConfiguration(client, controller, configuration, session, kubeConfigs)) {
            displaySessionStatus(client, session);
        } else {
            throw new IllegalStateException("Failed to apply kubernetes configuration.");
        }
    } catch (Exception e) {
        try {
            cleanupSession(client, controller, configuration, session, kubeConfigs, Constants.ERROR_STATUS);
        } catch (MultiException me) {
            throw e;
        } finally {
            if (shutdownHook != null) {
                Runtime.getRuntime().removeShutdownHook(shutdownHook);
            }
        }
        throw new RuntimeException(e);
    }
}
Also used : Util.readAsString(io.fabric8.arquillian.utils.Util.readAsString) Logger(io.fabric8.arquillian.kubernetes.log.Logger) URL(java.net.URL) MultiException(io.fabric8.utils.MultiException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) File(java.io.File) MultiException(io.fabric8.utils.MultiException) Util.cleanupSession(io.fabric8.arquillian.utils.Util.cleanupSession)

Aggregations

IOException (java.io.IOException)27 Test (org.junit.Test)25 File (java.io.File)18 HashMap (java.util.HashMap)16 Map (java.util.Map)10 Git (org.eclipse.jgit.api.Git)10 ArrayList (java.util.ArrayList)9 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)8 Bundle (org.osgi.framework.Bundle)8 PatchException (io.fabric8.patch.management.PatchException)7 URISyntaxException (java.net.URISyntaxException)7 BundleException (org.osgi.framework.BundleException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 CuratorFramework (org.apache.curator.framework.CuratorFramework)6 Container (io.fabric8.api.Container)5 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)5 FabricService (io.fabric8.api.FabricService)5 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)5 HashSet (java.util.HashSet)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5