Skip to content

Commit

Permalink
default to Composite claimcondition
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Borrelli <[email protected]>
  • Loading branch information
stevendborrelli committed Nov 25, 2024
1 parent f9edb3f commit 54705fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
8 changes: 4 additions & 4 deletions claimconditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func transformCondition(tc TargetedCondition) *fnv1.Condition {
}

// transformTarget converts the input into a target Go SDK Enum
// Default to TARGET_COMPOSITE_AND_CLAIM
// Default to TARGET_COMPOSITE
func transformTarget(ct CompositionTarget) *fnv1.Target {
if ct == CompositionTargetComposite {
return fnv1.Target_TARGET_COMPOSITE.Enum()
if ct == CompositionTargetCompositeAndClaim {
return fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum().Enum()
}
return fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum()
return fnv1.Target_TARGET_COMPOSITE.Enum()
}

// UpdateResponseWithCondition updates the RunFunctionResponse with a Condition
Expand Down
12 changes: 6 additions & 6 deletions claimconditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func Test_UpdateClaimConditions(t *testing.T) {
{
Message: ptr.To("No Target should add CompositeAndClaim"),
Status: fnv1.Status_STATUS_CONDITION_TRUE,
Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),
Target: fnv1.Target_TARGET_COMPOSITE.Enum(),
Type: "NoTarget",
},
},
Expand Down Expand Up @@ -168,7 +168,7 @@ func Test_transformCondition(t *testing.T) {
},
want: &fnv1.Condition{
Status: fnv1.Status_STATUS_CONDITION_UNKNOWN,
Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),
Target: fnv1.Target_TARGET_COMPOSITE.Enum(),
},
},
"StatusFalseNoTarget": {
Expand All @@ -185,7 +185,7 @@ func Test_transformCondition(t *testing.T) {
want: &fnv1.Condition{
Message: ptr.To("Basic Message"),
Status: fnv1.Status_STATUS_CONDITION_FALSE,
Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),
Target: fnv1.Target_TARGET_COMPOSITE.Enum(),
Type: "TestType",
},
},
Expand All @@ -208,12 +208,12 @@ func Test_transformTarget(t *testing.T) {
args args
want *fnv1.Target
}{
"DefaultToCompositeAndClaim": {
reason: "unknown target will default to CompositeAndClaim",
"DefaultToComposite": {
reason: "unknown target will default to Composite",
args: args{
ct: "COMPOSE",
},
want: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),
want: fnv1.Target_TARGET_COMPOSITE.Enum(),
},
"Composite": {
reason: "Composite target correctly set",
Expand Down
11 changes: 7 additions & 4 deletions example/conditions/composition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ spec:
apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1
kind: ClaimConditions
conditions:
# Guide to ClaimConditions fields:
# Type of the condition, e.g. DatabaseReady.
# 'Healthy', 'Ready' and 'Synced' are reserved for use by Crossplane and this function will raise an error if used
# - type:
# Status of the condition.
# Status of the condition. String of "True"/"False"/"Unknown"
# status:
# Machine-readable PascalCase reason.
# Machine-readable PascalCase reason, for example "DatabaseReady"
# reason:
# Optional Target. Publish Condition only to the Composite, or the Composite and the Claim.
# Defaults to CompositeAndClaim
# Optional Target. Publish Condition only to the Composite, or the Composite and the Claim (CompositeAndClaim).
# Defaults to Composite
# target:
# Optional message:
# message:
- type: TestCondition
status: "False"
reason: InstallFail
Expand Down
4 changes: 2 additions & 2 deletions fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ func TestRunFunction(t *testing.T) {
Status: fnv1.Status_STATUS_CONDITION_FALSE,
Reason: "InstallFail",
Message: ptr.To("failed to install"),
Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),
Target: fnv1.Target_TARGET_COMPOSITE.Enum(),
},
{
Type: "ConditionTrue",
Expand All @@ -697,7 +697,7 @@ func TestRunFunction(t *testing.T) {
Status: fnv1.Status_STATUS_CONDITION_TRUE,
Reason: "Ready",
Message: ptr.To("Database is ready"),
Target: fnv1.Target_TARGET_COMPOSITE_AND_CLAIM.Enum(),
Target: fnv1.Target_TARGET_COMPOSITE.Enum(),
},
},
Meta: &fnv1.ResponseMeta{Ttl: durationpb.New(response.DefaultTTL)},
Expand Down

0 comments on commit 54705fe

Please sign in to comment.