Skip to content

Conversation

wwcchh0123
Copy link
Contributor

No description provided.

Copy link

netlify bot commented Oct 9, 2024

Deploy Preview for reviewbot-x canceled.

Name Link
🔨 Latest commit 9084bab
🔍 Latest deploy log https://app.netlify.com/sites/reviewbot-x/deploys/670cf48094bfe6000926526a

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 0% with 189 lines in your changes missing coverage. Please review.

Project coverage is 32.91%. Comparing base (d042c56) to head (9084bab).
Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
internal/runner/kubenertes.go 0.00% 156 Missing ⚠️
server.go 0.00% 24 Missing ⚠️
config/config.go 0.00% 4 Missing and 3 partials ⚠️
main.go 0.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

k.script = scriptContent

// create default config
// Note(wwcchh0123): support unmarshalling YAML into structures in the future
Copy link
Contributor

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)
Copy link
Contributor

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{})
Copy link
Contributor

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)
Copy link
Contributor

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))
Copy link
Contributor

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() {
Copy link
Contributor

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
Copy link
Contributor

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 != "" {
Copy link
Contributor

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
Copy link
Contributor

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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来叫 CopySSHKeyToPod 更贴切

@CarlJi CarlJi merged commit 146c6f6 into qiniu:master Oct 18, 2024
7 of 8 checks passed
@CarlJi
Copy link
Contributor

CarlJi commented Oct 18, 2024

link #313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants