Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
3d11687d
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看板
提交
3d11687d
编写于
5月 13, 2019
作者:
R
runzexia
提交者:
zryfish
5月 15, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete all devops project when delete ws
Signed-off-by:
N
runzexia
<
runzexia@yunify.com
>
上级
5c322256
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
115 addition
and
1 deletion
+115
-1
pkg/controller/workspace/workspace_controller.go
pkg/controller/workspace/workspace_controller.go
+39
-0
pkg/models/devops/project.go
pkg/models/devops/project.go
+5
-0
pkg/simple/client/kubesphere/kubesphereclient.go
pkg/simple/client/kubesphere/kubesphereclient.go
+71
-1
未找到文件。
pkg/controller/workspace/workspace_controller.go
浏览文件 @
3d11687d
...
...
@@ -43,6 +43,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
logf
"sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/source"
"sync"
)
const
(
...
...
@@ -137,6 +138,10 @@ func (r *ReconcileWorkspace) Reconcile(request reconcile.Request) (reconcile.Res
return
reconcile
.
Result
{},
err
}
if
err
:=
r
.
deleteDevOpsProjects
(
instance
);
err
!=
nil
{
return
reconcile
.
Result
{},
err
}
// remove our finalizer from the list and update it.
instance
.
ObjectMeta
.
Finalizers
=
sliceutil
.
RemoveString
(
instance
.
ObjectMeta
.
Finalizers
,
func
(
item
string
)
bool
{
return
item
==
finalizer
...
...
@@ -327,6 +332,40 @@ func (r *ReconcileWorkspace) deleteGroup(instance *tenantv1alpha1.Workspace) err
return
nil
}
func
(
r
*
ReconcileWorkspace
)
deleteDevOpsProjects
(
instance
*
tenantv1alpha1
.
Workspace
)
error
{
var
wg
sync
.
WaitGroup
log
.
Info
(
"Delete DevOps Projects"
)
for
{
errChan
:=
make
(
chan
error
,
10
)
projects
,
err
:=
r
.
ksclient
.
ListWorkspaceDevOpsProjects
(
instance
.
Name
)
if
err
!=
nil
{
log
.
Error
(
err
,
"Failed to Get Workspace's DevOps Projects"
,
"ws"
,
instance
.
Name
)
return
err
}
if
projects
.
TotalCount
==
0
{
return
nil
}
for
_
,
project
:=
range
projects
.
Items
{
wg
.
Add
(
1
)
go
func
(
workspace
,
devops
string
)
{
err
:=
r
.
ksclient
.
DeleteWorkspaceDevOpsProjects
(
workspace
,
devops
)
errChan
<-
err
wg
.
Done
()
}(
instance
.
Name
,
project
.
ProjectId
)
}
wg
.
Wait
()
close
(
errChan
)
for
err
:=
range
errChan
{
if
err
!=
nil
{
log
.
Error
(
err
,
"delete devops project error"
)
return
err
}
}
}
}
func
(
r
*
ReconcileWorkspace
)
createWorkspaceRoleBindings
(
instance
*
tenantv1alpha1
.
Workspace
)
error
{
adminRoleBinding
:=
&
rbac
.
ClusterRoleBinding
{}
...
...
pkg/models/devops/project.go
浏览文件 @
3d11687d
...
...
@@ -31,6 +31,11 @@ const (
DevOpsProjectCreateTimeColumn
=
"project.create_time"
)
type
PageableDevOpsProject
struct
{
Items
[]
*
DevOpsProject
`json:"items"`
TotalCount
int
`json:"total_count"`
}
type
DevOpsProject
struct
{
ProjectId
string
`json:"project_id" db:"project_id"`
Name
string
`json:"name"`
...
...
pkg/simple/client/kubesphere/kubesphereclient.go
浏览文件 @
3d11687d
...
...
@@ -23,7 +23,9 @@ import (
"flag"
"fmt"
"io/ioutil"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/models/devops"
"log"
"net/http"
"strings"
...
...
@@ -32,7 +34,7 @@ import (
var
(
accountAPIServer
string
devopsAPIServer
string
ksAPIServer
string
once
sync
.
Once
c
client
)
...
...
@@ -43,6 +45,8 @@ type Interface interface {
DescribeGroup
(
name
string
)
(
*
models
.
Group
,
error
)
DeleteGroup
(
name
string
)
error
ListUsers
()
(
*
models
.
PageableResponse
,
error
)
ListWorkspaceDevOpsProjects
(
workspace
string
)
(
*
devops
.
PageableDevOpsProject
,
error
)
DeleteWorkspaceDevOpsProjects
(
workspace
,
devops
string
)
error
}
type
client
struct
{
...
...
@@ -51,6 +55,7 @@ type client struct {
func
init
()
{
flag
.
StringVar
(
&
accountAPIServer
,
"ks-account-api-server"
,
"http://ks-account.kubesphere-system.svc"
,
"kubesphere account api server"
)
flag
.
StringVar
(
&
ksAPIServer
,
"ks-api-server"
,
"http://ks-apiserver.kubesphere-system.svc"
,
"kubesphere api server"
)
}
func
Client
()
Interface
{
...
...
@@ -248,6 +253,71 @@ func (c client) ListUsers() (*models.PageableResponse, error) {
return
&
result
,
nil
}
func
(
c
client
)
ListWorkspaceDevOpsProjects
(
workspace
string
)
(
*
devops
.
PageableDevOpsProject
,
error
)
{
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
fmt
.
Sprintf
(
"%s/kapis/tenant.kubesphere.io/v1alpha2/workspaces/%s/devops"
,
ksAPIServer
,
workspace
),
nil
)
if
err
!=
nil
{
return
nil
,
err
}
req
.
Header
.
Add
(
constants
.
UserNameHeader
,
constants
.
AdminUserName
)
if
err
!=
nil
{
return
nil
,
err
}
log
.
Println
(
req
.
Method
,
req
.
URL
)
resp
,
err
:=
c
.
client
.
Do
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
data
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
nil
,
err
}
if
resp
.
StatusCode
>
http
.
StatusOK
{
return
nil
,
Error
{
resp
.
StatusCode
,
string
(
data
)}
}
var
result
devops
.
PageableDevOpsProject
err
=
json
.
Unmarshal
(
data
,
&
result
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
result
,
nil
}
func
(
c
client
)
DeleteWorkspaceDevOpsProjects
(
workspace
,
devops
string
)
error
{
req
,
err
:=
http
.
NewRequest
(
http
.
MethodDelete
,
fmt
.
Sprintf
(
"%s/kapis/tenant.kubesphere.io/v1alpha2/workspaces/%s/devops/%s"
,
ksAPIServer
,
workspace
,
devops
),
nil
)
if
err
!=
nil
{
return
err
}
req
.
Header
.
Add
(
constants
.
UserNameHeader
,
constants
.
AdminUserName
)
if
err
!=
nil
{
return
err
}
log
.
Println
(
req
.
Method
,
req
.
URL
)
resp
,
err
:=
c
.
client
.
Do
(
req
)
if
err
!=
nil
{
return
err
}
defer
resp
.
Body
.
Close
()
data
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
err
}
if
resp
.
StatusCode
>
http
.
StatusOK
{
return
Error
{
resp
.
StatusCode
,
string
(
data
)}
}
return
nil
}
func
IsNotFound
(
err
error
)
bool
{
if
e
,
ok
:=
err
.
(
Error
);
ok
{
if
e
.
status
==
http
.
StatusNotFound
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录