Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
e72b0be0
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
e72b0be0
编写于
11月 06, 2019
作者:
R
runzexia
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
job rerun with resourceVersion
Signed-off-by:
N
runzexia
<
runzexia@yunify.com
>
上级
0c11778e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
22 addition
and
5 deletion
+22
-5
pkg/apis/operations/v1alpha2/register.go
pkg/apis/operations/v1alpha2/register.go
+1
-0
pkg/apis/resources/v1alpha2/register.go
pkg/apis/resources/v1alpha2/register.go
+1
-0
pkg/apiserver/operations/job.go
pkg/apiserver/operations/job.go
+7
-1
pkg/models/workloads/jobs.go
pkg/models/workloads/jobs.go
+13
-4
未找到文件。
pkg/apis/operations/v1alpha2/register.go
浏览文件 @
e72b0be0
...
...
@@ -54,6 +54,7 @@ func addWebService(c *restful.Container) error {
Param
(
webservice
.
PathParameter
(
"job"
,
"job name"
))
.
Param
(
webservice
.
PathParameter
(
"namespace"
,
"the name of the namespace where the job runs in"
))
.
Param
(
webservice
.
QueryParameter
(
"action"
,
"action must be
\"
rerun
\"
"
))
.
Param
(
webservice
.
QueryParameter
(
"resourceVersion"
,
"version of job, rerun when the version matches"
))
.
Returns
(
http
.
StatusOK
,
ok
,
errors
.
Error
{}))
c
.
Add
(
webservice
)
...
...
pkg/apis/resources/v1alpha2/register.go
浏览文件 @
e72b0be0
...
...
@@ -82,6 +82,7 @@ func addWebService(c *restful.Container) error {
Param
(
webservice
.
PathParameter
(
"job"
,
"job name"
))
.
Param
(
webservice
.
PathParameter
(
"namespace"
,
"the name of the namespace where the job runs in"
))
.
Param
(
webservice
.
QueryParameter
(
"action"
,
"action must be
\"
rerun
\"
"
))
.
Param
(
webservice
.
QueryParameter
(
"resourceVersion"
,
"version of job, rerun when the version matches"
))
.
Returns
(
http
.
StatusOK
,
ok
,
errors
.
Error
{}))
webservice
.
Route
(
webservice
.
GET
(
"/{resources}"
)
.
...
...
pkg/apiserver/operations/job.go
浏览文件 @
e72b0be0
...
...
@@ -19,6 +19,7 @@
package
operations
import
(
k8serr
"k8s.io/apimachinery/pkg/api/errors"
"kubesphere.io/kubesphere/pkg/models/workloads"
"kubesphere.io/kubesphere/pkg/server/errors"
"net/http"
...
...
@@ -34,15 +35,20 @@ func RerunJob(req *restful.Request, resp *restful.Response) {
job
:=
req
.
PathParameter
(
"job"
)
namespace
:=
req
.
PathParameter
(
"namespace"
)
action
:=
req
.
QueryParameter
(
"action"
)
resourceVersion
:=
req
.
QueryParameter
(
"resourceVersion"
)
switch
action
{
case
"rerun"
:
err
=
workloads
.
JobReRun
(
namespace
,
job
)
err
=
workloads
.
JobReRun
(
namespace
,
job
,
resourceVersion
)
default
:
resp
.
WriteHeaderAndEntity
(
http
.
StatusBadRequest
,
errors
.
Wrap
(
fmt
.
Errorf
(
"invalid operation %s"
,
action
)))
return
}
if
err
!=
nil
{
if
k8serr
.
IsConflict
(
err
)
{
resp
.
WriteHeaderAndEntity
(
http
.
StatusConflict
,
errors
.
Wrap
(
err
))
return
}
resp
.
WriteHeaderAndEntity
(
http
.
StatusInternalServerError
,
errors
.
Wrap
(
err
))
return
}
...
...
pkg/models/workloads/jobs.go
浏览文件 @
e72b0be0
...
...
@@ -19,23 +19,32 @@ package workloads
import
(
"fmt"
"k8s.io/api/batch/v1"
k8serr
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/simple/client"
"strings"
"time"
"k8s.io/api/batch/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
)
const
retryTimes
=
3
func
JobReRun
(
namespace
,
jobName
string
)
error
{
func
JobReRun
(
namespace
,
jobName
,
resourceVersion
string
)
error
{
k8sClient
:=
client
.
ClientSets
()
.
K8s
()
.
Kubernetes
()
job
,
err
:=
k8sClient
.
BatchV1
()
.
Jobs
(
namespace
)
.
Get
(
jobName
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
err
}
// do not rerun job if resourceVersion not match
if
job
.
GetObjectMeta
()
.
GetResourceVersion
()
!=
resourceVersion
{
err
:=
k8serr
.
NewConflict
(
schema
.
GroupResource
{
Group
:
job
.
GetObjectKind
()
.
GroupVersionKind
()
.
Group
,
Resource
:
"job"
,
},
jobName
,
fmt
.
Errorf
(
"please apply your changes to the latest version and try again"
))
klog
.
Warning
(
err
)
return
err
}
newJob
:=
*
job
newJob
.
ResourceVersion
=
""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录