-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [FEATURE] k8s 1.20后续版本默认容器运行时采用
containerd
,k8s-mon获取容器tag时需要适配,默认采…
…用docker-api,失败再尝试containerd-api * [CHANGE] pod runner改为`yauritux/busybox-curl` 提供curl命令方便排查问题 * [CHANGE] 注意如果 不采集etcd,没有创建对应的证书(如k8s使用公有云托管的),那么请将 deployment中挂载证书那几行注释掉,不然容器起不来 * [CHANGE] 容器版本调整为 v2.1.0
- Loading branch information
Showing
8 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.0.7 | ||
2.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package collect | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/containerd/containerd" | ||
) | ||
|
||
func getLabelMapByContainerdSdk(nidLabelName string) (map[string]map[string]string, error) { | ||
client, err := containerd.New("/run/containerd/containerd.sock", containerd.WithDefaultNamespace("k8s.io")) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer client.Close() | ||
|
||
context := context.Background() | ||
cers, err := client.Containers(context) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if len(cers) == 0 { | ||
return nil, errors.New("got zero containers on this node") | ||
} | ||
|
||
insM := make(map[string]map[string]string) | ||
whiteKeyM := map[string]struct{}{ | ||
nidLabelName: {}, | ||
} | ||
|
||
for _, c := range cers { | ||
labels, err := c.Labels(context) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
podName := labels["io.kubernetes.pod.name"] | ||
if podName == "" { | ||
continue | ||
} | ||
|
||
lastM, loaded := insM[podName] | ||
if !loaded { | ||
lastM = make(map[string]string) | ||
} | ||
|
||
for k, v := range labels { | ||
|
||
if _, found := whiteKeyM[k]; !found { | ||
continue | ||
} | ||
lastM[k] = v | ||
} | ||
|
||
insM[podName] = lastM | ||
|
||
} | ||
return insM, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters