Skip to content

Commit 553a032

Browse files
manusaclaude
andauthored
test(openshift): add recreate mode with BuildConfig fragment test
Verifies that when using openshiftBuildRecreateMode=buildConfig with a buildconfig.yml resource fragment, the fragment is loaded locally from the filesystem after the existing BuildConfig is deleted, rather than attempting to fetch it from the cluster. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Marc Nuri <marc@marcnuri.com>
1 parent 4d0217e commit 553a032

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/openshift/OpenshiftBuildServiceIntegrationTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,57 @@ void build_withBuildConfigFragment_shouldMergeFragmentSpec() throws Exception {
712712
});
713713
}
714714

715+
@Test
716+
@DisplayName("build with recreateMode=buildConfig and fragment should load fragment locally after delete")
717+
void build_withRecreateModeBuildConfigAndFragment_shouldLoadFragmentLocallyAfterDelete() throws Exception {
718+
// Given - create a buildconfig.yml fragment
719+
final File resourceDir = Files.createDirectories(baseDirectory.toPath().resolve("src/main/jkube")).toFile();
720+
final String fragmentContent = "apiVersion: build.openshift.io/v1\n" +
721+
"kind: BuildConfig\n" +
722+
"spec:\n" +
723+
" runPolicy: SerialLatestOnly\n" +
724+
" resources:\n" +
725+
" requests:\n" +
726+
" cpu: \"500m\"\n" +
727+
" memory: \"512Mi\"\n";
728+
Files.write(resourceDir.toPath().resolve("buildconfig.yml"), fragmentContent.getBytes(StandardCharsets.UTF_8));
729+
730+
image = image.toBuilder()
731+
.build(image.getBuild().toBuilder()
732+
.openshiftBuildRecreateMode(BuildRecreateMode.buildConfig)
733+
.build())
734+
.build();
735+
withBuildServiceConfig(defaultConfig.resourceDir(resourceDir).build());
736+
final WebServerEventCollector collector = MockServerSetup.forServer(mockServer)
737+
.resourceName(projectName)
738+
.buildConfigSuffix("-s2i-suffix-configured-in-image")
739+
.buildConfigExists(true) // Existing BuildConfig that will be deleted
740+
.imageStreamExists(true)
741+
.recreateMode(BuildRecreateMode.buildConfig)
742+
.configure();
743+
744+
// When
745+
new OpenshiftBuildService(jKubeServiceHub).build(image);
746+
747+
// Then - fragment should be merged after delete (no API call to fetch deleted resource)
748+
collector.assertEventsRecordedInOrder("build-config-check", "build-config-delete", "new-build-config", "pushed");
749+
collector.assertEventsNotRecorded("patch-build-config");
750+
// Body indices: 0=build-config-check, 1=build-config-delete, 2=imagestream-check, 3=new-build-config
751+
assertThat(Serialization.unmarshal(collector.getBodies().get(3), BuildConfig.class))
752+
.hasFieldOrPropertyWithValue("metadata.name", "myapp-s2i-suffix-configured-in-image")
753+
.extracting(BuildConfig::getSpec)
754+
.satisfies(spec -> {
755+
// Fragment-specified fields should be present
756+
assertThat(spec.getRunPolicy()).isEqualTo("SerialLatestOnly");
757+
assertThat(spec.getResources().getRequests())
758+
.containsEntry("cpu", Quantity.parse("500m"))
759+
.containsEntry("memory", Quantity.parse("512Mi"));
760+
// Generated fields should also be present
761+
assertThat(spec.getOutput().getTo().getKind()).isEqualTo("ImageStreamTag");
762+
assertThat(spec.getStrategy().getType()).isEqualTo("Source");
763+
});
764+
}
765+
715766
@Test
716767
@DisplayName("build with DockerImage output kind should not create ImageStream")
717768
void successfulDockerImageOutputBuild() throws Exception {

0 commit comments

Comments
 (0)