Skip to content

Commit

Permalink
fix: improve docs
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Altmann <[email protected]>
  • Loading branch information
Wompipomp committed Jan 3, 2025
1 parent 1bb6428 commit a7bc48b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package/input/template.fn.crossplane.io_kclinputs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
controller-gen.kubebuilder.io/version: v0.17.0
name: kclinputs.template.fn.crossplane.io
spec:
group: template.fn.crossplane.io
Expand Down
5 changes: 4 additions & 1 deletion pkg/resource/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ConditionResources []ConditionResource
// ConditionResource will set a condition on the target.
type ConditionResource struct {
// The target(s) to receive the condition. Can be Composite or
// CompositeAndClaim.
// CompositeAndClaim. Defaults to Composite
Target *BindingTarget `json:"target"`
// If true, the condition will override a condition of the same Type. Defaults
// to false.
Expand All @@ -50,6 +50,7 @@ type Condition struct {
Message *string `json:"message"`
}

// transformCondition converts a ConditionResource into an fnv1.Condition while mapping status and target accordingly.
func transformCondition(cs ConditionResource) *fnv1.Condition {
c := &fnv1.Condition{
Type: cs.Condition.Type,
Expand Down Expand Up @@ -81,6 +82,8 @@ func transformTarget(t *BindingTarget) *fnv1.Target {
return fnv1.Target_TARGET_COMPOSITE.Enum()
}

// SetConditions updates the RunFunctionResponse with specified conditions from ConditionResources, ensuring no duplicates.
// It validates that system-reserved Crossplane condition types are not set and permits forced updates when specified.
func SetConditions(rsp *fnv1.RunFunctionResponse, cr ConditionResources, log logging.Logger) error {
conditionsSet := map[string]bool{}
// All matchConditions matched, set the desired conditions.
Expand Down
6 changes: 5 additions & 1 deletion pkg/resource/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ type Event struct {
// CreateEvent will create an event for the target(s).
type CreateEvent struct {
// The target(s) to create an event for. Can be Composite or
// CompositeAndClaim.
// CompositeAndClaim. Defaults to Composite
Target *BindingTarget `json:"target"`

// Event to create.
Event Event `json:"event"`
}

// SetEvents processes a list of EventResources, transforms them into Results, and appends them to the RunFunctionResponse.
// Returns an error if any transformation fails.
func SetEvents(rsp *fnv1.RunFunctionResponse, ers EventResources) error {
for _, er := range ers {
r, err := transformEvent(er)
Expand All @@ -54,6 +56,8 @@ func SetEvents(rsp *fnv1.RunFunctionResponse, ers EventResources) error {
return nil
}

// transformEvent converts a CreateEvent into a fnv1.Result object, handling event severity, reason, message, and target.
// Returns a fnv1.Result object or an error if the event type is invalid.
func transformEvent(ec CreateEvent) (*fnv1.Result, error) {
e := &fnv1.Result{
Reason: ec.Event.Reason,
Expand Down

0 comments on commit a7bc48b

Please sign in to comment.