-
Notifications
You must be signed in to change notification settings - Fork 229
improve: showcase issue where updating the spec with SSA removes the finalizer #2848
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
3
commits into
main
Choose a base branch
from
ssa-spec-update
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
14 changes: 14 additions & 0 deletions
14
.../io/javaoperatorsdk/operator/baseapi/ssaissue/specupdate/SSASpecUpdateCustomResource.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,14 @@ | ||
package io.javaoperatorsdk.operator.baseapi.ssaissue.specupdate; | ||
|
||
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("ssul") | ||
public class SSASpecUpdateCustomResource | ||
extends CustomResource<SSASpecUpdateCustomResourceSpec, SSASpecUpdateCustomResourceStatus> | ||
implements Namespaced {} |
14 changes: 14 additions & 0 deletions
14
...javaoperatorsdk/operator/baseapi/ssaissue/specupdate/SSASpecUpdateCustomResourceSpec.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,14 @@ | ||
package io.javaoperatorsdk.operator.baseapi.ssaissue.specupdate; | ||
|
||
public class SSASpecUpdateCustomResourceSpec { | ||
|
||
private String value; | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...vaoperatorsdk/operator/baseapi/ssaissue/specupdate/SSASpecUpdateCustomResourceStatus.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.baseapi.ssaissue.specupdate; | ||
|
||
public class SSASpecUpdateCustomResourceStatus { | ||
|
||
private Integer value = 0; | ||
|
||
public Integer getValue() { | ||
return value; | ||
} | ||
|
||
public SSASpecUpdateCustomResourceStatus setValue(Integer value) { | ||
this.value = value; | ||
return this; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...rc/test/java/io/javaoperatorsdk/operator/baseapi/ssaissue/specupdate/SSASpecUpdateIT.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,41 @@ | ||
package io.javaoperatorsdk.operator.baseapi.ssaissue.specupdate; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
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 SSASpecUpdateIT { | ||
|
||
public static final String TEST_RESOURCE_NAME = "test"; | ||
|
||
@RegisterExtension | ||
LocallyRunOperatorExtension operator = | ||
LocallyRunOperatorExtension.builder().withReconciler(SSASpecUpdateReconciler.class).build(); | ||
|
||
// showcases that if the spec of the resources is updated with SSA, but the finalizer | ||
// is not explicitly added to the fresh resource, the update removes the finalizer | ||
@Test | ||
void showFinalizerRemovalWhenSpecUpdated() { | ||
SSASpecUpdateCustomResource res = createResource(); | ||
operator.create(res); | ||
|
||
await() | ||
.untilAsserted( | ||
() -> { | ||
var actual = operator.get(SSASpecUpdateCustomResource.class, TEST_RESOURCE_NAME); | ||
assertThat(actual.getSpec()).isNotNull(); | ||
assertThat(actual.getFinalizers()).isEmpty(); | ||
}); | ||
} | ||
|
||
SSASpecUpdateCustomResource createResource() { | ||
SSASpecUpdateCustomResource res = new SSASpecUpdateCustomResource(); | ||
res.setMetadata(new ObjectMetaBuilder().withName(TEST_RESOURCE_NAME).build()); | ||
return res; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...java/io/javaoperatorsdk/operator/baseapi/ssaissue/specupdate/SSASpecUpdateReconciler.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,47 @@ | ||
package io.javaoperatorsdk.operator.baseapi.ssaissue.specupdate; | ||
|
||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.javaoperatorsdk.operator.api.reconciler.Cleaner; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; | ||
import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; | ||
import io.javaoperatorsdk.operator.api.reconciler.Reconciler; | ||
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; | ||
|
||
@ControllerConfiguration | ||
public class SSASpecUpdateReconciler | ||
implements Reconciler<SSASpecUpdateCustomResource>, Cleaner<SSASpecUpdateCustomResource> { | ||
|
||
@Override | ||
public UpdateControl<SSASpecUpdateCustomResource> reconcile( | ||
SSASpecUpdateCustomResource resource, Context<SSASpecUpdateCustomResource> context) { | ||
|
||
var copy = createFreshCopy(resource); | ||
copy.getSpec().setValue("value"); | ||
context | ||
.getClient() | ||
.resource(copy) | ||
.fieldManager(context.getControllerConfiguration().fieldManager()) | ||
.serverSideApply(); | ||
|
||
return UpdateControl.noUpdate(); | ||
} | ||
|
||
SSASpecUpdateCustomResource createFreshCopy(SSASpecUpdateCustomResource resource) { | ||
var res = new SSASpecUpdateCustomResource(); | ||
res.setMetadata( | ||
new ObjectMetaBuilder() | ||
.withName(resource.getMetadata().getName()) | ||
.withNamespace(resource.getMetadata().getNamespace()) | ||
.build()); | ||
res.setSpec(new SSASpecUpdateCustomResourceSpec()); | ||
return res; | ||
} | ||
|
||
@Override | ||
public DeleteControl cleanup( | ||
SSASpecUpdateCustomResource resource, Context<SSASpecUpdateCustomResource> context) { | ||
|
||
return DeleteControl.defaultDelete(); | ||
} | ||
} |
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.