Search in sources :

Example 1 with BuildConfigBuilder

use of io.fabric8.openshift.api.model.BuildConfigBuilder 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 BuildConfigBuilder

use of io.fabric8.openshift.api.model.BuildConfigBuilder in project strimzi by strimzi.

the class KafkaConnectS2ICluster method generateBuildConfig.

/**
 * Generate new BuildConfig
 *
 * @return      BuildConfig resource definition
 */
public BuildConfig generateBuildConfig() {
    BuildTriggerPolicy triggerConfigChange = new BuildTriggerPolicy();
    triggerConfigChange.setType("ConfigChange");
    BuildTriggerPolicy triggerImageChange = new BuildTriggerPolicy();
    triggerImageChange.setType("ImageChange");
    triggerImageChange.setImageChange(new ImageChangeTrigger());
    BuildConfig build = new BuildConfigBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).endMetadata().withNewSpec().withFailedBuildsHistoryLimit(5).withNewOutput().withNewTo().withKind("ImageStreamTag").withName(image).endTo().endOutput().withRunPolicy("Serial").withNewSource().withType("Binary").withBinary(new BinaryBuildSource()).endSource().withNewStrategy().withType("Source").withNewSourceStrategy().withNewFrom().withKind("ImageStreamTag").withName(getSourceImageStreamName() + ":" + sourceImageTag).endFrom().endSourceStrategy().endStrategy().withTriggers(triggerConfigChange, triggerImageChange).endSpec().build();
    return build;
}
Also used : BinaryBuildSource(io.fabric8.openshift.api.model.BinaryBuildSource) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) ImageChangeTrigger(io.fabric8.openshift.api.model.ImageChangeTrigger) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) BuildTriggerPolicy(io.fabric8.openshift.api.model.BuildTriggerPolicy)

Example 3 with BuildConfigBuilder

use of io.fabric8.openshift.api.model.BuildConfigBuilder in project fabric8 by fabric8io.

the class CreateBuildConfig method main.

public static void main(String... args) {
    if (args.length < 1) {
        System.out.println("Usage nameOfBuildConfig");
        return;
    }
    try {
        KubernetesClient kube = new DefaultKubernetesClient();
        String name = args[0];
        String namespace = kube.getNamespace();
        if (Strings.isNullOrBlank(namespace)) {
            namespace = KubernetesHelper.defaultNamespace();
        }
        if (Strings.isNullOrBlank(namespace)) {
            namespace = "default";
        }
        System.out.println("Creating a BuildConfig for name: " + name + " in namespace: " + namespace);
        BuildConfig buildConfig = new BuildConfigBuilder().withNewMetadata().withName(name).withNamespace(namespace).endMetadata().withNewSpec().withNewSource().withType("Git").withNewGit().withUri("http://gogs.vagrant.f8/gogsadmin/" + name + ".git").endGit().endSource().endSpec().build();
        System.out.println("Creating BuildConfig: " + buildConfig);
        Controller controller = new Controller(kube);
        if (controller.getNamespace() == null) {
            controller.setNamespace(namespace);
        }
        controller.applyBuildConfig(buildConfig, "Generated!");
        System.out.println("Applied!: " + name);
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder)

Aggregations

BuildConfig (io.fabric8.openshift.api.model.BuildConfig)3 BuildConfigBuilder (io.fabric8.openshift.api.model.BuildConfigBuilder)3 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 WatchEvent (io.fabric8.kubernetes.api.model.WatchEvent)1 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 WebServerEventCollector (io.fabric8.maven.core.util.WebServerEventCollector)1 BinaryBuildSource (io.fabric8.openshift.api.model.BinaryBuildSource)1 Build (io.fabric8.openshift.api.model.Build)1 BuildBuilder (io.fabric8.openshift.api.model.BuildBuilder)1 BuildTriggerPolicy (io.fabric8.openshift.api.model.BuildTriggerPolicy)1 ImageChangeTrigger (io.fabric8.openshift.api.model.ImageChangeTrigger)1 ImageStream (io.fabric8.openshift.api.model.ImageStream)1 ImageStreamBuilder (io.fabric8.openshift.api.model.ImageStreamBuilder)1 ImageStreamStatusBuilder (io.fabric8.openshift.api.model.ImageStreamStatusBuilder)1 NamedTagEventListBuilder (io.fabric8.openshift.api.model.NamedTagEventListBuilder)1 OpenShiftMockServer (io.fabric8.openshift.client.server.mock.OpenShiftMockServer)1