-
Notifications
You must be signed in to change notification settings - Fork 22
feat: support kubenertes runner #403
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
Conversation
✅ Deploy Preview for reviewbot-x canceled.
|
ec6a33f
to
20dc1c7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #403 +/- ##
==========================================
- Coverage 35.75% 32.91% -2.84%
==========================================
Files 27 28 +1
Lines 2358 2561 +203
==========================================
Hits 843 843
- Misses 1390 1590 +200
- Partials 125 128 +3 ☔ View full report in Codecov by Sentry. |
20dc1c7
to
9084bab
Compare
k.script = scriptContent | ||
|
||
// create default config | ||
// Note(wwcchh0123): support unmarshalling YAML into structures in the future |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看表达,应该说的是TODO
} else if len(paths) == 1 { | ||
srcPath, dstPath = paths[0], paths[0] | ||
} else { | ||
return nil, fmt.Errorf("invalid copy ssh key format: %s", cfg.DockerAsRunner.CopySSHKeyToContainer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释不对
}) | ||
} | ||
|
||
createdjob, err := k.Cli.BatchV1().Jobs(cfg.KubernetesAsRunner.Namespace).Create(ctx, job, metav1.CreateOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace能为空吗?
return nil, err | ||
} | ||
|
||
podName := k.getJobNameWithPrefix(ctx, cfg.KubernetesAsRunner.Namespace, createdjob.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以通过selector 拿到唯一的Pod名
log := lintersutil.FromContext(ctx) | ||
|
||
// create command script on pod | ||
cmd := exec.CommandContext(ctx, "kubectl", "exec", "-n", namespace, podName, "-c", containerName, "--", "bash", "-c", fmt.Sprintf("echo '%s' > %s/script.sh && chmod +x %s/script.sh", commandStr, workDir, workDir)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
强制依赖了 kubectl
} | ||
s.KubenertesRunner = k8sRunner | ||
} | ||
go func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个本质是检查是否有权限,是个简单操作,不应该异步。
docker 那里异步,是因为下载镜像是耗时操作,且容易出问题,所以里面有个多次尝试。
if err != nil { | ||
log.Fatalf("failed to init kube runner: %v", err) | ||
} | ||
s.KubenertesRunner = k8sRunner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里会对server 结构的结构会造成变动,方法名应该有所体现,checkKubenertes 不合适了。
@@ -404,6 +441,9 @@ func (s *Server) handle(ctx context.Context, event *github.PullRequestEvent) err | |||
if linterConfig.DockerAsRunner.Image != "" { | |||
r = s.dockerRunner | |||
} | |||
if linterConfig.KubernetesAsRunner.Image != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是多个条件选择一个,看来这块的代码改为 switch 更合适
podName := k.getJobNameWithPrefix(ctx, cfg.KubernetesAsRunner.Namespace, createdjob.Name) | ||
namespace := cfg.KubernetesAsRunner.Namespace | ||
|
||
// copy ssh to pod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该设计成可选择的
type KubernetesAsRunner struct { | ||
Namespace string `json:"namespace"` | ||
Image string `json:"image"` | ||
SSHKeyMount string `json:"sshkeyMount,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来叫 CopySSHKeyToPod
更贴切
link #313 |
No description provided.