Skip to content

Commit

Permalink
kata-monitor: make code to identify kata pods simpler
Browse files Browse the repository at this point in the history
just search for the "kata" substring in the runtime value and log at
info level when the runtime name/type is not found.

Signed-off-by: Francesco Giudici <fgiudici@redhat.com>
  • Loading branch information
fgiudici committed Aug 5, 2021
1 parent 68a6f01 commit 8714a35
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/runtime/pkg/kata-monitor/cri.go
Expand Up @@ -12,9 +12,8 @@ import (
"fmt"
"net"
"net/url"
"regexp"
"strings"

"github.com/kata-containers/kata-containers/src/runtime/pkg/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/xeipuuv/gojsonpointer"
Expand Down Expand Up @@ -59,18 +58,6 @@ func getConnection(endPoint string) (*grpc.ClientConn, error) {
return conn, nil
}

func matchesRegex(pattern, target string) bool {
if pattern == "" {
return true
}
matched, err := regexp.MatchString(pattern, target)
if err != nil {
// Assume it's not a match if an error occurs.
return false
}
return matched
}

func closeConnection(conn *grpc.ClientConn) error {
if conn == nil {
return nil
Expand Down Expand Up @@ -192,11 +179,19 @@ func (km *KataMonitor) getSandboxes() (map[string]struct{}, error) {
}
}

// Filter by pod name/namespace regular expressions.
// If lowRuntime is empty something changed in containerd/CRI-O or we are dealing with an unknown container engine.
// Safest options is to add the POD in the list: we will be able to connect to the shim to retrieve the actual info
// only for kata PODs.
if lowRuntime == "" {
monitorLog.WithField("pod", r).Info("unable to retrieve the runtime type")
sandboxMap[pod.Id] = struct{}{}
continue
}

monitorLog.WithFields(logrus.Fields{
"low runtime": lowRuntime,
}).Debug("")
if matchesRegex(types.KataRuntimeNameRegexp, lowRuntime) || matchesRegex("kata*", lowRuntime) {
if strings.Contains(lowRuntime, "kata") {
sandboxMap[pod.Id] = struct{}{}
}
}
Expand Down

0 comments on commit 8714a35

Please sign in to comment.