-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Attila Mészáros <[email protected]>
- Loading branch information
Showing
5 changed files
with
76 additions
and
28 deletions.
There are no files selected for viewing
7 changes: 6 additions & 1 deletion
7
...in/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionCustomResource.java
This file contains 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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package io.javaoperatorsdk.operator.sample; | ||
|
||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.fabric8.kubernetes.model.annotation.Group; | ||
import io.fabric8.kubernetes.model.annotation.Version; | ||
|
||
public class ControllerNamespaceDeletionCustomResource extends CustomResource<ControllerNamespaceDeletionSpec, ControllerNamespaceDeletionStatus> { | ||
@Group("namespacedeletion.io") | ||
@Version("v1") | ||
public class ControllerNamespaceDeletionCustomResource | ||
extends CustomResource<ControllerNamespaceDeletionSpec, ControllerNamespaceDeletionStatus> { | ||
|
||
} |
This file contains 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
71 changes: 48 additions & 23 deletions
71
...c/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionReconciler.java
This file contains 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 |
---|---|---|
@@ -1,33 +1,58 @@ | ||
package io.javaoperatorsdk.operator.sample; | ||
|
||
import java.time.Duration; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
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.DeleteControl; | ||
import io.javaoperatorsdk.operator.api.reconciler.Reconciler; | ||
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; | ||
|
||
import java.time.Duration; | ||
|
||
public class ControllerNamespaceDeletionReconciler implements Reconciler<ControllerNamespaceDeletionCustomResource>, | ||
Cleaner<ControllerNamespaceDeletionCustomResource> { | ||
|
||
@Override | ||
public UpdateControl<ControllerNamespaceDeletionCustomResource> reconcile(ControllerNamespaceDeletionCustomResource resource, | ||
Context<ControllerNamespaceDeletionCustomResource> context) { | ||
|
||
|
||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public DeleteControl cleanup(ControllerNamespaceDeletionCustomResource resource, | ||
Context<ControllerNamespaceDeletionCustomResource> context) { | ||
try { | ||
Thread.sleep(Duration.ofSeconds(10).toMillis()); | ||
return DeleteControl.defaultDelete(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
public class ControllerNamespaceDeletionReconciler | ||
implements Reconciler<ControllerNamespaceDeletionCustomResource>, | ||
Cleaner<ControllerNamespaceDeletionCustomResource> { | ||
|
||
private static final Logger log = | ||
LoggerFactory.getLogger(ControllerNamespaceDeletionReconciler.class); | ||
|
||
public static final Duration CLEANUP_DELAY = Duration.ofSeconds(10); | ||
|
||
@Override | ||
public UpdateControl<ControllerNamespaceDeletionCustomResource> reconcile( | ||
ControllerNamespaceDeletionCustomResource resource, | ||
Context<ControllerNamespaceDeletionCustomResource> context) { | ||
log.info("Reconciling: {} in namespace: {}", resource.getMetadata().getName(), | ||
resource.getMetadata().getNamespace()); | ||
|
||
var response = createResponseResource(resource); | ||
response.getStatus().setValue(resource.getSpec().getValue()); | ||
|
||
return UpdateControl.patchStatus(response); | ||
} | ||
|
||
private ControllerNamespaceDeletionCustomResource createResponseResource( | ||
ControllerNamespaceDeletionCustomResource resource) { | ||
var res = new ControllerNamespaceDeletionCustomResource(); | ||
res.setMetadata(new ObjectMetaBuilder() | ||
.withName(resource.getMetadata().getName()) | ||
.withNamespace(resource.getMetadata().getNamespace()) | ||
.build()); | ||
res.setStatus(new ControllerNamespaceDeletionStatus()); | ||
return res; | ||
} | ||
|
||
@Override | ||
public DeleteControl cleanup(ControllerNamespaceDeletionCustomResource resource, | ||
Context<ControllerNamespaceDeletionCustomResource> context) { | ||
try { | ||
Thread.sleep(CLEANUP_DELAY.toMillis()); | ||
return DeleteControl.defaultDelete(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
11 changes: 10 additions & 1 deletion
11
...ion/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionSpec.java
This file contains 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 |
---|---|---|
@@ -1,6 +1,15 @@ | ||
package io.javaoperatorsdk.operator.sample; | ||
|
||
import io.fabric8.kubernetes.client.CustomResource; | ||
|
||
public class ControllerNamespaceDeletionSpec { | ||
|
||
private String value; | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
} |
11 changes: 10 additions & 1 deletion
11
...n/src/main/java/io/javaoperatorsdk/operator/sample/ControllerNamespaceDeletionStatus.java
This file contains 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 |
---|---|---|
@@ -1,6 +1,15 @@ | ||
package io.javaoperatorsdk.operator.sample; | ||
|
||
import io.fabric8.kubernetes.client.CustomResource; | ||
|
||
public class ControllerNamespaceDeletionStatus { | ||
|
||
private String value; | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
} |