-
Notifications
You must be signed in to change notification settings - Fork 220
improve: blocklist of problematic resources for previous version annotation #2774
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5e80d98
feat: blacklist of problematic resources for previous version annotation
csviri f7ba067
rename to blocklist, added javadocs
csviri 3b147fe
wip
csviri 0aefb56
remove deamonSet since was not able to reproduce the behavior
csviri 74c13ff
Add integration test
csviri 7a1902b
explanation and using Set instead of list
csviri e31793c
fix: improve javadoc
metacosm 19ce185
refactor: rename so that relation between methods is more explicit
metacosm 7639330
naming
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
95 changes: 95 additions & 0 deletions
95
...rc/test/java/io/javaoperatorsdk/operator/dependent/prevblocklist/DeploymentDependent.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,95 @@ | ||
package io.javaoperatorsdk.operator.dependent.prevblocklist; | ||
|
||
import java.util.Map; | ||
|
||
import io.fabric8.kubernetes.api.model.ContainerBuilder; | ||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.LabelSelectorBuilder; | ||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.fabric8.kubernetes.api.model.PodSpecBuilder; | ||
import io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder; | ||
import io.fabric8.kubernetes.api.model.Quantity; | ||
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder; | ||
import io.fabric8.kubernetes.api.model.apps.DeploymentSpecBuilder; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.GenericKubernetesResourceMatcher; | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent; | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.SSABasedGenericKubernetesResourceMatcher; | ||
|
||
@KubernetesDependent | ||
public class DeploymentDependent | ||
extends CRUDKubernetesDependentResource<Deployment, PrevAnnotationBlockCustomResource> { | ||
|
||
public static final String RESOURCE_NAME = "test1"; | ||
|
||
public DeploymentDependent() { | ||
super(Deployment.class); | ||
} | ||
|
||
@Override | ||
protected Deployment desired( | ||
PrevAnnotationBlockCustomResource primary, | ||
Context<PrevAnnotationBlockCustomResource> context) { | ||
|
||
return new DeploymentBuilder() | ||
.withMetadata( | ||
new ObjectMetaBuilder() | ||
.withName(primary.getMetadata().getName()) | ||
.withNamespace(primary.getMetadata().getNamespace()) | ||
.build()) | ||
.withSpec( | ||
new DeploymentSpecBuilder() | ||
.withReplicas(1) | ||
.withSelector( | ||
new LabelSelectorBuilder().withMatchLabels(Map.of("app", "nginx")).build()) | ||
.withTemplate( | ||
new PodTemplateSpecBuilder() | ||
.withMetadata( | ||
new ObjectMetaBuilder().withLabels(Map.of("app", "nginx")).build()) | ||
.withSpec( | ||
new PodSpecBuilder() | ||
.withContainers( | ||
new ContainerBuilder() | ||
.withName("nginx") | ||
.withImage("nginx:1.14.2") | ||
.withResources( | ||
new ResourceRequirementsBuilder() | ||
.withLimits(Map.of("cpu", new Quantity("2000m"))) | ||
.build()) | ||
.build()) | ||
.build()) | ||
.build()) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
// for testing purposes replicating the matching logic but with the special matcher | ||
@Override | ||
public Result<Deployment> match( | ||
Deployment actualResource, | ||
Deployment desired, | ||
PrevAnnotationBlockCustomResource primary, | ||
Context<PrevAnnotationBlockCustomResource> context) { | ||
final boolean matches; | ||
addMetadata(true, actualResource, desired, primary, context); | ||
if (useSSA(context)) { | ||
matches = new SSAMatcherWithoutSanitization().matches(actualResource, desired, context); | ||
} else { | ||
matches = | ||
GenericKubernetesResourceMatcher.match(desired, actualResource, false, false, context) | ||
.matched(); | ||
} | ||
return Result.computed(matches, desired); | ||
} | ||
|
||
// using this matcher, so we are able to reproduce issue with resource limits | ||
static class SSAMatcherWithoutSanitization<R extends HasMetadata> | ||
extends SSABasedGenericKubernetesResourceMatcher<R> { | ||
|
||
@Override | ||
protected void sanitizeState(R actual, R desired, Map<String, Object> actualMap) {} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...o/javaoperatorsdk/operator/dependent/prevblocklist/PrevAnnotationBlockCustomResource.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,13 @@ | ||
package io.javaoperatorsdk.operator.dependent.prevblocklist; | ||
|
||
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("pabc") | ||
public class PrevAnnotationBlockCustomResource extends CustomResource<PrevAnnotationBlockSpec, Void> | ||
implements Namespaced {} |
34 changes: 34 additions & 0 deletions
34
...va/io/javaoperatorsdk/operator/dependent/prevblocklist/PrevAnnotationBlockReconciler.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,34 @@ | ||
package io.javaoperatorsdk.operator.dependent.prevblocklist; | ||
|
||
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; | ||
import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider; | ||
|
||
@Workflow(dependents = {@Dependent(type = DeploymentDependent.class)}) | ||
@ControllerConfiguration() | ||
public class PrevAnnotationBlockReconciler | ||
implements Reconciler<PrevAnnotationBlockCustomResource>, TestExecutionInfoProvider { | ||
|
||
private final AtomicInteger numberOfExecutions = new AtomicInteger(0); | ||
|
||
public PrevAnnotationBlockReconciler() {} | ||
|
||
@Override | ||
public UpdateControl<PrevAnnotationBlockCustomResource> reconcile( | ||
PrevAnnotationBlockCustomResource resource, | ||
Context<PrevAnnotationBlockCustomResource> context) { | ||
numberOfExecutions.getAndIncrement(); | ||
|
||
return UpdateControl.noUpdate(); | ||
} | ||
|
||
public int getNumberOfExecutions() { | ||
return numberOfExecutions.get(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../io/javaoperatorsdk/operator/dependent/prevblocklist/PrevAnnotationBlockReconcilerIT.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 @@ | ||
package io.javaoperatorsdk.operator.dependent.prevblocklist; | ||
|
||
import java.time.Duration; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
class PrevAnnotationBlockReconcilerIT { | ||
|
||
public static final String TEST_1 = "test1"; | ||
|
||
@RegisterExtension | ||
LocallyRunOperatorExtension extension = | ||
LocallyRunOperatorExtension.builder() | ||
// Removing resource from blocklist List would result in test failure | ||
// .withConfigurationService( | ||
// o -> o.previousAnnotationUsageBlocklist(Collections.emptyList())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a new test then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be an additional test, I did not add that since I did not find it important to show that something is not working. |
||
.withReconciler(PrevAnnotationBlockReconciler.class) | ||
.build(); | ||
|
||
@Test | ||
void doNotUsePrevAnnotationForDeploymentDependent() { | ||
extension.create(testResource(TEST_1)); | ||
|
||
var reconciler = extension.getReconcilerOfType(PrevAnnotationBlockReconciler.class); | ||
await() | ||
.pollDelay(Duration.ofMillis(200)) | ||
.untilAsserted( | ||
() -> { | ||
var deployment = extension.get(Deployment.class, TEST_1); | ||
assertThat(deployment).isNotNull(); | ||
assertThat(reconciler.getNumberOfExecutions()).isGreaterThan(0).isLessThan(10); | ||
}); | ||
} | ||
|
||
PrevAnnotationBlockCustomResource testResource(String name) { | ||
var res = new PrevAnnotationBlockCustomResource(); | ||
res.setMetadata(new ObjectMetaBuilder().withName(name).build()); | ||
res.setSpec(new PrevAnnotationBlockSpec()); | ||
res.getSpec().setValue("value"); | ||
return res; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...est/java/io/javaoperatorsdk/operator/dependent/prevblocklist/PrevAnnotationBlockSpec.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,15 @@ | ||
package io.javaoperatorsdk.operator.dependent.prevblocklist; | ||
|
||
public class PrevAnnotationBlockSpec { | ||
|
||
private String value; | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public PrevAnnotationBlockSpec setValue(String value) { | ||
this.value = value; | ||
return this; | ||
} | ||
} |
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 should use the configuration option from #2760 instead.
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.
If that is merged, can change it (might be a new PR). thx!