-
Notifications
You must be signed in to change notification settings - Fork 236
fix: handling delete non-active dependent when parent reconcile condition false #3273
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ea84665
fix: handling delete non-active dependent when parent reconcile condi…
csviri 461e78e
Avoiding condition double checking
csviri ad7c9c6
wip
csviri c8440a8
additional unit test
csviri 819b044
add integration test for corner case
csviri 2073e65
test case for reported issue
csviri 79a2b2f
wip
csviri add22fd
wip
csviri fa65d4d
wip
csviri 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
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
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
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
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
39 changes: 39 additions & 0 deletions
39
...atorsdk/operator/workflow/onedependentactivationcondition/ConfigMapDependentResource.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,39 @@ | ||
| /* | ||
| * 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.workflow.onedependentactivationcondition; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.ConfigMap; | ||
| import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
| import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; | ||
|
|
||
| public class ConfigMapDependentResource | ||
| extends CRUDKubernetesDependentResource< | ||
| ConfigMap, OneDependentActivationConditionCustomResource> { | ||
|
|
||
| @Override | ||
| protected ConfigMap desired( | ||
| OneDependentActivationConditionCustomResource primary, | ||
| Context<OneDependentActivationConditionCustomResource> context) { | ||
| ConfigMap configMap = new ConfigMap(); | ||
| configMap.setMetadata( | ||
| new ObjectMetaBuilder() | ||
| .withName(primary.getMetadata().getName()) | ||
| .withNamespace(primary.getMetadata().getNamespace()) | ||
| .build()); | ||
| return configMap; | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...eratorsdk/operator/workflow/onedependentactivationcondition/FalseActivationCondition.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,32 @@ | ||
| /* | ||
| * 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.workflow.onedependentactivationcondition; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.ConfigMap; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
| import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; | ||
| import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; | ||
|
|
||
| public class FalseActivationCondition | ||
| implements Condition<ConfigMap, OneDependentActivationConditionCustomResource> { | ||
| @Override | ||
| public boolean isMet( | ||
| DependentResource<ConfigMap, OneDependentActivationConditionCustomResource> dependentResource, | ||
| OneDependentActivationConditionCustomResource primary, | ||
| Context<OneDependentActivationConditionCustomResource> context) { | ||
| return false; | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...rkflow/onedependentactivationcondition/OneDependentActivationConditionCustomResource.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,28 @@ | ||
| /* | ||
| * 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.workflow.onedependentactivationcondition; | ||
|
|
||
| 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.ShortNames; | ||
| import io.fabric8.kubernetes.model.annotation.Version; | ||
|
|
||
| @Group("sample.javaoperatorsdk") | ||
| @Version("v1") | ||
| @ShortNames("odac") | ||
| public class OneDependentActivationConditionCustomResource extends CustomResource<Void, Void> | ||
| implements Namespaced {} |
62 changes: 62 additions & 0 deletions
62
.../operator/workflow/onedependentactivationcondition/OneDependentActivationConditionIT.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,62 @@ | ||
| /* | ||
| * 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.workflow.onedependentactivationcondition; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| import io.fabric8.kubernetes.api.model.ConfigMap; | ||
| import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
| import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.awaitility.Awaitility.await; | ||
|
|
||
| class OneDependentActivationConditionIT { | ||
|
|
||
| public static final String TEST_RESOURCE_NAME = "test1"; | ||
|
|
||
| @RegisterExtension | ||
| LocallyRunOperatorExtension extension = | ||
| LocallyRunOperatorExtension.builder() | ||
| .withReconciler(OneDependentActivationConditionReconciler.class) | ||
| .build(); | ||
|
|
||
| @Test | ||
| void handlesOnlyNonActiveDependent() { | ||
| extension.create(testResource()); | ||
|
|
||
| await() | ||
| .untilAsserted( | ||
| () -> { | ||
| assertThat( | ||
| extension | ||
| .getReconcilerOfType(OneDependentActivationConditionReconciler.class) | ||
| .getNumberOfReconciliationExecution()) | ||
| .isPositive(); | ||
| }); | ||
|
|
||
| // ConfigMap should not be created since the activation condition is false | ||
| var cm = extension.get(ConfigMap.class, TEST_RESOURCE_NAME); | ||
| assertThat(cm).isNull(); | ||
| } | ||
|
|
||
| private OneDependentActivationConditionCustomResource testResource() { | ||
| var res = new OneDependentActivationConditionCustomResource(); | ||
| res.setMetadata(new ObjectMetaBuilder().withName(TEST_RESOURCE_NAME).build()); | ||
| return res; | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
...r/workflow/onedependentactivationcondition/OneDependentActivationConditionReconciler.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,50 @@ | ||
| /* | ||
| * 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.workflow.onedependentactivationcondition; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
| import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Reconciler; | ||
| import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; | ||
| import io.javaoperatorsdk.operator.api.reconciler.Workflow; | ||
| import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; | ||
|
|
||
| @Workflow( | ||
| dependents = { | ||
| @Dependent( | ||
| type = ConfigMapDependentResource.class, | ||
| activationCondition = FalseActivationCondition.class) | ||
| }) | ||
| @ControllerConfiguration | ||
| public class OneDependentActivationConditionReconciler | ||
| implements Reconciler<OneDependentActivationConditionCustomResource> { | ||
|
|
||
| private final AtomicInteger numberOfReconciliationExecution = new AtomicInteger(0); | ||
|
|
||
| @Override | ||
| public UpdateControl<OneDependentActivationConditionCustomResource> reconcile( | ||
| OneDependentActivationConditionCustomResource resource, | ||
| Context<OneDependentActivationConditionCustomResource> context) { | ||
| numberOfReconciliationExecution.incrementAndGet(); | ||
| return UpdateControl.noUpdate(); | ||
| } | ||
|
|
||
| public int getNumberOfReconciliationExecution() { | ||
| return numberOfReconciliationExecution.get(); | ||
| } | ||
| } |
Oops, something went wrong.
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.