io.fabric8.openshift.api.model.BuildConfig Java Examples

The following examples show how to use io.fabric8.openshift.api.model.BuildConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HandlersTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
void checkHandlers() {
  checkHandler(new BuildConfig(), new BuildConfigHandler());
  checkHandler(new Build(), new BuildHandler());
  checkHandler(new DeploymentConfig(), new DeploymentConfigHandler());
  checkHandler(new Group(), new GroupHandler());
  checkHandler(new Identity(), new IdentityHandler());
  checkHandler(new Image(), new ImageHandler());
  checkHandler(new ImageStream(), new ImageStreamHandler());
  checkHandler(new ImageStreamTag(), new ImageStreamTagHandler());
  checkHandler(new NetNamespace(), new NetNamespaceHandler());
  checkHandler(new OAuthAccessToken(), new OAuthAccessTokenHandler());
  checkHandler(new OAuthAuthorizeToken(), new OAuthAuthorizeTokenHandler());
  checkHandler(new OAuthClient(), new OAuthClientHandler());
  checkHandler(new Project(), new ProjectHandler());
  checkHandler(new Route(), new RouteHandler());
  checkHandler(new SecurityContextConstraints(), new SecurityContextConstraintsHandler());
  checkHandler(new User(), new UserHandler());
}
 
Example #2
Source File: NewIntegrationTestBuildCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    String buildConfigName = buildName.getValue();
    Objects.assertNotNull(buildConfigName, "buildName");
    Map<String, String> labels = BuildConfigs.createBuildLabels(buildConfigName);
    String gitUrlText = getOrFindGitUrl(context, gitUri.getValue());
    String imageText = image.getValue();
    List<EnvVar> envVars = createEnvVars(buildConfigName, gitUrlText, mavenCommand.getValue());
    BuildConfig buildConfig = BuildConfigs.createIntegrationTestBuildConfig(buildConfigName, labels, gitUrlText, imageText, envVars);

    LOG.info("Generated BuildConfig: " + toJson(buildConfig));

    ImageStream imageRepository = BuildConfigs.imageRepository(buildConfigName, labels);

    Controller controller = createController();
    controller.applyImageStream(imageRepository, "generated ImageStream: " + toJson(imageRepository));
    controller.applyBuildConfig(buildConfig, "generated BuildConfig: " + toJson(buildConfig));
    return Results.success("Added BuildConfig: " + Builds.getName(buildConfig) + " to OpenShift at master: " + getKubernetes().getMasterUrl());
}
 
Example #3
Source File: BuildConfigs.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static BuildConfig createBuildConfig(String buildConfigName, Map<String, String> labels, String gitUrlText, String outputImageStreamName, String imageText, String webhookSecret) {
    BuildConfigBuilder buildConfigBuilder = buildConfigBuilder(buildConfigName, labels);
    BuildConfigSpecBuilder specBuilder = new BuildConfigSpecBuilder();

    addBuildParameterGitSource(specBuilder, gitUrlText);
    if (Strings.isNotBlank(outputImageStreamName)) {
        addBuildParameterOutput(specBuilder, outputImageStreamName);
    }
    if (Strings.isNotBlank(imageText)) {
        addBuildConfigSpectiStrategy(specBuilder, imageText);
    }
    if (Strings.isNotBlank(webhookSecret)) {
        addWebHookTriggers(specBuilder, webhookSecret);
    }
    return buildConfigBuilder.withSpec(specBuilder.build()).build();
}
 
Example #4
Source File: BuilderTest.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateBuild() throws Exception {
    String buildName = "my-build";
    String imageTag = "test";
    String image = "fabric8/quickstart-camel-cdi";
    String webhookSecret = "secret101";

    Map<String, String> labels = BuildConfigs.createBuildLabels(buildName);
    ImageStream imageRepository = BuildConfigs.imageRepository(buildName, labels);
    System.out.println("Generated ImageStream: " + JsonHelper.toJson(imageRepository));

    String gitUrl = "https://github.com/jstrachan/example-cd-workflow.git";
    BuildConfig buildConfig = BuildConfigs.createBuildConfig(buildName, labels, gitUrl, imageTag, image, webhookSecret);

    System.out.println("Generated BuildConfig: " + JsonHelper.toJson(buildConfig));
}
 
Example #5
Source File: KafkaConnectS2IClusterTest.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateBuildConfig() {
    BuildConfig bc = kc.generateBuildConfig();

    assertThat(bc.getMetadata().getName(), is(KafkaConnectS2IResources.buildConfigName(cluster)));
    assertThat(bc.getMetadata().getNamespace(), is(namespace));
    assertThat(bc.getMetadata().getLabels(), is(expectedLabels(KafkaConnectS2IResources.buildConfigName(cluster))));
    assertThat(bc.getSpec().getOutput().getTo().getKind(), is("ImageStreamTag"));
    assertThat(bc.getSpec().getOutput().getTo().getName(), is(kc.image));
    assertThat(bc.getSpec().getRunPolicy(), is("Serial"));
    assertThat(bc.getSpec().getSource().getType(), is("Binary"));
    assertThat(bc.getSpec().getSource().getBinary(), is(new BinaryBuildSource()));
    assertThat(bc.getSpec().getStrategy().getType(), is("Source"));
    assertThat(bc.getSpec().getStrategy().getSourceStrategy().getFrom().getKind(), is("ImageStreamTag"));
    assertThat(bc.getSpec().getStrategy().getSourceStrategy().getFrom().getName(),
            is(KafkaConnectS2IResources.sourceImageStreamName(cluster) + ":" + kc.sourceImageTag));
    assertThat(bc.getSpec().getTriggers().size(), is(2));
    assertThat(bc.getSpec().getTriggers().get(0).getType(), is("ConfigChange"));
    assertThat(bc.getSpec().getTriggers().get(1).getType(), is("ImageChange"));
    assertThat(bc.getSpec().getTriggers().get(1).getImageChange(), is(new ImageChangeTrigger()));
    assertThat(bc.getSpec().getSuccessfulBuildsHistoryLimit(), is(new Integer(5)));
    assertThat(bc.getSpec().getFailedBuildsHistoryLimit(), is(new Integer(5)));
    assertThat(bc.getSpec().getResources().getLimits().get("cpu").getAmount(), is("42"));
    assertThat(bc.getSpec().getResources().getRequests().get("mem").getAmount(), is("4Gi"));
    checkOwnerReference(kc.createOwnerReference(), bc);
}
 
Example #6
Source File: BuildConfigCrudTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testCrud() {
  OpenShiftClient client = server.getOpenshiftClient();

  BuildConfig buildConfig = new BuildConfigBuilder()
    .withNewMetadata()
      .withName("bc2")
      .withLabels(Collections.singletonMap("key","value"))
    .endMetadata()
    .build();

  client.buildConfigs().create(buildConfig);

  BuildConfig buildConfig1 = client.buildConfigs().withName("bc2").get();
  assertEquals("value", buildConfig1.getMetadata().getLabels().get("key"));

  BuildConfigList buildConfigList = client.buildConfigs().list();
  assertEquals(1, buildConfigList.getItems().size());
}
 
Example #7
Source File: BuildConfigTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() {
 server.expect().withPath("/apis/build.openshift.io/v1/namespaces/test/buildconfigs/bc1").andReturn(200, new BuildConfigBuilder()
    .withNewMetadata().withName("bc1").endMetadata()
    .build()).once();

 server.expect().withPath("/apis/build.openshift.io/v1/namespaces/ns1/buildconfigs/bc2").andReturn(200, new BuildConfigBuilder()
    .withNewMetadata().withName("bc2").endMetadata()
    .build()).once();

  OpenShiftClient client = server.getOpenshiftClient();

  BuildConfig buildConfig = client.buildConfigs().withName("bc1").get();
  assertNotNull(buildConfig);
  assertEquals("bc1", buildConfig.getMetadata().getName());

  buildConfig = client.buildConfigs().withName("bc2").get();
  assertNull(buildConfig);

  buildConfig = client.buildConfigs().inNamespace("ns1").withName("bc2").get();
  assertNotNull(buildConfig);
  assertEquals("bc2", buildConfig.getMetadata().getName());
}
 
Example #8
Source File: WatchBuildConfigs.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  try {
    OpenShiftClient client = new DefaultOpenShiftClient();
    String namespace = client.getNamespace();
    System.out.println("Watching BuildConfigs in namespace " + namespace);
    try (Watch watchable = client.buildConfigs().inNamespace(namespace).watch(new Watcher<BuildConfig>() {
      @Override
      public void eventReceived(Action action, BuildConfig resource) {
        System.out.println(">> Action: " + action + " on BuildConfig " + resource.getMetadata().getName() + " with version: " + resource.getApiVersion());
      }

      @Override
      public void onClose(KubernetesClientException cause) {
        System.out.println("Watch Closed: " + cause);
        if (cause != null) {
          cause.printStackTrace();
        }
      }
    })) {
      System.out.println("Created watchable " + watchable);
    }
  } catch (KubernetesClientException e) {
    System.out.println("Failed: " + e);
    e.printStackTrace();
  }
}
 
Example #9
Source File: ListBuildConfigs.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  try {
    OpenShiftClient client = new DefaultOpenShiftClient();
    if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.BUILD)) {
      System.out.println("WARNING this cluster does not support the API Group " + OpenShiftAPIGroups.BUILD);
      return;
    }
    BuildConfigList list = client.buildConfigs().list();
    if (list == null) {
      System.out.println("ERROR no list returned!");
      return;
    }
    List<BuildConfig> items = list.getItems();
    for (BuildConfig item : items) {
      System.out.println("BuildConfig " + item.getMetadata().getName() + " has version: " + item.getApiVersion());
    }
  } catch (KubernetesClientException e) {
    System.out.println("Failed: " + e);
    e.printStackTrace();
  }
}
 
Example #10
Source File: PatchService.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private static EntityPatcher<BuildConfig> bcPatcher() {
    return (KubernetesClient client, String namespace, BuildConfig newObj, BuildConfig oldObj) -> {
        if (UserConfigurationCompare.configEqual(newObj, oldObj)) {
            return oldObj;
        }
        OpenShiftClient openShiftClient = OpenshiftHelper.asOpenShiftClient(client);
        if (openShiftClient == null) {
            throw new IllegalArgumentException("BuildConfig can only be patched when connected to an OpenShift cluster");
        }
        DoneableBuildConfig entity =
            openShiftClient.buildConfigs()
                  .inNamespace(namespace)
                  .withName(oldObj.getMetadata().getName())
                  .edit();

        if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) {
            entity.withMetadata(newObj.getMetadata());
        }

        if(!UserConfigurationCompare.configEqual(newObj.getSpec(), oldObj.getSpec())) {
                entity.withSpec(newObj.getSpec());
        }
        return entity.done();
    };
}
 
Example #11
Source File: OpenshiftBuildService.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private void logBuildFailedDetails(OpenShiftClient client, String buildName) {
    try {
        BuildConfig build = client.buildConfigs().withName(buildName).get();
        ObjectReference ref = build.getSpec().getStrategy().getSourceStrategy().getFrom();
        String kind = ref.getKind();
        String name = ref.getName();

        if ("DockerImage".equals(kind)) {
            log.error("Please, ensure that the Docker image '%s' exists and is accessible by OpenShift", name);
        } else if ("ImageStreamTag".equals(kind)) {
            String namespace = ref.getNamespace();
            String namespaceInfo = "current";
            String namespaceParams = "";
            if (namespace != null && !namespace.isEmpty()) {
                namespaceInfo = "'" + namespace + "'";
                namespaceParams = " -n " + namespace;
            }

            log.error("Please, ensure that the ImageStream Tag '%s' exists in the %s namespace (with 'oc get is%s')", name, namespaceInfo, namespaceParams);
        }
    } catch (Exception ex) {
        log.error("Unable to get detailed information from the BuildServiceConfig: " + ex.getMessage());
    }
}
 
Example #12
Source File: BuildConfigOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
public BuildConfigOperationsImpl(BuildConfigOperationContext context) {
  super(context.withApiGroupName(BUILD)
    .withPlural("buildconfigs"));

  this.type = BuildConfig.class;
  this.listType = BuildConfigList.class;
  this.doneableType = DoneableBuildConfig.class;

  this.triggerType = context.getTriggerType();
  this.secret = context.getSecret();
  this.authorName = context.getAuthorName();
  this.authorEmail = context.getAuthorEmail() ;
  this.committerName = context.getCommitterName();
  this.committerEmail = context.getCommitterEmail();
  this.commit = context.getCommit();
  this.message = context.getMessage();
  this.asFile = context.getAsFile();
  this.timeout = context.getTimeout();
  this.timeoutUnit = context.getTimeoutUnit();
}
 
Example #13
Source File: BuildConfigIT.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@After
public void cleanup() throws InterruptedException {
  if (client.buildConfigs().list().getItems().size() != 0) {
    client.buildConfigs().inNamespace(currentNamespace).delete();
  }

  DeleteEntity<BuildConfig> buildConfigDelete = new DeleteEntity<>(BuildConfig.class, client, "bc1", currentNamespace);
  await().atMost(30, TimeUnit.SECONDS).until(buildConfigDelete);
}
 
Example #14
Source File: BuildConfigIT.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void delete() {
  ReadyEntity<BuildConfig> buildConfigReady = new ReadyEntity<>(BuildConfig.class, client, "bc1", currentNamespace);
  await().atMost(30, TimeUnit.SECONDS).until(buildConfigReady);
  boolean bDeleted = client.buildConfigs().inNamespace(currentNamespace).withName("bc1").delete();
  assertTrue(bDeleted);
}
 
Example #15
Source File: BuildConfigIT.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void update() {
  ReadyEntity<BuildConfig> buildConfigReady = new ReadyEntity<>(BuildConfig.class, client, "bc1", currentNamespace);
  buildConfig1 = client.buildConfigs().inNamespace(currentNamespace).withName("bc1").edit()
    .editSpec().withFailedBuildsHistoryLimit(5).endSpec().done();
  await().atMost(30, TimeUnit.SECONDS).until(buildConfigReady);
  assertEquals(5, buildConfig1.getSpec().getFailedBuildsHistoryLimit().intValue());
}
 
Example #16
Source File: BuildConfigIT.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void load() {
  BuildConfig aBuildConfig = client.buildConfigs().inNamespace(currentNamespace)
    .load(getClass().getResourceAsStream("/test-buildconfig.yml")).get();
  assertThat(aBuildConfig).isNotNull();
  assertEquals("ruby-sample-build", aBuildConfig.getMetadata().getName());
}
 
Example #17
Source File: BuildConfigOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Override
protected BuildConfig resource() {
    return new BuildConfigBuilder().withNewMetadata()
            .withNamespace(NAMESPACE)
            .withName(RESOURCE_NAME)
        .endMetadata()
        .withNewSpec()
            .withTriggers(new BuildTriggerPolicy())
        .endSpec().build();
}
 
Example #18
Source File: NewBuildCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    String buildConfigName = buildName.getValue();
    Objects.assertNotNull(buildConfigName, "buildName");
    Map<String, String> labels = BuildConfigs.createBuildLabels(buildConfigName);
    String ouputImageName = imageName.getValue();
    String gitUrlText = getOrFindGitUrl(context, gitUri.getValue());
    String imageText = outputImage.getValue();
    Model mavenModel = getMavenModel(context);
    if (Strings.isNullOrBlank(imageText) && mavenModel != null) {
        imageText = mavenModel.getProperties().getProperty("docker.image");
    }

    String webhookSecretText = webHookSecret.getValue();
    if (Strings.isNullOrBlank(webhookSecretText)) {
        // TODO generate a really good secret!
        webhookSecretText = "secret101";
    }
    BuildConfig buildConfig = BuildConfigs.createBuildConfig(buildConfigName, labels, gitUrlText, ouputImageName, imageText, webhookSecretText);

    System.out.println("Generated BuildConfig: " + toJson(buildConfig));

    ImageStream imageRepository = BuildConfigs.imageRepository(buildConfigName, labels);

    Controller controller = createController();
    controller.applyImageStream(imageRepository, "generated ImageStream: " + toJson(imageRepository));
    controller.applyBuildConfig(buildConfig, "generated BuildConfig: " + toJson(buildConfig));
    return Results.success("Added BuildConfig: " + Builds.getName(buildConfig) + " to OpenShift at master: " + getKubernetes().getMasterUrl());
}
 
Example #19
Source File: BuildConfigs.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static BuildConfig createIntegrationTestBuildConfig(String buildConfigName, Map<String, String> labels, String gitUrlText, String image, List<EnvVar> envVars) {
    BuildConfigBuilder buildConfigBuilder = buildConfigBuilder(buildConfigName, labels);
    BuildConfigSpecBuilder specBuilder = new BuildConfigSpecBuilder();
    addBuildParameterGitSource(specBuilder, gitUrlText);
    if (Strings.isNotBlank(image)) {
        addBuildParameterCustomStrategy(specBuilder, image, envVars);
    }
    return buildConfigBuilder.withSpec(specBuilder.build()).build();
}
 
Example #20
Source File: OpenshiftBuildService.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private BuildConfigSpec getBuildConfigSpec(BuildConfig buildConfig) {
    BuildConfigSpec spec = buildConfig.getSpec();
    if (spec == null) {
        spec = new BuildConfigSpec();
        buildConfig.setSpec(spec);
    }
    return spec;
}
 
Example #21
Source File: ForgeClientAsserts.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public static BuildConfig assertGetBuildConfig(ForgeClient forgeClient, String projectName) throws URISyntaxException, IOException {
    OpenShiftClient openShiftClient = forgeClient.getOpenShiftOrJenkinshiftClient();
    String namespace = forgeClient.getNamespace();
    BuildConfig buildConfig = openShiftClient.buildConfigs().inNamespace(namespace).withName(projectName).get();
    assertThat(buildConfig).describedAs("No BuildConfig found in " + namespace + " called " + projectName).isNotNull();
    return buildConfig;
}
 
Example #22
Source File: TeiidOpenShiftClient.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static Build createBuild(OpenShiftClient client, String namespace, BuildConfig config,
        InputStream tarInputStream) {
    return client.buildConfigs()
            .inNamespace(namespace)
            .withName(config.getMetadata().getName())
            .instantiateBinary().fromInputStream(tarInputStream);
}
 
Example #23
Source File: OpenshiftExtension.java    From dekorate with Apache License 2.0 5 votes vote down vote up
/**
 * Performs the binary build of the specified {@link BuildConfig} with the given binary input.
 * @param buildConfig The build config.
 * @param binaryFile  The binary file.
 */
private void binaryBuild(OpenShiftClient client, BuildConfig buildConfig, File binaryFile) {
  LOGGER.info("Running binary build:"+buildConfig.getMetadata().getName()+ " for:" +binaryFile.getAbsolutePath());
  Build build = client.buildConfigs().withName(buildConfig.getMetadata().getName()).instantiateBinary().fromFile(binaryFile);
  try  (BufferedReader reader = new BufferedReader(client.builds().withName(build.getMetadata().getName()).getLogReader())) {
    for (String line = reader.readLine(); line != null; line = reader.readLine()) {
      System.out.println(line);
    }
  } catch (IOException e) {
    throw DekorateException.launderThrowable(e);
  }
}
 
Example #24
Source File: OpenshiftBuildService.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
protected String updateOrCreateBuildConfig(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, ImageConfiguration imageConfig, String openshiftPullSecret) {
    ImageName imageName = new ImageName(imageConfig.getName());
    String buildName = getS2IBuildName(config, imageName);
    String imageStreamName = getImageStreamName(imageName);
    String outputImageStreamTag = imageStreamName + ":" + (imageName.getTag() != null ? imageName.getTag() : "latest");

    BuildStrategy buildStrategyResource = createBuildStrategy(imageConfig, config.getOpenshiftBuildStrategy(), openshiftPullSecret);
    BuildOutput buildOutput = new BuildOutputBuilder().withNewTo()
            .withKind("ImageStreamTag")
            .withName(outputImageStreamTag)
            .endTo().build();

    // Fetch existing build config
    BuildConfig buildConfig = client.buildConfigs().withName(buildName).get();
    if (buildConfig != null) {
        // lets verify the BC
        BuildConfigSpec spec = getBuildConfigSpec(buildConfig);
        validateSourceType(buildName, spec);

        if (config.getBuildRecreateMode().isBuildConfig()) {
            // Delete and recreate afresh
            client.buildConfigs().withName(buildName).delete();
            return createBuildConfig(builder, buildName, buildStrategyResource, buildOutput);
        } else {
            // Update & return
            return updateBuildConfig(client, buildName, buildStrategyResource, buildOutput, spec);
        }
    } else {
        // Create afresh
        return createBuildConfig(builder, buildName, buildStrategyResource, buildOutput);
    }
}
 
Example #25
Source File: OpenshiftBuildService.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private BuildConfigSpec getBuildConfigSpec(BuildStrategy buildStrategyResource, BuildOutput buildOutput) {
    BuildConfigSpecBuilder specBuilder = null;

    // Check for BuildConfig resource fragment
    File buildConfigResourceFragment = KubernetesHelper.getResourceFragmentFromSource(config.getResourceDir(), config.getResourceConfig() != null ? config.getResourceConfig().getRemotes() : null, "buildconfig.yml", log);
    if (buildConfigResourceFragment != null) {
        BuildConfig buildConfigFragment = client.buildConfigs().load(buildConfigResourceFragment).get();
        specBuilder = new BuildConfigSpecBuilder(buildConfigFragment.getSpec());
    } else {
        specBuilder = new BuildConfigSpecBuilder();
    }

    if (specBuilder.buildSource() == null) {
        specBuilder.withNewSource()
                .withType(DEFAULT_S2I_SOURCE_TYPE)
                .endSource();
    }

    if (specBuilder.buildStrategy() == null) {
        specBuilder.withStrategy(buildStrategyResource);
    }

    if (specBuilder.buildOutput() == null) {
        specBuilder.withOutput(buildOutput);
    }

    Map<String, Map<String, Quantity>> requestsLimitsMap = getRequestsAndLimits();
    if (requestsLimitsMap.containsKey(REQUESTS)) {
        specBuilder.editOrNewResources().addToRequests(requestsLimitsMap.get(REQUESTS)).endResources();
    }
    if (requestsLimitsMap.containsKey(LIMITS)) {
        specBuilder.editOrNewResources().addToLimits(requestsLimitsMap.get(LIMITS)).endResources();
    }
    return specBuilder.build();
}
 
Example #26
Source File: ApplyService.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public void doCreateBuildConfig(BuildConfig entity, String namespace , String sourceName) {
    OpenShiftClient openShiftClient = getOpenShiftClient();
    if (openShiftClient != null) {
        try {
            openShiftClient.buildConfigs().inNamespace(namespace).create(entity);
        } catch (Exception e) {
            onApplyError("Failed to create BuildConfig from " + sourceName + ". " + e, e);
        }
    }
}
 
Example #27
Source File: Sample17Test.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Path sourcePath = SOURCE_DIR_PATH.resolve("hello_world_oc.bal");
    
    // save original source
    Stream<String> lines = Files.lines(sourcePath);
    this.originalSourceContent = lines.collect(Collectors.toList());
    
    // replace placeholders with mocks
    lines = Files.lines(sourcePath);
    List<String> replacedContent = lines.map(line -> line
            .replaceAll("<MINISHIFT_IP>", "192.168.99.131")
            .replaceAll("<MINISHIFT_DOCKER_REGISTRY_IP>", "172.30.1.1:5000"))
            .collect(Collectors.toList());
    Files.write(sourcePath, replacedContent);
    
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_oc.bal"), 0);
    File yamlFile = KUBERNETES_TARGET_PATH.resolve(OPENSHIFT).resolve("hello_world_oc.yaml").toFile();
    Assert.assertTrue(yamlFile.exists());
    List<HasMetadata> k8sItems = KubernetesTestUtils.loadYaml(yamlFile);
    for (HasMetadata data : k8sItems) {
        if ("BuildConfig".equals(data.getKind())) {
            buildConfig = (BuildConfig) data;
        } else if ("ImageStream".equals(data.getKind())) {
            imageStream = (ImageStream) data;
        } else if ("Route".equals(data.getKind())) {
            route = (Route) data;
        }
    }
}
 
Example #28
Source File: SpringBootOnOpenshiftTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveBuildConfig() {
  KubernetesList list = Serialization.unmarshalAsList(getClass().getClassLoader().getResourceAsStream("META-INF/dekorate/openshift.yml"));
  assertNotNull(list);
  DeploymentConfig d = findFirst(list, DeploymentConfig.class).orElseThrow(() -> new IllegalStateException());
  assertNotNull(d);
  BuildConfig b = findFirst(list, BuildConfig.class).orElse(null);
  assertNull(b);
}
 
Example #29
Source File: SpringBootOnOpenshiftTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveBuildConfig() {
  KubernetesList list = Serialization.unmarshalAsList(getClass().getClassLoader().getResourceAsStream("META-INF/dekorate/openshift.yml"));
  assertNotNull(list);
  DeploymentConfig d = findFirst(list, DeploymentConfig.class).orElseThrow(() -> new IllegalStateException());
  assertNotNull(d);
  BuildConfig b = findFirst(list, BuildConfig.class).orElse(null);
  assertNull(b);
}
 
Example #30
Source File: SpringBootOnOpenshiftTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHaveMatchingOutputImageAndTrigger() {
  KubernetesList list = Serialization.unmarshalAsList(getClass().getClassLoader().getResourceAsStream("META-INF/dekorate/openshift.yml"));
  assertNotNull(list);
  DeploymentConfig d = findFirst(list, DeploymentConfig.class).orElseThrow(() -> new IllegalStateException());
  BuildConfig b = findFirst(list, BuildConfig.class).orElseThrow(() -> new IllegalStateException());
  assertNotNull(d);
  assertNotNull(b);
  assertTrue(d.getSpec().getTriggers().stream().filter(t -> t.getImageChangeParams().getFrom().getName().equals(b.getSpec().getOutput().getTo().getName())).findFirst().isPresent());
}