Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
98f44fac
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
98f44fac
编写于
5月 01, 2020
作者:
Z
zryfish
提交者:
GitHub
5月 01, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix generation bug (#2043)
上级
933207d2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
14 deletion
+69
-14
pkg/controller/cluster/cluster_controller.go
pkg/controller/cluster/cluster_controller.go
+10
-0
pkg/kapis/cluster/v1alpha1/handler.go
pkg/kapis/cluster/v1alpha1/handler.go
+11
-0
pkg/kapis/cluster/v1alpha1/handler_test.go
pkg/kapis/cluster/v1alpha1/handler_test.go
+48
-14
未找到文件。
pkg/controller/cluster/cluster_controller.go
浏览文件 @
98f44fac
...
@@ -309,6 +309,16 @@ func (c *ClusterController) syncCluster(key string) error {
...
@@ -309,6 +309,16 @@ func (c *ClusterController) syncCluster(key string) error {
cluster
.
Spec
.
Connection
.
KubernetesAPIEndpoint
=
fmt
.
Sprintf
(
"https://%s:%d"
,
service
.
Spec
.
ClusterIP
,
kubernetesPort
)
cluster
.
Spec
.
Connection
.
KubernetesAPIEndpoint
=
fmt
.
Sprintf
(
"https://%s:%d"
,
service
.
Spec
.
ClusterIP
,
kubernetesPort
)
cluster
.
Spec
.
Connection
.
KubeSphereAPIEndpoint
=
fmt
.
Sprintf
(
"http://%s:%d"
,
service
.
Spec
.
ClusterIP
,
kubespherePort
)
cluster
.
Spec
.
Connection
.
KubeSphereAPIEndpoint
=
fmt
.
Sprintf
(
"http://%s:%d"
,
service
.
Spec
.
ClusterIP
,
kubespherePort
)
initializedCondition
:=
clusterv1alpha1
.
ClusterCondition
{
Type
:
clusterv1alpha1
.
ClusterInitialized
,
Status
:
v1
.
ConditionTrue
,
Reason
:
string
(
clusterv1alpha1
.
ClusterInitialized
),
Message
:
"Cluster has been initialized"
,
LastUpdateTime
:
metav1
.
Now
(),
LastTransitionTime
:
metav1
.
Now
(),
}
c
.
updateClusterCondition
(
cluster
,
initializedCondition
)
if
!
reflect
.
DeepEqual
(
oldCluster
.
Spec
,
cluster
.
Spec
)
{
if
!
reflect
.
DeepEqual
(
oldCluster
.
Spec
,
cluster
.
Spec
)
{
cluster
,
err
=
c
.
clusterClient
.
Update
(
cluster
)
cluster
,
err
=
c
.
clusterClient
.
Update
(
cluster
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kapis/cluster/v1alpha1/handler.go
浏览文件 @
98f44fac
...
@@ -23,6 +23,8 @@ const (
...
@@ -23,6 +23,8 @@ const (
defaultAgentImage
=
"kubesphere/tower:v1.0"
defaultAgentImage
=
"kubesphere/tower:v1.0"
)
)
var
ErrClusterConnectionIsNotProxy
=
fmt
.
Errorf
(
"cluster is not using proxy connection"
)
type
handler
struct
{
type
handler
struct
{
serviceLister
v1
.
ServiceLister
serviceLister
v1
.
ServiceLister
clusterLister
clusterlister
.
ClusterLister
clusterLister
clusterlister
.
ClusterLister
...
@@ -62,6 +64,11 @@ func (h *handler) GenerateAgentDeployment(request *restful.Request, response *re
...
@@ -62,6 +64,11 @@ func (h *handler) GenerateAgentDeployment(request *restful.Request, response *re
}
}
}
}
if
cluster
.
Spec
.
Connection
.
Type
!=
v1alpha1
.
ConnectionTypeProxy
{
api
.
HandleNotFound
(
response
,
request
,
fmt
.
Errorf
(
"cluster %s is not using proxy connection"
,
cluster
.
Name
))
return
}
// use service ingress address
// use service ingress address
if
len
(
h
.
proxyAddress
)
==
0
{
if
len
(
h
.
proxyAddress
)
==
0
{
err
=
h
.
populateProxyAddress
()
err
=
h
.
populateProxyAddress
()
...
@@ -126,6 +133,10 @@ func (h *handler) populateProxyAddress() error {
...
@@ -126,6 +133,10 @@ func (h *handler) populateProxyAddress() error {
func
(
h
*
handler
)
generateDefaultDeployment
(
cluster
*
v1alpha1
.
Cluster
,
w
io
.
Writer
)
error
{
func
(
h
*
handler
)
generateDefaultDeployment
(
cluster
*
v1alpha1
.
Cluster
,
w
io
.
Writer
)
error
{
if
cluster
.
Spec
.
Connection
.
Type
==
v1alpha1
.
ConnectionTypeDirect
{
return
ErrClusterConnectionIsNotProxy
}
agent
:=
appsv1
.
Deployment
{
agent
:=
appsv1
.
Deployment
{
TypeMeta
:
metav1
.
TypeMeta
{
TypeMeta
:
metav1
.
TypeMeta
{
Kind
:
"Deployment"
,
Kind
:
"Deployment"
,
...
...
pkg/kapis/cluster/v1alpha1/handler_test.go
浏览文件 @
98f44fac
...
@@ -98,23 +98,57 @@ func TestGeranteAgentDeployment(t *testing.T) {
...
@@ -98,23 +98,57 @@ func TestGeranteAgentDeployment(t *testing.T) {
informersFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Services
()
.
Informer
()
.
GetIndexer
()
.
Add
(
service
)
informersFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Services
()
.
Informer
()
.
GetIndexer
()
.
Add
(
service
)
informersFactory
.
KubeSphereSharedInformerFactory
()
.
Cluster
()
.
V1alpha1
()
.
Clusters
()
.
Informer
()
.
GetIndexer
()
.
Add
(
cluster
)
informersFactory
.
KubeSphereSharedInformerFactory
()
.
Cluster
()
.
V1alpha1
()
.
Clusters
()
.
Informer
()
.
GetIndexer
()
.
Add
(
cluster
)
h
:=
NewHandler
(
informersFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Services
()
.
Lister
(),
directConnectionCluster
:=
cluster
.
DeepCopy
()
informersFactory
.
KubeSphereSharedInformerFactory
()
.
Cluster
()
.
V1alpha1
()
.
Clusters
()
.
Lister
(),
directConnectionCluster
.
Spec
.
Connection
.
Type
=
v1alpha1
.
ConnectionTypeDirect
proxyService
,
""
,
var
testCases
=
[]
struct
{
agentImage
)
description
string
expectingError
bool
var
buf
bytes
.
Buffer
expectedError
error
cluster
*
v1alpha1
.
Cluster
err
:=
h
.
populateProxyAddress
()
expected
string
if
err
!=
nil
{
}{
t
.
Error
(
err
)
{
description
:
"test normal case"
,
expectingError
:
false
,
expected
:
expected
,
cluster
:
cluster
,
},
{
description
:
"test direct connection cluster"
,
expectingError
:
true
,
expectedError
:
ErrClusterConnectionIsNotProxy
,
cluster
:
directConnectionCluster
,
},
}
}
err
=
h
.
generateDefaultDeployment
(
cluster
,
&
buf
)
for
_
,
testCase
:=
range
testCases
{
if
diff
:=
cmp
.
Diff
(
buf
.
String
(),
expected
);
len
(
diff
)
!=
0
{
t
.
Error
(
diff
)
t
.
Run
(
testCase
.
description
,
func
(
t
*
testing
.
T
)
{
h
:=
NewHandler
(
informersFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Services
()
.
Lister
(),
informersFactory
.
KubeSphereSharedInformerFactory
()
.
Cluster
()
.
V1alpha1
()
.
Clusters
()
.
Lister
(),
proxyService
,
""
,
agentImage
)
var
buf
bytes
.
Buffer
err
:=
h
.
populateProxyAddress
()
if
err
!=
nil
{
t
.
Error
(
err
)
}
err
=
h
.
generateDefaultDeployment
(
testCase
.
cluster
,
&
buf
)
if
testCase
.
expectingError
{
if
err
==
nil
{
t
.
Fatalf
(
"expecting error %v, got nil"
,
testCase
.
expectedError
)
}
else
if
err
!=
testCase
.
expectedError
{
t
.
Fatalf
(
"expecting error %v, got %v"
,
testCase
.
expectedError
,
err
)
}
}
})
}
}
}
}
func
TestInnerGenerateAgentDeployment
(
t
*
testing
.
T
)
{
func
TestInnerGenerateAgentDeployment
(
t
*
testing
.
T
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录