From 54705fe87b5b8c6059a314cf068bf28a79c37ca1 Mon Sep 17 00:00:00 2001 From: Steven Borrelli Date: Mon, 25 Nov 2024 09:53:23 -0600 Subject: [PATCH] default to Composite claimcondition Signed-off-by: Steven Borrelli --- claimconditions.go | 8 ++++---- claimconditions_test.go | 12 ++++++------ example/conditions/composition.yaml | 11 +++++++---- fn_test.go | 4 ++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/claimconditions.go b/claimconditions.go index 6e8537b..3788e28 100644 --- a/claimconditions.go +++ b/claimconditions.go @@ -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 diff --git a/claimconditions_test.go b/claimconditions_test.go index f933f6e..d948d90 100644 --- a/claimconditions_test.go +++ b/claimconditions_test.go @@ -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", }, }, @@ -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": { @@ -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", }, }, @@ -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", diff --git a/example/conditions/composition.yaml b/example/conditions/composition.yaml index 26f9da3..7c23e6c 100644 --- a/example/conditions/composition.yaml +++ b/example/conditions/composition.yaml @@ -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 diff --git a/fn_test.go b/fn_test.go index 11f69c4..227d208 100644 --- a/fn_test.go +++ b/fn_test.go @@ -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", @@ -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)},