Skip to content

Commit

Permalink
tetragon-oci-hook: add server-version command
Browse files Browse the repository at this point in the history
Add a server-version command, which is intended for testing.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Jul 2, 2024
1 parent 94a8d4f commit 56443a3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions contrib/tetragon-rthooks/cmd/oci-hook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ func main() {
}
case "poststop":
// do nothing
case "server-version":
ver, err := serverVersion(log)
if err != nil {
log.Warn("failed to get server version", "error", err)
os.Exit(1)
}
log.Info("server-version", "version", ver)
default:
log.Warn("hook called with unknown hook",
"hook", cliConf.HookName,
Expand All @@ -368,3 +375,24 @@ func getBinaryDir() string {

return path.Dir(p)
}

func serverVersion(log *slog.Logger) (string, error) {
req := &tetragon.GetVersionRequest{}
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

connCtx, connCancel := context.WithTimeout(ctx, cliConf.GrpcTimeout)
defer connCancel()
conn, err := grpc.DialContext(connCtx, cliConf.AgentAddr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
if err != nil {
return "", fmt.Errorf("connecting to agent (%s) failed: %s", err, cliConf.AgentAddr)
}
defer conn.Close()

client := tetragon.NewFineGuidanceSensorsClient(conn)
res, err := client.GetVersion(ctx, req)
if err != nil {
return "", err
}
return res.Version, nil
}

0 comments on commit 56443a3

Please sign in to comment.