Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support k3s runtime api & support specify cri address #66

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading