Search in sources :

Example 1 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method createMockServer.

protected WebServerEventCollector<OpenShiftMockServer> createMockServer(BuildService.BuildServiceConfig config, boolean success, long buildDelay, boolean buildConfigExists, boolean imageStreamExists) {
    OpenShiftMockServer mockServer = new OpenShiftMockServer(false);
    WebServerEventCollector<OpenShiftMockServer> collector = new WebServerEventCollector<>(mockServer);
    BuildConfig bc = new BuildConfigBuilder().withNewMetadata().withName(projectName + config.getS2iBuildNameSuffix()).endMetadata().withNewSpec().endSpec().build();
    ImageStream imageStream = new ImageStreamBuilder().withNewMetadata().withName(projectName).endMetadata().withStatus(new ImageStreamStatusBuilder().addNewTagLike(new NamedTagEventListBuilder().addNewItem().withImage("abcdef0123456789").endItem().build()).endTag().build()).build();
    KubernetesList builds = new KubernetesListBuilder().withItems(new BuildBuilder().withNewMetadata().withName(projectName).endMetadata().build()).withNewMetadata().withResourceVersion("1").endMetadata().build();
    String buildStatus = success ? "Complete" : "Fail";
    Build build = new BuildBuilder().withNewMetadata().withResourceVersion("2").endMetadata().withNewStatus().withPhase(buildStatus).endStatus().build();
    if (!buildConfigExists) {
        mockServer.expect().get().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("build-config-check").andReturn(404, "")).once();
        mockServer.expect().post().withPath("/oapi/v1/namespaces/test/buildconfigs").andReply(collector.record("new-build-config").andReturn(201, bc)).once();
    } else {
        mockServer.expect().patch().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("patch-build-config").andReturn(200, bc)).once();
    }
    mockServer.expect().get().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix()).andReply(collector.record("build-config-check").andReturn(200, bc)).always();
    if (!imageStreamExists) {
        mockServer.expect().get().withPath("/oapi/v1/namespaces/test/imagestreams/" + projectName).andReturn(404, "").once();
    }
    mockServer.expect().get().withPath("/oapi/v1/namespaces/test/imagestreams/" + projectName).andReturn(200, imageStream).always();
    mockServer.expect().post().withPath("/oapi/v1/namespaces/test/imagestreams").andReturn(201, imageStream).once();
    mockServer.expect().post().withPath("/oapi/v1/namespaces/test/buildconfigs/" + projectName + config.getS2iBuildNameSuffix() + "/instantiatebinary?commit=").andReply(collector.record("pushed").andReturn(201, imageStream)).once();
    mockServer.expect().get().withPath("/oapi/v1/namespaces/test/builds").andReply(collector.record("check-build").andReturn(200, builds)).always();
    mockServer.expect().get().withPath("/oapi/v1/namespaces/test/builds?labelSelector=openshift.io/build-config.name%3D" + projectName + config.getS2iBuildNameSuffix()).andReturn(200, builds).always();
    mockServer.expect().withPath("/oapi/v1/namespaces/test/builds/" + projectName).andReturn(200, build).always();
    mockServer.expect().withPath("/oapi/v1/namespaces/test/builds?fieldSelector=metadata.name%3D" + projectName + "&watch=true").andUpgradeToWebSocket().open().waitFor(buildDelay).andEmit(new WatchEvent(build, "MODIFIED")).done().always();
    return collector;
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) WebServerEventCollector(io.fabric8.maven.core.util.WebServerEventCollector) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Build(io.fabric8.openshift.api.model.Build) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) WatchEvent(io.fabric8.kubernetes.api.model.WatchEvent)

Example 2 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class ExposeEnricher method addMissingResources.

@Override
public void addMissingResources(KubernetesListBuilder builder) {
    int serviceCount = 0;
    List<HasMetadata> items = builder.getItems();
    if (items != null) {
        for (HasMetadata item : items) {
            if (item instanceof Service) {
                Service service = (Service) item;
                enrichService(service);
                serviceCount++;
            }
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Service(io.fabric8.kubernetes.api.model.Service)

Example 3 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class OpenShiftRouteEnricher method hasRoute.

/**
 * Returns true if we already have a route created for the given name
 */
private boolean hasRoute(final KubernetesListBuilder listBuilder, final String name) {
    final AtomicBoolean answer = new AtomicBoolean(false);
    listBuilder.accept(new TypedVisitor<RouteBuilder>() {

        @Override
        public void visit(RouteBuilder builder) {
            ObjectMeta metadata = builder.getMetadata();
            if (metadata != null && name.equals(metadata.getName())) {
                answer.set(true);
            }
        }
    });
    return answer.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder)

Example 4 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class DockerHealthCheckEnricherTest method testUnmatchingHealthCheck.

@Test
public void testUnmatchingHealthCheck() throws Exception {
    // Setup mock behaviour
    new Expectations() {

        {
            context.getImages();
            result = Arrays.asList(new ImageConfiguration.Builder().alias("myImage").buildConfig(new BuildImageConfiguration.Builder().healthCheck(new HealthCheckConfiguration.Builder().mode(HealthCheckMode.cmd).cmd("/bin/check").timeout("1s").interval("1h1s").retries(3).build()).build()).build());
        }
    };
    KubernetesListBuilder builder = createDeployment("myUnmatchingImage");
    DockerHealthCheckEnricher enricher = new DockerHealthCheckEnricher(context);
    enricher.addMissingResources(builder);
    KubernetesList list = builder.build();
    assertEquals(1, list.getItems().size());
    assertNoProbes(list.getItems().get(0));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.Test)

Example 5 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class DockerHealthCheckEnricherTest method testEnrichFromSingleImage.

@Test
public void testEnrichFromSingleImage() throws Exception {
    // Setup mock behaviour
    new Expectations() {

        {
            context.getImages();
            result = Arrays.asList(new ImageConfiguration.Builder().alias("myImage").buildConfig(new BuildImageConfiguration.Builder().healthCheck(new HealthCheckConfiguration.Builder().mode(HealthCheckMode.cmd).cmd("/bin/check").timeout("1s").interval("1h1s").retries(3).build()).build()).build(), new ImageConfiguration.Builder().alias("myImage2").buildConfig(new BuildImageConfiguration.Builder().healthCheck(new HealthCheckConfiguration.Builder().mode(HealthCheckMode.cmd).cmd("/xxx/check").timeout("3s").interval("3h1s").retries(9).build()).build()).build());
        }
    };
    KubernetesListBuilder builder = createDeployment("myImage");
    DockerHealthCheckEnricher enricher = new DockerHealthCheckEnricher(context);
    enricher.addMissingResources(builder);
    KubernetesList list = builder.build();
    assertEquals(1, list.getItems().size());
    assertHealthCheckMatching(builder.build().getItems().get(0), "livenessProbe", "/bin/check", 1, 3601, 3);
    assertHealthCheckMatching(builder.build().getItems().get(0), "readinessProbe", "/bin/check", 1, 3601, 3);
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.Test)

Aggregations

KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)30 Test (org.junit.Test)25 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)17 Expectations (mockit.Expectations)13 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)8 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 File (java.io.File)5 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)3 Secret (io.fabric8.kubernetes.api.model.Secret)3 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)3 IOException (java.io.IOException)3 Map (java.util.Map)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 Visitable (io.fabric8.kubernetes.api.builder.Visitable)2 Visitor (io.fabric8.kubernetes.api.builder.Visitor)2 KubernetesResource (io.fabric8.kubernetes.api.model.KubernetesResource)2