io.fabric8.openshift.api.model.BuildConfigBuilder Java Examples
The following examples show how to use
io.fabric8.openshift.api.model.BuildConfigBuilder.
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: BuildConfigs.java From fabric8-forge with Apache License 2.0 | 6 votes |
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 #2
Source File: BuildConfigCrudTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@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 #3
Source File: BuildConfigTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@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 #4
Source File: BuildConfigTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testDelete() { server.expect().withPath("/apis/build.openshift.io/v1/namespaces/test/buildconfigs/bc1").andReturn(200, new BuildConfigBuilder().withNewMetadata().withName("bc1").and().build()).once(); server.expect().withPath("/apis/build.openshift.io/v1/namespaces/test/builds?labelSelector=openshift.io%2Fbuild-config.name%3Dbc1").andReturn( 200, new BuildListBuilder().build()).once(); server.expect().withPath("/apis/build.openshift.io/v1/namespaces/ns1/buildconfigs/bc2").andReturn( 200, new BuildConfigBuilder().withNewMetadata().withName("bc2").and().build()).once(); server.expect().withPath("/apis/build.openshift.io/v1/namespaces/ns1/builds?labelSelector=openshift.io%2Fbuild-config.name%3Dbc2").andReturn( 200, new BuildListBuilder().build()).once(); OpenShiftClient client = server.getOpenshiftClient(); Boolean deleted = client.buildConfigs().withName("bc1").delete(); assertNotNull(deleted); deleted = client.buildConfigs().withName("bc2").delete(); assertFalse(deleted); deleted = client.buildConfigs().inNamespace("ns1").withName("bc2").delete(); assertTrue(deleted); }
Example #5
Source File: OpenshiftBuildService.java From jkube with Eclipse Public License 2.0 | 5 votes |
private String createBuildConfig(KubernetesListBuilder builder, String buildName, BuildStrategy buildStrategyResource, BuildOutput buildOutput) { log.info("Creating BuildServiceConfig %s for %s build", buildName, buildStrategyResource.getType()); builder.addToItems(new BuildConfigBuilder() .withNewMetadata() .withName(buildName) .endMetadata() .withSpec(getBuildConfigSpec(buildStrategyResource, buildOutput)) .build() ); return buildName; }
Example #6
Source File: BuildConfigs.java From fabric8-forge with Apache License 2.0 | 5 votes |
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 #7
Source File: BuildConfigOperatorTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override protected BuildConfig resource() { return new BuildConfigBuilder().withNewMetadata() .withNamespace(NAMESPACE) .withName(RESOURCE_NAME) .endMetadata() .withNewSpec() .withTriggers(new BuildTriggerPolicy()) .endSpec().build(); }
Example #8
Source File: KubernetesOperationTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testDeleteWithAdapt() { server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers/rc1").andReturn(200, new ReplicationControllerBuilder().build()).once(); server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, new PodBuilder().build()).once(); server.expect().withPath("/apis").andReturn(200, new APIGroupListBuilder() .addNewGroup() .withApiVersion("v1") .withName("autoscaling.k8s.io") .endGroup() .addNewGroup() .withApiVersion("v1") .withName("security.openshift.io") .endGroup() .build()).once(); server.expect().withPath("/apis/build.openshift.io/v1/namespaces/test/buildconfigs/bc1").andReturn(200, new BuildConfigBuilder().build()).once(); server.expect().withPath("/api/v1/namespaces/test/pods/pod1").andReturn(200, new PodBuilder().build()).once(); try (KubernetesClient client = server.getKubernetesClient()) { Boolean deleted = client.replicationControllers().withName("rc1").cascading(false).delete(); assertTrue(deleted); deleted = client.pods().withName("pod1").cascading(false).delete(); assertTrue(deleted); OpenShiftClient oclient = client.adapt(OpenShiftClient.class); deleted = oclient.buildConfigs().withName("bc1").cascading(false).delete(); assertTrue(deleted); deleted = oclient.pods().withName("pod1").cascading(false).delete(); assertTrue(deleted); } }
Example #9
Source File: MetadataVisitor.java From jkube with Eclipse Public License 2.0 | 4 votes |
@Override protected ObjectMeta getOrCreateMetadata(BuildConfigBuilder item) { return addEmptyLabelsAndAnnotations(item::hasMetadata, item::withNewMetadata, item::editMetadata, item::buildMetadata) .endMetadata().buildMetadata(); }
Example #10
Source File: OpenShiftBuildConfigHandler.java From module-ballerina-kubernetes with Apache License 2.0 | 4 votes |
private void generate(OpenShiftBuildExtensionModel buildConfigModel) throws KubernetesPluginException { try { buildConfigModel.setLabels(new LinkedHashMap<>()); if (null != buildConfigModel.getLabels() && !buildConfigModel.getLabels().containsKey("build")) { buildConfigModel.getLabels().put("build", buildConfigModel.getName()); } // Generate docker artifacts Path dockerOutputDir = dataHolder.getDockerArtifactOutputPath().resolve("Dockerfile"); DockerImageName dockerImageName = new DockerImageName(dataHolder.getDockerModel().getName()); BuildConfig bc = new BuildConfigBuilder() .withNewMetadata() .withName(buildConfigModel.getName()) .withLabels(buildConfigModel.getLabels()) .withAnnotations(buildConfigModel.getAnnotations()) .withNamespace(dataHolder.getNamespace()) .endMetadata() .withNewSpec() .withNewOutput() .withNewTo() .withKind("ImageStreamTag") .withName(dockerImageName.getRepository() + ":" + dockerImageName.getTag()) .endTo() .endOutput() .withNewSource() .withNewBinary() .endBinary() .endSource() .withNewStrategy() .withNewDockerStrategy() .withDockerfilePath(dataHolder.getUberJarPath().getParent().relativize(dockerOutputDir).toString()) .withForcePull(buildConfigModel.isForcePullDockerImage()) .withNoCache(buildConfigModel.isBuildDockerWithNoCache()) .endDockerStrategy() .endStrategy() .endSpec() .build(); String resourceQuotaContent = SerializationUtils.dumpWithoutRuntimeStateAsYaml(bc); KubernetesUtils.writeToFile(dataHolder.getK8sArtifactOutputPath().resolve(OPENSHIFT), resourceQuotaContent, OPENSHIFT_BUILD_CONFIG_FILE_POSTFIX + YAML); // Modify instructions } catch (IOException e) { String errorMessage = "error while generating OpenShift Build Config yaml file: " + buildConfigModel.getName(); throw new KubernetesPluginException(errorMessage, e); } }
Example #11
Source File: AddBuildConfigResourceDecorator.java From dekorate with Apache License 2.0 | 4 votes |
public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); String repository = Images.getRepository(config.getBuilderImage()); String builderRepository = Images.getRepository(config.getBuilderImage()); String builderTag = Images.getTag(config.getBuilderImage()); String builderName = !builderRepository.contains("/") ? builderRepository : builderRepository.substring(builderRepository.lastIndexOf("/") + 1); //First we need to consult the labels String fallbackVersion = Strings.isNotNullOrEmpty(config.getVersion()) ? config.getVersion() : LATEST; String version = meta.getLabels().getOrDefault(Labels.VERSION, fallbackVersion); list.addToItems(new BuildConfigBuilder() .withNewMetadata() .withName(config.getName()) .withLabels(meta.getLabels()) .endMetadata() .withNewSpec() .withNewOutput() .withNewTo() .withKind(IMAGESTREAMTAG) .withName(config.getName() + ":" + version) .endTo() .endOutput() .withNewSource() .withNewBinary() .endBinary() .endSource() .withNewStrategy() .withNewSourceStrategy() .withEnv() .withNewFrom() .withKind(IMAGESTREAMTAG) .withName(builderName + ":" + builderTag) .endFrom() .endSourceStrategy() .endStrategy() .endSpec()); }
Example #12
Source File: BuildConfigs.java From fabric8-forge with Apache License 2.0 | 4 votes |
public static BuildConfigBuilder buildConfigBuilder(String buildName, Map<String, String> labels) { return new BuildConfigBuilder(). withNewMetadata().withLabels(labels).withName(buildName).endMetadata(); }
Example #13
Source File: KafkaConnectS2ICluster.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
/** * 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(KafkaConnectS2IResources.buildConfigName(cluster)) .withLabels(getLabelsWithStrimziName(name, null).toMap()) .withNamespace(namespace) .withOwnerReferences(createOwnerReference()) .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() .withScripts("image:///opt/kafka/s2i") .withNewFrom() .withKind("ImageStreamTag") .withName(KafkaConnectS2IResources.sourceImageStreamName(cluster) + ":" + sourceImageTag) .endFrom() .endSourceStrategy() .endStrategy() .withTriggers(triggerConfigChange, triggerImageChange) .withSuccessfulBuildsHistoryLimit(5) .withFailedBuildsHistoryLimit(5) .withResources(buildRequirements) .endSpec() .build(); return build; }
Example #14
Source File: BuildConfigIT.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Before public void init() { currentNamespace = session.getNamespace(); buildConfig1 = new BuildConfigBuilder() .withNewMetadata().withName("bc1").endMetadata() .withNewSpec() .addNewTrigger() .withType("GitHub") .withNewGithub() .withSecret("secret101") .endGithub() .endTrigger() .addNewTrigger() .withType("Generic") .withNewGeneric() .withSecret("secret101") .endGeneric() .endTrigger() .addNewTrigger() .withType("ImageChange") .endTrigger() .withNewSource() .withType("Git") .withNewGit() .withUri("https://github.com/openshift/ruby-hello-world") .endGit() .withDockerfile("FROM openshift/ruby-22-centos7\\nUSER example") .endSource() .withNewStrategy() .withType("Source") .withNewSourceStrategy() .withNewFrom() .withKind("ImageStreamTag") .withName("origin-ruby-sample:latest") .endFrom() .endSourceStrategy() .endStrategy() .withNewOutput() .withNewTo() .withKind("ImageStreamTag") .withName("origin-ruby-sample:latest") .endTo() .endOutput() .withNewPostCommit() .withScript("bundle exec rake test") .endPostCommit() .endSpec() .build(); client.buildConfigs().inNamespace(currentNamespace).createOrReplace(buildConfig1); }