package main import ( "context" "github.com/crossplane/function-sdk-go/errors" "github.com/crossplane/function-sdk-go/logging" fnv1 "github.com/crossplane/function-sdk-go/proto/v1" "github.com/crossplane/function-sdk-go/request" "github.com/crossplane/function-sdk-go/response" "github.com/crossplane/function-template-go/input/v1beta1" ) // Function returns whatever response you ask it to. type Function struct { fnv1.UnimplementedFunctionRunnerServiceServer log logging.Logger } // RunFunction runs the Function. func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) (*fnv1.RunFunctionResponse, error) { f.log.Info("Running function", "tag", req.GetMeta().GetTag()) rsp := response.To(req, response.DefaultTTL) in := &v1beta1.Input{} if err := request.GetInput(req, in); err != nil { // You can set a custom status condition on the claim. This allows you to // communicate with the user. See the link below for status condition // guidance. // https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties response.ConditionFalse(rsp, "FunctionSuccess", "InternalError"). WithMessage("Something went wrong."). TargetCompositeAndClaim() // You can emit an event regarding the claim. This allows you to communicate // with the user. Note that events should be used sparingly and are subject // to throttling; see the issue below for more information. // https://github.com/crossplane/crossplane/issues/5802 response.Warning(rsp, errors.New("something went wrong")). TargetCompositeAndClaim() response.Fatal(rsp, errors.Wrapf(err, "cannot get Function input from %T", req)) return rsp, nil } // TODO: Add your Function logic here! response.Normalf(rsp, "I was run with input %q!", in.Example) f.log.Info("I was run!", "input", in.Example) // You can set a custom status condition on the claim. This allows you to // communicate with the user. See the link below for status condition // guidance. // https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties response.ConditionTrue(rsp, "FunctionSuccess", "Success"). TargetCompositeAndClaim() return rsp, nil }