-
Notifications
You must be signed in to change notification settings - Fork 240
test: integration test for finalizer adding without SSA #3487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
csviri
wants to merge
1
commit into
operator-framework:main
Choose a base branch
from
csviri:finalizer-no-ssa-it
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...a/io/javaoperatorsdk/operator/baseapi/finalizernossa/AddFinalizerNoSSACustomResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright Java Operator SDK Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.javaoperatorsdk.operator.baseapi.finalizernossa; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.Namespaced; | ||
| import io.fabric8.kubernetes.client.CustomResource; | ||
| import io.fabric8.kubernetes.model.annotation.Group; | ||
| import io.fabric8.kubernetes.model.annotation.Kind; | ||
| import io.fabric8.kubernetes.model.annotation.ShortNames; | ||
| import io.fabric8.kubernetes.model.annotation.Version; | ||
|
|
||
| @Group("sample.javaoperatorsdk") | ||
| @Version("v1") | ||
| @Kind("AddFinalizerNoSSACustomResource") | ||
| @ShortNames("afnossa") | ||
| public class AddFinalizerNoSSACustomResource extends CustomResource<Void, String> | ||
| implements Namespaced {} |
73 changes: 73 additions & 0 deletions
73
...src/test/java/io/javaoperatorsdk/operator/baseapi/finalizernossa/AddFinalizerNoSSAIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright Java Operator SDK Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.javaoperatorsdk.operator.baseapi.finalizernossa; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
| import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.awaitility.Awaitility.await; | ||
|
|
||
| class AddFinalizerNoSSAIT { | ||
|
|
||
| public static final String TEST_RESOURCE_NAME = "add-finalizer-no-ssa-test1"; | ||
|
|
||
| @RegisterExtension | ||
| LocallyRunOperatorExtension operator = | ||
| LocallyRunOperatorExtension.builder() | ||
| .withConfigurationService(o -> o.withUseSSAToPatchPrimaryResource(false)) | ||
| .withReconciler(new AddFinalizerNoSSAReconciler()) | ||
| .build(); | ||
|
|
||
| @Test | ||
| void addsFinalizerWithoutSSAAndRemovesItOnCleanup() { | ||
| var reconciler = operator.getReconcilerOfType(AddFinalizerNoSSAReconciler.class); | ||
|
|
||
| var testResource = createTestResource(); | ||
| operator.create(testResource); | ||
|
|
||
| await("finalizer added") | ||
| .atMost(5, TimeUnit.SECONDS) | ||
| .untilAsserted( | ||
| () -> { | ||
| var actual = operator.get(AddFinalizerNoSSACustomResource.class, TEST_RESOURCE_NAME); | ||
| assertThat(actual).isNotNull(); | ||
| assertThat(actual.getMetadata().getFinalizers()).hasSize(1); | ||
| }); | ||
|
|
||
| operator.delete(testResource); | ||
|
|
||
| await("resource deleted after finalizer removal") | ||
| .atMost(5, TimeUnit.SECONDS) | ||
| .until( | ||
| () -> operator.get(AddFinalizerNoSSACustomResource.class, TEST_RESOURCE_NAME) == null); | ||
|
|
||
| assertThat(reconciler.getNumberOfExecutions()).isEqualTo(1); | ||
| assertThat(reconciler.getNumberOfCleanupExecutions()).isEqualTo(1); | ||
| } | ||
|
|
||
| private AddFinalizerNoSSACustomResource createTestResource() { | ||
| AddFinalizerNoSSACustomResource cr = new AddFinalizerNoSSACustomResource(); | ||
| cr.setMetadata(new ObjectMeta()); | ||
| cr.getMetadata().setName(TEST_RESOURCE_NAME); | ||
| return cr; | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
.../java/io/javaoperatorsdk/operator/baseapi/finalizernossa/AddFinalizerNoSSAReconciler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright Java Operator SDK Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.javaoperatorsdk.operator.baseapi.finalizernossa; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| import io.javaoperatorsdk.operator.api.reconciler.*; | ||
| import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; | ||
|
|
||
| @ControllerConfiguration | ||
| public class AddFinalizerNoSSAReconciler | ||
| implements Reconciler<AddFinalizerNoSSACustomResource>, | ||
| Cleaner<AddFinalizerNoSSACustomResource>, | ||
| TestExecutionInfoProvider { | ||
|
|
||
| private final AtomicInteger numberOfExecutions = new AtomicInteger(0); | ||
| private final AtomicInteger numberOfCleanupExecutions = new AtomicInteger(0); | ||
|
|
||
| @Override | ||
| public UpdateControl<AddFinalizerNoSSACustomResource> reconcile( | ||
| AddFinalizerNoSSACustomResource resource, Context<AddFinalizerNoSSACustomResource> context) { | ||
| numberOfExecutions.addAndGet(1); | ||
| return UpdateControl.noUpdate(); | ||
| } | ||
|
|
||
| @Override | ||
| public DeleteControl cleanup( | ||
| AddFinalizerNoSSACustomResource resource, Context<AddFinalizerNoSSACustomResource> context) { | ||
| numberOfCleanupExecutions.addAndGet(1); | ||
| return DeleteControl.defaultDelete(); | ||
| } | ||
|
|
||
| public int getNumberOfExecutions() { | ||
| return numberOfExecutions.get(); | ||
| } | ||
|
|
||
| public int getNumberOfCleanupExecutions() { | ||
| return numberOfCleanupExecutions.get(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.