Search in sources :

Example 1 with BuildRequestBuilder

use of io.fabric8.openshift.api.model.BuildRequestBuilder in project kubernetes-client by fabric8io.

the class BuildConfigExamples method main.

@SuppressWarnings("java:S106")
public static void main(String[] args) throws InterruptedException {
    try (KubernetesClient kubernetesClient = new KubernetesClientBuilder().build()) {
        final OpenShiftClient client = kubernetesClient.adapt(OpenShiftClient.class);
        final String namespace;
        if (client.getNamespace() != null) {
            namespace = client.getNamespace();
            logger.info("Using configured namespace: {}", namespace);
        } else {
            final Namespace ns = client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName(NAMESPACE).addToLabels("this", "rocks").endMetadata().build());
            namespace = ns.getMetadata().getName();
            logger.info("Created namespace: {}", namespace);
        }
        client.serviceAccounts().inNamespace(namespace).create(new ServiceAccountBuilder().withNewMetadata().withName("fabric8").endMetadata().build());
        final ImageStream is = client.imageStreams().inNamespace(namespace).create(new ImageStreamBuilder().withNewMetadata().withName("example-camel-cdi").endMetadata().withNewSpec().addNewTag().withName("latest").endTag().withDockerImageRepository("fabric8/example-camel-cdi").endSpec().withNewStatus().withDockerImageRepository("").endStatus().build());
        logger.info("Created image stream: {}", is.getMetadata().getName());
        final String buildConfigName = "custom-build-config";
        final BuildConfig buildConfig = client.buildConfigs().inNamespace(namespace).create(new BuildConfigBuilder().withNewMetadata().withName(buildConfigName).endMetadata().withNewSpec().withServiceAccount("fabric8").withNewSource().withType("Git").withNewGit().withUri("https://github.com/fabric8io/example-camel-cdi.git").endGit().endSource().withNewResources().addToLimits("mykey", new Quantity("10")).addToRequests("mykey", new Quantity("10")).endResources().withNewStrategy().withType("Source").withNewSourceStrategy().withNewFrom().withName("java-sti:latest").withKind("DockerImage").endFrom().endSourceStrategy().endStrategy().withNewOutput().withNewTo().withKind("DockerImage").withName("example-camel-cdi:latest").endTo().endOutput().addNewTrigger().withType("GitHub").withNewGithub().withSecret("secret101").endGithub().endTrigger().endSpec().build());
        logger.info("Created Build Config: {}", buildConfig.getMetadata().getName());
        final Build build = client.buildConfigs().inNamespace(namespace).withName("custom-build-config").instantiate(new BuildRequestBuilder().withNewMetadata().withName(buildConfigName).endMetadata().build());
        logger.info("Instantiated Build: {}", build.getMetadata().getName());
        client.buildConfigs().inNamespace(namespace).withName(buildConfigName).withSecret("secret101").withType("github").trigger(new WebHookTriggerBuilder().withSecret("secret101").build());
        logger.info("Triggered Build Config: {}", buildConfigName);
        Thread.sleep(6000);
        logger.info("Builds:");
        for (Build b : client.builds().inNamespace(namespace).list().getItems()) {
            logger.info("\t\t\t{}", b.getMetadata().getName());
            logger.info("\t\t\t\t\t Log:");
            client.builds().inNamespace(namespace).withName(b.getMetadata().getName()).watchLog(System.out);
        }
        logger.info("Done");
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ServiceAccountBuilder(io.fabric8.kubernetes.api.model.ServiceAccountBuilder) ImageStream(io.fabric8.openshift.api.model.ImageStream) Quantity(io.fabric8.kubernetes.api.model.Quantity) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) Namespace(io.fabric8.kubernetes.api.model.Namespace) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) KubernetesClientBuilder(io.fabric8.kubernetes.client.KubernetesClientBuilder) Build(io.fabric8.openshift.api.model.Build) BuildRequestBuilder(io.fabric8.openshift.api.model.BuildRequestBuilder) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) WebHookTriggerBuilder(io.fabric8.openshift.api.model.WebHookTriggerBuilder)

Example 2 with BuildRequestBuilder

use of io.fabric8.openshift.api.model.BuildRequestBuilder in project kubernetes-client by fabric8io.

the class BuildConfigWatchIT method instantiateAndWatchBuild.

@Test
public void instantiateAndWatchBuild() throws InterruptedException {
    // Given
    BuildRequest buildRequest = new BuildRequestBuilder().withNewMetadata().withName("ruby-hello-world").endMetadata().build();
    CountDownLatch buildEventReceivedLatch = new CountDownLatch(1);
    // When
    Build startedBuild = client.buildConfigs().inNamespace(session.getNamespace()).withName("ruby-hello-world").instantiate(buildRequest);
    TestBuildWatcher testBuildWatcher = new TestBuildWatcher(buildEventReceivedLatch, getName(startedBuild));
    Watch watcher = client.builds().inNamespace(session.getNamespace()).withName(getName(startedBuild)).watch(testBuildWatcher);
    // Then
    assertNotNull(startedBuild);
    assertEquals("ruby-hello-world", getOrCreateAnnotations(startedBuild).get("openshift.io/build-config.name"));
    assertTrue(buildEventReceivedLatch.await(5, TimeUnit.SECONDS));
    watcher.close();
}
Also used : BuildRequestBuilder(io.fabric8.openshift.api.model.BuildRequestBuilder) Build(io.fabric8.openshift.api.model.Build) Watch(io.fabric8.kubernetes.client.Watch) BuildRequest(io.fabric8.openshift.api.model.BuildRequest) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Build (io.fabric8.openshift.api.model.Build)2 BuildRequestBuilder (io.fabric8.openshift.api.model.BuildRequestBuilder)2 Namespace (io.fabric8.kubernetes.api.model.Namespace)1 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 ServiceAccountBuilder (io.fabric8.kubernetes.api.model.ServiceAccountBuilder)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientBuilder (io.fabric8.kubernetes.client.KubernetesClientBuilder)1 Watch (io.fabric8.kubernetes.client.Watch)1 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)1 BuildConfigBuilder (io.fabric8.openshift.api.model.BuildConfigBuilder)1 BuildRequest (io.fabric8.openshift.api.model.BuildRequest)1 ImageStream (io.fabric8.openshift.api.model.ImageStream)1 ImageStreamBuilder (io.fabric8.openshift.api.model.ImageStreamBuilder)1 WebHookTriggerBuilder (io.fabric8.openshift.api.model.WebHookTriggerBuilder)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1