diff --git a/src/runtime/pkg/katautils/hook.go b/src/runtime/pkg/katautils/hook.go index 62eb81169c..16c316fea9 100644 --- a/src/runtime/pkg/katautils/hook.go +++ b/src/runtime/pkg/katautils/hook.go @@ -32,15 +32,16 @@ func hookLogger() *logrus.Entry { return kataUtilsLogger.WithField("subsystem", "hook") } -func runHook(ctx context.Context, hook specs.Hook, cid, bundlePath string) error { +func runHook(ctx context.Context, spec specs.Spec, hook specs.Hook, cid, bundlePath string) error { span, _ := katatrace.Trace(ctx, hookLogger(), "runHook", hookTracingTags) defer span.End() katatrace.AddTags(span, "path", hook.Path, "args", hook.Args) state := specs.State{ - Pid: syscall.Gettid(), - Bundle: bundlePath, - ID: cid, + Pid: syscall.Gettid(), + Bundle: bundlePath, + ID: cid, + Annotations: spec.Annotations, } stateJSON, err := json.Marshal(state) @@ -90,13 +91,13 @@ func runHook(ctx context.Context, hook specs.Hook, cid, bundlePath string) error return nil } -func runHooks(ctx context.Context, hooks []specs.Hook, cid, bundlePath, hookType string) error { +func runHooks(ctx context.Context, spec specs.Spec, hooks []specs.Hook, cid, bundlePath, hookType string) error { span, ctx := katatrace.Trace(ctx, hookLogger(), "runHooks", hookTracingTags) katatrace.AddTags(span, "type", hookType) defer span.End() for _, hook := range hooks { - if err := runHook(ctx, hook, cid, bundlePath); err != nil { + if err := runHook(ctx, spec, hook, cid, bundlePath); err != nil { hookLogger().WithFields(logrus.Fields{ "hook-type": hookType, "error": err, @@ -116,7 +117,7 @@ func PreStartHooks(ctx context.Context, spec specs.Spec, cid, bundlePath string) return nil } - return runHooks(ctx, spec.Hooks.Prestart, cid, bundlePath, "pre-start") + return runHooks(ctx, spec, spec.Hooks.Prestart, cid, bundlePath, "pre-start") } // PostStartHooks run the hooks just after start container @@ -126,7 +127,7 @@ func PostStartHooks(ctx context.Context, spec specs.Spec, cid, bundlePath string return nil } - return runHooks(ctx, spec.Hooks.Poststart, cid, bundlePath, "post-start") + return runHooks(ctx, spec, spec.Hooks.Poststart, cid, bundlePath, "post-start") } // PostStopHooks run the hooks after stop container @@ -136,5 +137,5 @@ func PostStopHooks(ctx context.Context, spec specs.Spec, cid, bundlePath string) return nil } - return runHooks(ctx, spec.Hooks.Poststop, cid, bundlePath, "post-stop") + return runHooks(ctx, spec, spec.Hooks.Poststop, cid, bundlePath, "post-stop") } diff --git a/src/runtime/pkg/katautils/hook_test.go b/src/runtime/pkg/katautils/hook_test.go index 54acfecc06..6109b55499 100644 --- a/src/runtime/pkg/katautils/hook_test.go +++ b/src/runtime/pkg/katautils/hook_test.go @@ -57,26 +57,27 @@ func TestRunHook(t *testing.T) { assert := assert.New(t) ctx := context.Background() + spec := specs.Spec{} // Run with timeout 0 hook := createHook(0) - err := runHook(ctx, hook, testSandboxID, testBundlePath) + err := runHook(ctx, spec, hook, testSandboxID, testBundlePath) assert.NoError(err) // Run with timeout 1 hook = createHook(1) - err = runHook(ctx, hook, testSandboxID, testBundlePath) + err = runHook(ctx, spec, hook, testSandboxID, testBundlePath) assert.NoError(err) // Run timeout failure hook = createHook(1) hook.Args = append(hook.Args, "2") - err = runHook(ctx, hook, testSandboxID, testBundlePath) + err = runHook(ctx, spec, hook, testSandboxID, testBundlePath) assert.Error(err) // Failure due to wrong hook hook = createWrongHook() - err = runHook(ctx, hook, testSandboxID, testBundlePath) + err = runHook(ctx, spec, hook, testSandboxID, testBundlePath) assert.Error(err) }