Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
6dd86221
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看板
提交
6dd86221
编写于
5月 12, 2019
作者:
J
Jeff
提交者:
zryfish
5月 12, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix update router bug
上级
692de802
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
44 deletion
+71
-44
pkg/controller/namespace/namespace_controller.go
pkg/controller/namespace/namespace_controller.go
+46
-0
pkg/models/routers/routers.go
pkg/models/routers/routers.go
+25
-44
未找到文件。
pkg/controller/namespace/namespace_controller.go
浏览文件 @
6dd86221
...
...
@@ -22,6 +22,7 @@ import (
"context"
"fmt"
"github.com/golang/glog"
appsv1
"k8s.io/api/apps/v1"
corev1
"k8s.io/api/core/v1"
rbac
"k8s.io/api/rbac/v1"
"k8s.io/api/storage/v1"
...
...
@@ -122,6 +123,11 @@ func (r *ReconcileNamespace) Reconcile(request reconcile.Request) (reconcile.Res
if
!
instance
.
ObjectMeta
.
DeletionTimestamp
.
IsZero
()
{
// The object is being deleted
if
err
:=
r
.
deleteRouter
(
instance
.
Name
);
err
!=
nil
{
return
reconcile
.
Result
{},
err
}
if
err
:=
r
.
deleteRuntime
(
instance
);
err
!=
nil
{
// if fail to delete the external dependency here, return with error
// so that it can be retried
...
...
@@ -442,3 +448,43 @@ func (r *ReconcileNamespace) checkAndCreateCephSecret(namespace *corev1.Namespac
return
nil
}
func
(
r
*
ReconcileNamespace
)
deleteRouter
(
namespace
string
)
error
{
routerName
:=
constants
.
IngressControllerPrefix
+
namespace
// delete service first
found
:=
corev1
.
Service
{}
err
:=
r
.
Get
(
context
.
TODO
(),
types
.
NamespacedName
{
Namespace
:
constants
.
IngressControllerNamespace
,
Name
:
routerName
},
&
found
)
if
err
!=
nil
{
if
errors
.
IsNotFound
(
err
)
{
return
nil
}
log
.
V
(
2
)
.
Info
(
"get router service failed"
,
err
)
}
err
=
r
.
Delete
(
context
.
TODO
(),
&
found
)
if
err
!=
nil
{
log
.
Error
(
err
,
"delete router failed"
)
return
err
}
// delete deployment
deploy
:=
appsv1
.
Deployment
{}
err
=
r
.
Get
(
context
.
TODO
(),
types
.
NamespacedName
{
Namespace
:
constants
.
IngressControllerNamespace
,
Name
:
routerName
},
&
deploy
)
if
err
!=
nil
{
if
errors
.
IsNotFound
(
err
)
{
return
nil
}
log
.
V
(
2
)
.
Info
(
"get router deployment failed"
,
err
)
return
err
}
err
=
r
.
Delete
(
context
.
TODO
(),
&
deploy
)
if
err
!=
nil
{
log
.
Error
(
err
,
"delete router deployment failed"
)
return
err
}
return
nil
}
pkg/models/routers/routers.go
浏览文件 @
6dd86221
...
...
@@ -19,7 +19,6 @@
package
routers
import
(
"fmt"
"github.com/golang/glog"
"io/ioutil"
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -118,22 +117,19 @@ func GetAllRouters() ([]*corev1.Service, error) {
func
GetRouter
(
namespace
string
)
(
*
corev1
.
Service
,
error
)
{
serviceName
:=
constants
.
IngressControllerPrefix
+
namespace
selector
:=
labels
.
SelectorFromSet
(
labels
.
Set
{
"app"
:
"kubesphere"
,
"component"
:
"ks-router"
,
"tier"
:
"backend"
,
"project"
:
namespace
})
serviceLister
:=
informers
.
SharedInformerFactory
()
.
Core
()
.
V1
()
.
Services
()
.
Lister
()
service
s
,
err
:=
serviceLister
.
Services
(
constants
.
IngressControllerNamespace
)
.
List
(
selector
)
service
,
err
:=
serviceLister
.
Services
(
constants
.
IngressControllerNamespace
)
.
Get
(
serviceName
)
if
err
!=
nil
{
if
errors
.
IsNotFound
(
err
)
{
return
nil
,
errors
.
NewNotFound
(
corev1
.
Resource
(
"service"
),
serviceName
)
}
glog
.
Error
(
err
)
return
nil
,
err
}
for
i
:=
range
services
{
if
services
[
i
]
.
Name
==
serviceName
{
addLoadBalancerIp
(
services
[
i
])
return
services
[
i
],
nil
}
}
return
nil
,
errors
.
NewNotFound
(
corev1
.
Resource
(
"service"
),
serviceName
)
addLoadBalancerIp
(
service
)
return
service
,
nil
}
// Load all resource yamls
...
...
@@ -262,49 +258,40 @@ func DeleteRouter(namespace string) (*corev1.Service, error) {
var
err
error
var
router
*
corev1
.
Service
if
err
!=
nil
{
glog
.
Error
(
err
)
}
// delete controller service
serviceName
:=
constants
.
IngressControllerPrefix
+
namespace
deleteOptions
:=
meta_v1
.
DeleteOptions
{}
listOptions
:=
meta_v1
.
ListOptions
{
LabelSelector
:
"app=kubesphere,component=ks-router,tier=backend,project="
+
namespace
,
FieldSelector
:
"metadata.name="
+
serviceName
}
serviceList
,
err
:=
k8sClient
.
CoreV1
()
.
Services
(
constants
.
IngressControllerNamespace
)
.
List
(
listOptions
)
err
=
k8sClient
.
CoreV1
()
.
Services
(
constants
.
IngressControllerNamespace
)
.
Delete
(
serviceName
,
&
deleteOptions
)
if
err
!=
nil
{
glog
.
Error
(
err
)
}
if
len
(
serviceList
.
Items
)
>
0
{
router
=
&
serviceList
.
Items
[
0
]
err
=
k8sClient
.
CoreV1
()
.
Services
(
constants
.
IngressControllerNamespace
)
.
Delete
(
serviceName
,
&
deleteOptions
)
if
err
!=
nil
{
glog
.
Error
(
err
)
}
}
// delete controller deployment
deploymentName
:=
constants
.
IngressControllerPrefix
+
namespace
listOptions
=
meta_v1
.
ListOptions
{
LabelSelector
:
"app=kubesphere,component=ks-router,tier=backend,project="
+
namespace
,
}
deployments
,
err
:=
k8sClient
.
ExtensionsV1beta1
()
.
Deployments
(
constants
.
IngressControllerNamespace
)
.
List
(
listOptions
)
err
=
k8sClient
.
ExtensionsV1beta1
()
.
Deployments
(
constants
.
IngressControllerNamespace
)
.
Delete
(
deploymentName
,
&
deleteOptions
)
if
err
!=
nil
{
glog
.
Error
(
err
)
}
if
len
(
deployments
.
Items
)
>
0
{
err
=
k8sClient
.
ExtensionsV1beta1
()
.
Deployments
(
constants
.
IngressControllerNamespace
)
.
Delete
(
deploymentName
,
&
deleteOptions
)
// delete replicaset if there are any
selector
:=
labels
.
SelectorFromSet
(
labels
.
Set
{
"app"
:
"kubesphere"
,
"component"
:
"ks-router"
,
"tier"
:
"backend"
,
"project"
:
deploymentName
,
})
replicaSetLister
:=
informers
.
SharedInformerFactory
()
.
Apps
()
.
V1
()
.
ReplicaSets
()
.
Lister
()
replicaSets
,
err
:=
replicaSetLister
.
ReplicaSets
(
constants
.
IngressControllerNamespace
)
.
List
(
selector
)
if
err
==
nil
{
glog
.
Error
(
err
)
}
if
err
!=
nil
{
glog
.
Error
(
err
)
}
for
i
:=
range
replicaSets
{
err
=
k8sClient
.
AppsV1
()
.
ReplicaSets
(
constants
.
IngressControllerNamespace
)
.
Delete
(
replicaSets
[
i
]
.
Name
,
&
deleteOptions
)
glog
.
Error
(
err
)
}
return
router
,
nil
...
...
@@ -321,11 +308,6 @@ func UpdateRouter(namespace string, routerType corev1.ServiceType, annotations m
return
router
,
nil
}
if
router
==
nil
{
glog
.
Error
(
"Trying to update a non-existed router"
)
return
nil
,
fmt
.
Errorf
(
"router not created yet"
)
}
router
,
err
=
DeleteRouter
(
namespace
)
if
err
!=
nil
{
...
...
@@ -338,6 +320,5 @@ func UpdateRouter(namespace string, routerType corev1.ServiceType, annotations m
glog
.
Error
(
err
)
}
addLoadBalancerIp
(
router
)
return
router
,
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录