Skip to content

Commit

Permalink
Merge pull request #66 from BSWANG/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyt99 authored Jul 17, 2023
2 parents 2320ba4 + 96cd9ba commit 81ec8b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/skoop/collector/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func init() {
type SimplePodCollectorConfig struct {
Image string
CollectorNamespace string
RuntimeAPIAddress string
WaitInterval time.Duration
WaitTimeout time.Duration
PreserveCollectorPod bool
Expand All @@ -29,6 +30,7 @@ type SimplePodCollectorConfig struct {
func (cc *SimplePodCollectorConfig) BindFlags(fs *pflag.FlagSet) {
fs.StringVarP(&cc.Image, "collector-image", "", "kubeskoop/kubeskoop:v0.1.0", "Image used for collector.")
fs.StringVarP(&cc.CollectorNamespace, "collector-namespace", "", "skoop", "Namespace where collector pods in.")
fs.StringVarP(&cc.CollectorNamespace, "collector-cri-address", "", "", "Runtime CRI API endpoint address.")
fs.DurationVarP(&cc.WaitInterval, "collector-pod-wait-interval", "", 2*time.Second, "Collector pod running check interval.")
fs.DurationVarP(&cc.WaitTimeout, "collector-pod-wait-timeout", "", 120*time.Second, "Collector pod running check timeout.")
fs.BoolVarP(&cc.PreserveCollectorPod, "preserve-collector-pod", "", false, "Preserve collector pod after diagnosis complete.")
Expand Down
6 changes: 6 additions & 0 deletions pkg/skoop/collector/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type SimplePodCollectorManagerOptions struct {
type simplePodCollectorManager struct {
image string
namespace string
runtimeAPIAddress string
client *kubernetes.Clientset
restConfig *rest.Config
ipCache *k8s.IPCache
Expand Down Expand Up @@ -86,6 +87,7 @@ func NewSimplePodCollectorManager(ctx *ctx.Context) (collector.Manager, error) {
waitInterval: Config.SimplePodCollectorConfig.WaitInterval,
waitTimeout: Config.SimplePodCollectorConfig.WaitTimeout,
preserveCollectorPod: Config.SimplePodCollectorConfig.PreserveCollectorPod,
runtimeAPIAddress: Config.SimplePodCollectorConfig.RuntimeAPIAddress,
}, nil
}

Expand Down Expand Up @@ -334,6 +336,10 @@ func (m *simplePodCollectorManager) createCollectorPod(nodeName string) (*v1.Pod
SecurityContext: &v1.SecurityContext{
Privileged: pointer.Bool(true),
},
Env: []v1.EnvVar{{
Name: "RUNTIME_SOCK",
Value: m.runtimeAPIAddress,
}},
Command: []string{"/bin/pod-collector"},
VolumeMounts: []v1.VolumeMount{
{
Expand Down
15 changes: 14 additions & 1 deletion pkg/skoop/collector/podcollector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,20 @@ func NewCollector(podNamespace, podName, runtimeEndpoint string) (collector.Coll
_, err := os.Stat("/var/run/dockershim.sock")
if err != nil {
if os.IsNotExist(err) {
socket = "unix:///run/containerd/containerd.sock"
containerdSockets := []string{
"unix:///run/containerd/containerd.sock",
"unix:///run/k3s/containerd/containerd.sock",
}

for _, containerdAddr := range containerdSockets {
if _, err = os.Stat(strings.TrimPrefix(containerdAddr, "unix://")); err == nil {
socket = containerdAddr
break
}
}
if socket == "" {
return nil, fmt.Errorf("cannot found comportable endpoint address for cri-api, please specify cri address by --collector-cri-address")
}
} else {
return nil, err
}
Expand Down

0 comments on commit 81ec8b2

Please sign in to comment.