Created
June 15, 2023 12:51
-
-
Save haraldsk/1e7ba014dc8317c3f4e5f4f1de637598 to your computer and use it in GitHub Desktop.
Patch to return debug info from from crossplane-xfn to crossplane container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/cmd/xfn/run/run.go b/cmd/xfn/run/run.go | |
index c2699bf5..a06bc334 100644 | |
--- a/cmd/xfn/run/run.go | |
+++ b/cmd/xfn/run/run.go | |
@@ -141,4 +141,4 @@ func networkPolicy(p string) v1alpha1.NetworkPolicy { | |
default: | |
return v1alpha1.NetworkPolicy_NETWORK_POLICY_ISOLATED | |
} | |
-} | |
+} | |
\ No newline at end of file | |
diff --git a/cmd/xfn/spark/spark.go b/cmd/xfn/spark/spark.go | |
index 3f315aff..53652bd2 100644 | |
--- a/cmd/xfn/spark/spark.go | |
+++ b/cmd/xfn/spark/spark.go | |
@@ -27,6 +27,7 @@ import ( | |
"path/filepath" | |
"time" | |
+ "github.com/crossplane/crossplane-runtime/pkg/logging" | |
"github.com/google/go-containerregistry/pkg/name" | |
"github.com/google/uuid" | |
runtime "github.com/opencontainers/runtime-spec/specs-go" | |
@@ -78,7 +79,7 @@ type Command struct { | |
// Run a Composition Function inside an unprivileged user namespace. Reads a | |
// protocol buffer serialized RunFunctionRequest from stdin, and writes a | |
// protocol buffer serialized RunFunctionResponse to stdout. | |
-func (c *Command) Run() error { //nolint:gocyclo // TODO(negz): Refactor some of this out into functions, add tests. | |
+func (c *Command) Run(log logging.Logger) error { //nolint:gocyclo // TODO(negz): Refactor some of this out into functions, add tests. | |
pb, err := io.ReadAll(os.Stdin) | |
if err != nil { | |
return errors.Wrap(err, errReadRequest) | |
@@ -153,14 +154,28 @@ func (c *Command) Run() error { //nolint:gocyclo // TODO(negz): Refactor some of | |
// recommended; 'run' is more for testing. In practice though run seems to | |
// work just fine for our use case. | |
+ log.Debug("about to run: ", c.Runtime, "--root="+root, "run", "--bundle="+b.Path(), runID, "with", req.GetInput()) | |
//nolint:gosec // Executing with user-supplied input is intentional. | |
cmd := exec.CommandContext(ctx, c.Runtime, "--root="+root, "run", "--bundle="+b.Path(), runID) | |
cmd.Stdin = bytes.NewReader(req.GetInput()) | |
out, err := cmd.Output() | |
+ if out != nil { | |
+ log.Debug("output from xfn: ", out) | |
+ } | |
if err != nil { | |
+ errMsg := errRuntime + " command: " + c.Runtime + "--root=" + root + " run " + " --bundle=" + b.Path() + runID + " input: " + string(req.GetInput()) | |
+ | |
+ if exiterr, ok := err.(*exec.ExitError); ok { | |
+ errMsg += " stderr: " + string(exiterr.Stderr) | |
+ } | |
+ | |
+ if out != nil { | |
+ errMsg += string(out) | |
+ } | |
+ | |
_ = b.Cleanup() | |
- return errors.Wrap(err, errRuntime) | |
+ return errors.Wrap(err, errMsg) | |
} | |
if err := b.Cleanup(); err != nil { | |
return errors.Wrap(err, errCleanupBundle) | |
@@ -223,4 +238,4 @@ func FromRunFunctionConfig(cfg *v1alpha1.RunFunctionConfig) spec.Option { | |
return nil | |
} | |
-} | |
+} | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment