Skip to content

Commit 036e839

Browse files
committed
Add ability to set status of the desired object
Signed-off-by: Knut-Erik Johnsen <knut-erik.johnsen@klp.no>
1 parent 3d9b956 commit 036e839

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎crossplane-function-base/src/main/java/io/crossplane/compositefunctions/base/CrossplaneObjectToProtobufConverter.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.google.protobuf.Struct;
55
import com.google.protobuf.util.JsonFormat;
6+
import io.crossplane.compositefunctions.base.model.CrossplaneDesiredObject;
7+
import io.crossplane.compositefunctions.base.model.CrossplaneDesiredObjectStatus;
68
import io.crossplane.compositefunctions.protobuf.v1.Resource;
79

810
/**
@@ -21,7 +23,13 @@ public final class CrossplaneObjectToProtobufConverter {
2123
public static Resource convertToResource(Object object) {
2224
try {
2325
Resource.Builder builder = Resource.newBuilder();
24-
return builder.setResource(convertToStruct(object)).build();
26+
27+
if (object instanceof CrossplaneDesiredObject desiredObject) {
28+
object = desiredObject.object();
29+
builder.setReady(desiredObject.status().getStatus());
30+
}
31+
builder.setResource(convertToStruct(object));
32+
return builder.build();
2533
} catch (Exception e) {
2634
throw new RuntimeException("Unable to convert object to resource", e);
2735
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package io.crossplane.compositefunctions.base.model;
2+
3+
public record CrossplaneDesiredObject(Object object, CrossplaneDesiredObjectStatus status) {
4+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.crossplane.compositefunctions.base.model;
2+
3+
import io.crossplane.compositefunctions.protobuf.v1.Ready;
4+
5+
public enum CrossplaneDesiredObjectStatus {
6+
UNSPECIFIED(Ready.READY_UNSPECIFIED),
7+
READY(Ready.READY_TRUE),
8+
NOT_READY(Ready.READY_FALSE);
9+
10+
private final Ready status;
11+
private CrossplaneDesiredObjectStatus(Ready status) {
12+
this.status = status;
13+
}
14+
15+
public Ready getStatus() {
16+
return status;
17+
}
18+
19+
}

0 commit comments

Comments
 (0)