Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Mészáros <[email protected]>
  • Loading branch information
csviri committed Sep 6, 2024
1 parent 5a70e48 commit 1d05db5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 28 deletions.
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> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import org.slf4j.LoggerFactory;

import io.javaoperatorsdk.operator.Operator;
import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration;

public class ControllerNamespaceDeletionOperator {

private static final Logger log = LoggerFactory.getLogger(ControllerNamespaceDeletionOperator.class);
private static final Logger log =
LoggerFactory.getLogger(ControllerNamespaceDeletionOperator.class);

public static void main(String[] args) {
Operator operator = new Operator();
Expand Down
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);
}
}
}
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;
}
}
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;
}
}

0 comments on commit 1d05db5

Please sign in to comment.