From f9913836ec9e73bc3b2726fab34b3baea898c3f8 Mon Sep 17 00:00:00 2001 From: Kornilios Kourtis Date: Mon, 1 Jul 2024 13:22:00 +0200 Subject: [PATCH] tetragon-oci-hook-setup: prepare for nri interface Refactor code so that we can implement the NRI interface in tetragon-oci-hook-setup. Specifically, move everything under the ociHooksInstall function. Signed-off-by: Kornilios Kourtis --- contrib/tetragon-rthooks/cmd/setup/main.go | 40 +++++++++++++--------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/contrib/tetragon-rthooks/cmd/setup/main.go b/contrib/tetragon-rthooks/cmd/setup/main.go index 04f3f3ff0c6..657878bb222 100644 --- a/contrib/tetragon-rthooks/cmd/setup/main.go +++ b/contrib/tetragon-rthooks/cmd/setup/main.go @@ -62,7 +62,16 @@ func ociHooksConfig(binFname string, binArgs ...string) *ociHooks.Hook { } func (i *Install) ociHooksInstall(log *slog.Logger) { + var sigChan chan os.Signal + if i.Daemonize { + sigChan = make(chan os.Signal, 1) + signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) + } + // copy the binary to the host + i.copyBinary(log) + + // add .json file to oci hooks dir _, binBaseName := path.Split(i.LocalBinary) binFname := filepath.Join(i.HostInstallDir, binBaseName) @@ -83,24 +92,8 @@ func (i *Install) ociHooksInstall(log *slog.Logger) { } log.Info("written conf", "conf-dst-path", confDst) -} - -func (i *Install) Run(log *slog.Logger) error { - var sigChan chan os.Signal - if i.Daemonize { - sigChan = make(chan os.Signal, 1) - signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) - } - - i.copyBinary(log) - switch i.Interface { - case "oci-hooks": - i.ociHooksInstall(log) - default: - log.Error("unknown interface", "interface", i.Interface) - os.Exit(1) - } + // if --daemonize is set, wait until we receive a signal, and then uninstall hook. if i.Daemonize { <-sigChan u := Uninstall{ @@ -113,6 +106,19 @@ func (i *Install) Run(log *slog.Logger) error { log.Error("uninstall failed", "err", err) } } +} + +func (i *Install) Run(log *slog.Logger) error { + + i.copyBinary(log) + switch i.Interface { + case "oci-hooks": + i.ociHooksInstall(log) + return nil + } + + log.Error("unknown interface", "interface", i.Interface) + os.Exit(1) return nil }