Search in sources :

Example 1 with OpenshiftIntegrationTestConfig

use of io.dekorate.testing.openshift.config.OpenshiftIntegrationTestConfig in project dekorate by dekorateio.

the class OpenshiftExtension method startProject.

private void startProject(ExtensionContext context, Project project) throws InterruptedException {
    LOGGER.info("Starting project at " + project.getRoot());
    OpenshiftIntegrationTestConfig config = getOpenshiftIntegrationTestConfig(context);
    KubernetesClient client = getKubernetesClient(context);
    KubernetesList list = getOpenshiftResources(context, project);
    OpenshiftConfig openshiftConfig = getOpenshiftConfig(project);
    ImageConfiguration imageConfiguration = ImageConfiguration.from(openshiftConfig);
    BuildService buildService = null;
    try {
        BuildServiceFactory buildServiceFactory = BuildServiceFactories.find(project, imageConfiguration).orElseThrow(() -> new IllegalStateException("No applicable BuildServiceFactory found."));
        buildService = buildServiceFactory.create(project, imageConfiguration, list.getItems());
    } catch (Exception e) {
        throw DekorateException.launderThrowable("Failed to lookup BuildService.", e);
    }
    if (config.isPushEnabled()) {
        buildService.prepare();
        buildService.build();
        buildService.push();
    } else if (config.isBuildEnabled()) {
        buildService.prepare();
        buildService.build();
    }
    if (config.isDeployEnabled()) {
        // Create the remaining resources.
        list.getItems().stream().filter(i -> !(i instanceof BuildConfig)).forEach(i -> {
            try {
                HasMetadata r = client.resource(i).fromServer().get();
                if (r == null) {
                    client.resource(i).apply();
                } else if (r instanceof ImageStream) {
                // let's not delete image streams at this point
                } else if (deleteAndWait(context, i, 1, TimeUnit.MINUTES)) {
                    client.resource(i).apply();
                }
            } catch (Exception e) {
                e.printStackTrace(System.err);
            }
            LOGGER.info("Created: " + i.getKind() + " name:" + i.getMetadata().getName() + ".");
        });
        List<HasMetadata> waitables = list.getItems().stream().filter(i -> i instanceof Deployment || i instanceof DeploymentConfig || i instanceof Pod || i instanceof ReplicaSet || i instanceof ReplicationController).collect(Collectors.toList());
        long started = System.currentTimeMillis();
        LOGGER.info("Waiting until ready (" + config.getReadinessTimeout() + " ms)...");
        waitUntilCondition(context, waitables, i -> OpenshiftReadiness.isReady(i), config.getReadinessTimeout(), TimeUnit.MILLISECONDS);
        long ended = System.currentTimeMillis();
        LOGGER.info("Waited: " + (ended - started) + " ms.");
        // Display the item status
        waitables.stream().map(r -> client.resource(r).fromServer().get()).forEach(i -> {
            if (!OpenshiftReadiness.isReady(i)) {
                readinessFailed(context);
                LOGGER.warning(i.getKind() + ":" + i.getMetadata().getName() + " not ready!");
            }
        });
        if (hasReadinessFailed(context)) {
            throw new IllegalStateException("Readiness Failed");
        }
    }
}
Also used : WithEvents(io.dekorate.testing.WithEvents) WithProject(io.dekorate.testing.WithProject) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Arrays(java.util.Arrays) Project(io.dekorate.project.Project) OpenshiftIntegrationTestConfig(io.dekorate.testing.openshift.config.OpenshiftIntegrationTestConfig) WithKubernetesClient(io.dekorate.testing.WithKubernetesClient) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) OpenshiftConfig(io.dekorate.openshift.config.OpenshiftConfig) VersionInfo(io.fabric8.kubernetes.client.VersionInfo) TestWatcher(org.junit.jupiter.api.extension.TestWatcher) ImageStream(io.fabric8.openshift.api.model.ImageStream) DekorateException(io.dekorate.DekorateException) Logger(io.dekorate.Logger) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) WithPod(io.dekorate.testing.WithPod) Internal(io.dekorate.kubernetes.annotation.Internal) LoggerFactory(io.dekorate.LoggerFactory) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) BuildServiceFactories(io.dekorate.BuildServiceFactories) Pod(io.fabric8.kubernetes.api.model.Pod) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) BuildService(io.dekorate.BuildService) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) TimeUnit(java.util.concurrent.TimeUnit) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) List(java.util.List) ConditionEvaluationResult(org.junit.jupiter.api.extension.ConditionEvaluationResult) BeforeAllCallback(org.junit.jupiter.api.extension.BeforeAllCallback) ExecutionCondition(org.junit.jupiter.api.extension.ExecutionCondition) AfterAllCallback(org.junit.jupiter.api.extension.AfterAllCallback) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) BuildServiceFactory(io.dekorate.BuildServiceFactory) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) WithKubernetesClient(io.dekorate.testing.WithKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) WithPod(io.dekorate.testing.WithPod) Pod(io.fabric8.kubernetes.api.model.Pod) BuildService(io.dekorate.BuildService) ImageStream(io.fabric8.openshift.api.model.ImageStream) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) OpenshiftConfig(io.dekorate.openshift.config.OpenshiftConfig) DekorateException(io.dekorate.DekorateException) OpenshiftIntegrationTestConfig(io.dekorate.testing.openshift.config.OpenshiftIntegrationTestConfig) ImageConfiguration(io.dekorate.kubernetes.config.ImageConfiguration) BuildServiceFactory(io.dekorate.BuildServiceFactory) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet)

Example 2 with OpenshiftIntegrationTestConfig

use of io.dekorate.testing.openshift.config.OpenshiftIntegrationTestConfig in project dekorate by dekorateio.

the class OpenshiftExtension method afterAll.

@Override
public void afterAll(ExtensionContext context) {
    OpenshiftIntegrationTestConfig config = getOpenshiftIntegrationTestConfig(context);
    OpenShiftClient client = getKubernetesClient(context).adapt(OpenShiftClient.class);
    try {
        LOGGER.info("Cleaning up...");
        // For setup failures:
        if (shouldDisplayDiagnostics(context)) {
            displayDiagnostics(context);
        }
        if (config.isDeployEnabled()) {
            List<Project> projects = getProjects(context);
            for (Project project : projects) {
                deleteProject(context, project, client);
            }
        }
    } finally {
        closeKubernetesClient(context);
    }
}
Also used : WithProject(io.dekorate.testing.WithProject) Project(io.dekorate.project.Project) OpenshiftIntegrationTestConfig(io.dekorate.testing.openshift.config.OpenshiftIntegrationTestConfig) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient)

Aggregations

Project (io.dekorate.project.Project)2 WithProject (io.dekorate.testing.WithProject)2 OpenshiftIntegrationTestConfig (io.dekorate.testing.openshift.config.OpenshiftIntegrationTestConfig)2 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)2 BuildService (io.dekorate.BuildService)1 BuildServiceFactories (io.dekorate.BuildServiceFactories)1 BuildServiceFactory (io.dekorate.BuildServiceFactory)1 DekorateException (io.dekorate.DekorateException)1 Logger (io.dekorate.Logger)1 LoggerFactory (io.dekorate.LoggerFactory)1 Internal (io.dekorate.kubernetes.annotation.Internal)1 ImageConfiguration (io.dekorate.kubernetes.config.ImageConfiguration)1 OpenshiftConfig (io.dekorate.openshift.config.OpenshiftConfig)1 WithEvents (io.dekorate.testing.WithEvents)1 WithKubernetesClient (io.dekorate.testing.WithKubernetesClient)1 WithPod (io.dekorate.testing.WithPod)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)1