Skip to content

Commit

Permalink
ResultOption => Result
Browse files Browse the repository at this point in the history
TargetBoth => TargetCompositeAndClaim
  • Loading branch information
dalton-hill-0 committed Mar 28, 2024
1 parent d83c0a3 commit 99e0bda
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ import (
// DefaultTTL is the default TTL for which a response can be cached.
const DefaultTTL = 1 * time.Minute

// ResultOption allows you to further configure the Result that gets added to
// the response.
type ResultOption struct {
// A Result of running a Function.
type Result struct {
result *v1beta1.Result
}

Expand Down Expand Up @@ -104,7 +103,7 @@ func SetDesiredComposedResources(rsp *v1beta1.RunFunctionResponse, dcds map[reso

// Fatal adds a fatal result to the supplied RunFunctionResponse.
// A corresponding event will be created for the Composite Resource.
func Fatal(rsp *v1beta1.RunFunctionResponse, err error) *ResultOption {
func Fatal(rsp *v1beta1.RunFunctionResponse, err error) *Result {
if rsp.GetResults() == nil {
rsp.Results = make([]*v1beta1.Result, 0, 1)
}
Expand All @@ -115,14 +114,14 @@ func Fatal(rsp *v1beta1.RunFunctionResponse, err error) *ResultOption {
}
rsp.Results = append(rsp.GetResults(), result)

return &ResultOption{
return &Result{
result: result,
}
}

// Warning adds a warning result to the supplied RunFunctionResponse.
// A corresponding event will be created for the Composite Resource.
func Warning(rsp *v1beta1.RunFunctionResponse, err error) *ResultOption {
func Warning(rsp *v1beta1.RunFunctionResponse, err error) *Result {
if rsp.GetResults() == nil {
rsp.Results = make([]*v1beta1.Result, 0, 1)
}
Expand All @@ -133,14 +132,14 @@ func Warning(rsp *v1beta1.RunFunctionResponse, err error) *ResultOption {
}
rsp.Results = append(rsp.GetResults(), result)

return &ResultOption{
return &Result{
result: result,
}
}

// Normal adds a normal result to the supplied RunFunctionResponse.
// A corresponding event will be created for the Composite Resource.
func Normal(rsp *v1beta1.RunFunctionResponse, message string) *ResultOption {
func Normal(rsp *v1beta1.RunFunctionResponse, message string) *Result {
if rsp.GetResults() == nil {
rsp.Results = make([]*v1beta1.Result, 0, 1)
}
Expand All @@ -151,34 +150,34 @@ func Normal(rsp *v1beta1.RunFunctionResponse, message string) *ResultOption {
}
rsp.Results = append(rsp.GetResults(), result)

return &ResultOption{
return &Result{
result: result,
}
}

// Normalf adds a normal result to the supplied RunFunctionResponse.
// A corresponding event will be created for the Composite Resource.
func Normalf(rsp *v1beta1.RunFunctionResponse, format string, a ...any) *ResultOption {
func Normalf(rsp *v1beta1.RunFunctionResponse, format string, a ...any) *Result {
return Normal(rsp, fmt.Sprintf(format, a...))
}

// TargetComposite configures the Composite to receive any events or conditions
// generated by this result.
func (o *ResultOption) TargetComposite() *ResultOption {
func (o *Result) TargetComposite() *Result {
o.result.Target = v1beta1.Target_TARGET_COMPOSITE
return o
}

// TargetBoth configures both the Claim and Composite to receive any events or
// conditions generated by this result.
func (o *ResultOption) TargetBoth() *ResultOption {
// TargetCompositeAndClaim configures both the Claim and Composite to receive
// any events or conditions generated by this result.
func (o *Result) TargetCompositeAndClaim() *Result {
o.result.Target = v1beta1.Target_TARGET_COMPOSITE_AND_CLAIM
return o
}

// ConditionTrue configures the result to create a condition on the targeted
// objects with the status set to true.
func (o *ResultOption) ConditionTrue(t string, r string) *ResultOption {
func (o *Result) ConditionTrue(t string, r string) *Result {
o.result.Condition = &v1beta1.Condition{
Type: t,
Status: v1beta1.Status_STATUS_TRUE,
Expand All @@ -189,7 +188,7 @@ func (o *ResultOption) ConditionTrue(t string, r string) *ResultOption {

// ConditionFalse configures the result to create a condition on the targeted
// objects with the status set to false.
func (o *ResultOption) ConditionFalse(t string, r string) *ResultOption {
func (o *Result) ConditionFalse(t string, r string) *Result {
o.result.Condition = &v1beta1.Condition{
Type: t,
Status: v1beta1.Status_STATUS_FALSE,
Expand All @@ -200,7 +199,7 @@ func (o *ResultOption) ConditionFalse(t string, r string) *ResultOption {

// ConditionUnknown configures the result to create a condition on the targeted
// objects with the status set to unknown.
func (o *ResultOption) ConditionUnknown(t string, r string) *ResultOption {
func (o *Result) ConditionUnknown(t string, r string) *Result {
o.result.Condition = &v1beta1.Condition{
Type: t,
Status: v1beta1.Status_STATUS_UNKNOWN,
Expand Down
2 changes: 1 addition & 1 deletion response/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestResult(t *testing.T) {
response.Warning(rsp, errors.New("this is a test warning result targeting the composite")).TargetComposite()
},
func(rsp *v1beta1.RunFunctionResponse) {
response.Fatal(rsp, errors.New("this is a test fatal result targeting both")).TargetBoth()
response.Fatal(rsp, errors.New("this is a test fatal result targeting both")).TargetCompositeAndClaim()
},
},
},
Expand Down

0 comments on commit 99e0bda

Please sign in to comment.