Ai
2 Star 1 Fork 0

李玮/trireme-lib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
helpers.go 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
李玮 提交于 2020-01-29 13:23 +08:00 . v1
package dockermonitor
import (
"git.cloud.top/DSec/trireme-lib/common"
"git.cloud.top/DSec/trireme-lib/monitor/constants"
"git.cloud.top/DSec/trireme-lib/policy"
"go.uber.org/zap"
)
// getPausePUID returns puid of pause container.
func getPausePUID(extensions policy.ExtendedMap) string {
if extensions == nil {
return ""
}
if puid, ok := extensions.Get(constants.DockerHostPUID); ok {
zap.L().Debug("puid of pause container is", zap.String("puid", puid))
return puid
}
return ""
}
// PolicyExtensions retrieves policy extensions
func policyExtensions(runtime policy.RuntimeReader) (extensions policy.ExtendedMap) {
if runtime == nil {
return nil
}
if runtime.Options().PolicyExtensions == nil {
return nil
}
if extensions, ok := runtime.Options().PolicyExtensions.(policy.ExtendedMap); ok {
return extensions
}
return nil
}
// IsHostNetworkContainer returns true if container has hostnetwork set
// to true or is linked to container with hostnetwork set to true.
func isHostNetworkContainer(runtime policy.RuntimeReader) bool {
return runtime.PUType() == common.LinuxProcessPU || (getPausePUID(policyExtensions(runtime)) != "")
}
// IsKubernetesContainer checks if the container is in K8s.
func isKubernetesContainer(labels map[string]string) bool {
if _, ok := labels[constants.K8sPodNamespace]; ok {
return true
}
return false
}
// KubePodIdentifier returns identifier for K8s pod.
func kubePodIdentifier(labels map[string]string) string {
if !isKubernetesContainer(labels) {
return ""
}
podName := ""
podNamespace := ""
podNamespace, ok := labels[constants.K8sPodNamespace]
if !ok {
podNamespace = ""
}
podName, ok = labels[constants.K8sPodName]
if !ok {
podName = ""
}
if podName == "" || podNamespace == "" {
zap.L().Warn("K8s pod does not have podname/podnamespace labels")
return ""
}
return podNamespace + "/" + podName
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/emmoblin/trireme-lib.git
git@gitee.com:emmoblin/trireme-lib.git
emmoblin
trireme-lib
trireme-lib
7726874a2b9a

搜索帮助