-
Notifications
You must be signed in to change notification settings - Fork 218
fix: condition for bulk resources #1688
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 3 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
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
.../test/java/io/javaoperatorsdk/operator/bulkdependent/BulkDependentWithPreconditionIT.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 @@ | ||
package io.javaoperatorsdk.operator.bulkdependent; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; | ||
import io.javaoperatorsdk.operator.sample.bulkdependent.ManagedBulkDependentWithPreconditionReconciler; | ||
|
||
import static io.javaoperatorsdk.operator.bulkdependent.BulkDependentTestBase.INITIAL_NUMBER_OF_CONFIG_MAPS; | ||
import static io.javaoperatorsdk.operator.bulkdependent.BulkDependentTestBase.testResource; | ||
import static io.javaoperatorsdk.operator.sample.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_KEY; | ||
import static io.javaoperatorsdk.operator.sample.bulkdependent.ConfigMapDeleterBulkDependentResource.LABEL_VALUE; | ||
import static org.assertj.core.api.Assertions.*; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
class BulkDependentWithPreconditionIT { | ||
|
||
@RegisterExtension | ||
LocallyRunOperatorExtension extension = | ||
LocallyRunOperatorExtension.builder() | ||
.withReconciler(new ManagedBulkDependentWithPreconditionReconciler()) | ||
.build(); | ||
|
||
@Test | ||
void handlesBulkDependentWithPrecondition() { | ||
var resource = testResource(); | ||
extension.create(resource); | ||
|
||
await().untilAsserted(() -> { | ||
var cms = extension.getKubernetesClient().configMaps().inNamespace(extension.getNamespace()) | ||
.withLabel(LABEL_KEY, LABEL_VALUE) | ||
.list().getItems(); | ||
assertThat(cms).hasSize(INITIAL_NUMBER_OF_CONFIG_MAPS); | ||
}); | ||
} | ||
|
||
|
||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...atorsdk/operator/sample/bulkdependent/ManagedBulkDependentWithPreconditionReconciler.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,29 @@ | ||
package io.javaoperatorsdk.operator.sample.bulkdependent; | ||
|
||
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.dependent.Dependent; | ||
|
||
@ControllerConfiguration(dependents = @Dependent(reconcilePrecondition = SamplePrecondition.class, | ||
type = CRUDConfigMapBulkDependentResource.class)) | ||
public class ManagedBulkDependentWithPreconditionReconciler | ||
implements Reconciler<BulkDependentTestCustomResource> { | ||
|
||
private final AtomicInteger numberOfExecutions = new AtomicInteger(0); | ||
|
||
@Override | ||
public UpdateControl<BulkDependentTestCustomResource> reconcile( | ||
BulkDependentTestCustomResource resource, | ||
Context<BulkDependentTestCustomResource> context) throws Exception { | ||
numberOfExecutions.incrementAndGet(); | ||
return UpdateControl.noUpdate(); | ||
} | ||
|
||
public int getNumberOfExecutions() { | ||
return numberOfExecutions.get(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...rk/src/test/java/io/javaoperatorsdk/operator/sample/bulkdependent/SamplePrecondition.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,19 @@ | ||
package io.javaoperatorsdk.operator.sample.bulkdependent; | ||
|
||
import java.util.Map; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition; | ||
|
||
public class SamplePrecondition | ||
implements Condition<Map<String, ConfigMap>, BulkDependentTestCustomResource> { | ||
|
||
public static final String SKIP_RESOURCE_DATA = "skipThis"; | ||
|
||
@Override | ||
public boolean isMet(BulkDependentTestCustomResource primary, Map<String, ConfigMap> secondary, | ||
Context<BulkDependentTestCustomResource> context) { | ||
return !SKIP_RESOURCE_DATA.equals(primary.getSpec().getAdditionalData()); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't work because
R
can never be aMap
in aDependentResource
declaration so this should most likely cause aClassCastException
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That thing does not get into the bytecode, but also there is a test for this in the PR. Will try to make it more nice though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked but this is still the simplest way to do locally, this will change probably within this issue:
#1689
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will improve this sample so it shows more the issue with the Bulk resources.