|
| 1 | +package io.javaoperatorsdk.operator.baseapi.ssaissue.finalizer; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 7 | + |
| 8 | +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; |
| 9 | +import io.fabric8.kubernetes.client.dsl.base.PatchContext; |
| 10 | +import io.fabric8.kubernetes.client.dsl.base.PatchType; |
| 11 | +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; |
| 12 | + |
| 13 | +import static org.assertj.core.api.Assertions.assertThat; |
| 14 | +import static org.awaitility.Awaitility.await; |
| 15 | + |
| 16 | +class SSAFinalizerIssueIT { |
| 17 | + |
| 18 | + public static final String TEST_1 = "test1"; |
| 19 | + |
| 20 | + @RegisterExtension |
| 21 | + LocallyRunOperatorExtension extension = |
| 22 | + LocallyRunOperatorExtension.builder() |
| 23 | + .withReconciler(new SSAFinalizerIssueReconciler()) |
| 24 | + .build(); |
| 25 | + |
| 26 | + /** |
| 27 | + * Showcases possibly a case with SSA: When the resource is created with the same field manager |
| 28 | + * that used by the controller, when adding a finalizer, it deletes other parts of the spec. |
| 29 | + */ |
| 30 | + @Test |
| 31 | + void addingFinalizerRemoveListValues() { |
| 32 | + var fieldManager = |
| 33 | + extension |
| 34 | + .getRegisteredControllerForReconcile(SSAFinalizerIssueReconciler.class) |
| 35 | + .getConfiguration() |
| 36 | + .fieldManager(); |
| 37 | + |
| 38 | + extension |
| 39 | + .getKubernetesClient() |
| 40 | + .resource(testResource()) |
| 41 | + .inNamespace(extension.getNamespace()) |
| 42 | + .patch( |
| 43 | + new PatchContext.Builder() |
| 44 | + .withFieldManager(fieldManager) |
| 45 | + .withForce(true) |
| 46 | + .withPatchType(PatchType.SERVER_SIDE_APPLY) |
| 47 | + .build()); |
| 48 | + |
| 49 | + await() |
| 50 | + .untilAsserted( |
| 51 | + () -> { |
| 52 | + var actual = extension.get(SSAFinalizerIssueCustomResource.class, TEST_1); |
| 53 | + assertThat(actual.getFinalizers()).hasSize(1); |
| 54 | + assertThat(actual.getSpec()).isNull(); |
| 55 | + }); |
| 56 | + } |
| 57 | + |
| 58 | + SSAFinalizerIssueCustomResource testResource() { |
| 59 | + var res = new SSAFinalizerIssueCustomResource(); |
| 60 | + res.setMetadata(new ObjectMetaBuilder().withName(TEST_1).build()); |
| 61 | + res.setSpec(new SSAFinalizerIssueSpec()); |
| 62 | + res.getSpec().setValue("val"); |
| 63 | + res.getSpec().setList(List.of("val1", "val2")); |
| 64 | + return res; |
| 65 | + } |
| 66 | +} |
0 commit comments