Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
5d954202
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看板
未验证
提交
5d954202
编写于
6月 15, 2020
作者:
Z
zryfish
提交者:
GitHub
6月 15, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
create openpitrix runtime when new cluster added (#2204)
上级
bef5eb46
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
169 addition
and
49 deletion
+169
-49
cmd/controller-manager/app/controllers.go
cmd/controller-manager/app/controllers.go
+61
-42
cmd/controller-manager/app/options/options.go
cmd/controller-manager/app/options/options.go
+13
-1
cmd/controller-manager/app/server.go
cmd/controller-manager/app/server.go
+13
-5
pkg/apis/cluster/v1alpha1/cluster_types.go
pkg/apis/cluster/v1alpha1/cluster_types.go
+3
-0
pkg/controller/cluster/cluster_controller.go
pkg/controller/cluster/cluster_controller.go
+35
-1
test/testdata/certs/tls.crt
test/testdata/certs/tls.crt
+17
-0
test/testdata/certs/tls.key
test/testdata/certs/tls.key
+27
-0
未找到文件。
cmd/controller-manager/app/controllers.go
浏览文件 @
5d954202
...
@@ -48,18 +48,21 @@ import (
...
@@ -48,18 +48,21 @@ import (
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/kubefed/pkg/controller/util"
"sigs.k8s.io/kubefed/pkg/controller/util"
)
)
func
A
ddControllers
(
func
a
ddControllers
(
mgr
manager
.
Manager
,
mgr
manager
.
Manager
,
client
k8s
.
Client
,
client
k8s
.
Client
,
informerFactory
informers
.
InformerFactory
,
informerFactory
informers
.
InformerFactory
,
devopsClient
devops
.
Interface
,
devopsClient
devops
.
Interface
,
s3Client
s3
.
Interface
,
s3Client
s3
.
Interface
,
openpitrixClient
openpitrix
.
Client
,
multiClusterEnabled
bool
,
multiClusterEnabled
bool
,
networkPolicyEnabled
bool
,
stopCh
<-
chan
struct
{})
error
{
stopCh
<-
chan
struct
{})
error
{
kubernetesInformer
:=
informerFactory
.
KubernetesSharedInformerFactory
()
kubernetesInformer
:=
informerFactory
.
KubernetesSharedInformerFactory
()
...
@@ -94,33 +97,37 @@ func AddControllers(
...
@@ -94,33 +97,37 @@ func AddControllers(
jobController
:=
job
.
NewJobController
(
kubernetesInformer
.
Batch
()
.
V1
()
.
Jobs
(),
client
.
Kubernetes
())
jobController
:=
job
.
NewJobController
(
kubernetesInformer
.
Batch
()
.
V1
()
.
Jobs
(),
client
.
Kubernetes
())
s2iBinaryController
:=
s2ibinary
.
NewController
(
client
.
Kubernetes
(),
var
s2iBinaryController
,
s2iRunController
,
devopsProjectController
,
devopsPipelineController
,
devopsCredentialController
manager
.
Runnable
client
.
KubeSphere
(),
if
devopsClient
!=
nil
{
kubesphereInformer
.
Devops
()
.
V1alpha1
()
.
S2iBinaries
(),
s2iBinaryController
=
s2ibinary
.
NewController
(
client
.
Kubernetes
(),
s3Client
,
client
.
KubeSphere
(),
)
kubesphereInformer
.
Devops
()
.
V1alpha1
()
.
S2iBinaries
(),
s3Client
,
s2iRunController
:=
s2irun
.
NewS2iRunController
(
client
.
Kubernetes
(),
)
client
.
KubeSphere
(),
kubesphereInformer
.
Devops
()
.
V1alpha1
()
.
S2iBinaries
(),
s2iRunController
=
s2irun
.
NewS2iRunController
(
client
.
Kubernetes
(),
kubesphereInformer
.
Devops
()
.
V1alpha1
()
.
S2iRuns
())
client
.
KubeSphere
(),
kubesphereInformer
.
Devops
()
.
V1alpha1
()
.
S2iBinaries
(),
devopsProjectController
:=
devopsproject
.
NewController
(
client
.
Kubernetes
(),
kubesphereInformer
.
Devops
()
.
V1alpha1
()
.
S2iRuns
())
client
.
KubeSphere
(),
devopsClient
,
informerFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Namespaces
(),
devopsProjectController
=
devopsproject
.
NewController
(
client
.
Kubernetes
(),
informerFactory
.
KubeSphereSharedInformerFactory
()
.
Devops
()
.
V1alpha3
()
.
DevOpsProjects
(),
client
.
KubeSphere
(),
devopsClient
,
)
informerFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Namespaces
(),
informerFactory
.
KubeSphereSharedInformerFactory
()
.
Devops
()
.
V1alpha3
()
.
DevOpsProjects
(),
devopsPipelineController
:=
pipeline
.
NewController
(
client
.
Kubernetes
(),
)
client
.
KubeSphere
(),
devopsClient
,
devopsPipelineController
=
pipeline
.
NewController
(
client
.
Kubernetes
(),
informerFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Namespaces
(),
client
.
KubeSphere
(),
informerFactory
.
KubeSphereSharedInformerFactory
()
.
Devops
()
.
V1alpha3
()
.
Pipelines
())
devopsClient
,
informerFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Namespaces
(),
informerFactory
.
KubeSphereSharedInformerFactory
()
.
Devops
()
.
V1alpha3
()
.
Pipelines
())
devopsCredentialController
=
devopscredential
.
NewController
(
client
.
Kubernetes
(),
devopsClient
,
informerFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Namespaces
(),
informerFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Secrets
())
devopsCredentialController
:=
devopscredential
.
NewController
(
client
.
Kubernetes
(),
}
devopsClient
,
informerFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Namespaces
(),
informerFactory
.
KubernetesSharedInformerFactory
()
.
Core
()
.
V1
()
.
Secrets
())
storageCapabilityController
:=
capability
.
NewController
(
storageCapabilityController
:=
capability
.
NewController
(
client
.
Kubernetes
(),
client
.
Kubernetes
(),
...
@@ -223,22 +230,29 @@ func AddControllers(
...
@@ -223,22 +230,29 @@ func AddControllers(
kubesphereInformer
.
Iam
()
.
V1alpha2
()
.
RoleBases
(),
kubesphereInformer
.
Iam
()
.
V1alpha2
()
.
WorkspaceRoles
(),
kubesphereInformer
.
Iam
()
.
V1alpha2
()
.
RoleBases
(),
kubesphereInformer
.
Iam
()
.
V1alpha2
()
.
WorkspaceRoles
(),
fedWorkspaceCache
,
fedWorkspaceCacheController
,
multiClusterEnabled
)
fedWorkspaceCache
,
fedWorkspaceCacheController
,
multiClusterEnabled
)
clusterController
:=
cluster
.
NewClusterController
(
var
clusterController
manager
.
Runnable
client
.
Kubernetes
(),
if
multiClusterEnabled
{
client
.
Config
(),
clusterController
=
cluster
.
NewClusterController
(
kubesphereInformer
.
Cluster
()
.
V1alpha1
()
.
Clusters
(),
client
.
Kubernetes
(),
client
.
KubeSphere
()
.
ClusterV1alpha1
()
.
Clusters
())
client
.
Config
(),
kubesphereInformer
.
Cluster
()
.
V1alpha1
()
.
Clusters
(),
nsnpProvider
,
err
:=
provider
.
NewNsNetworkPolicyProvider
(
client
.
Kubernetes
(),
client
.
KubeSphere
()
.
ClusterV1alpha1
()
.
Clusters
(),
kubernetesInformer
.
Networking
()
.
V1
()
.
NetworkPolicies
())
openpitrixClient
)
if
err
!=
nil
{
}
return
err
var
nsnpController
manager
.
Runnable
if
networkPolicyEnabled
{
nsnpProvider
,
err
:=
provider
.
NewNsNetworkPolicyProvider
(
client
.
Kubernetes
(),
kubernetesInformer
.
Networking
()
.
V1
()
.
NetworkPolicies
())
if
err
!=
nil
{
return
err
}
nsnpController
=
nsnetworkpolicy
.
NewNSNetworkPolicyController
(
client
.
Kubernetes
(),
client
.
KubeSphere
()
.
NetworkV1alpha1
(),
kubesphereInformer
.
Network
()
.
V1alpha1
()
.
NamespaceNetworkPolicies
(),
kubernetesInformer
.
Core
()
.
V1
()
.
Services
(),
kubernetesInformer
.
Core
()
.
V1
()
.
Nodes
(),
kubesphereInformer
.
Tenant
()
.
V1alpha1
()
.
Workspaces
(),
kubernetesInformer
.
Core
()
.
V1
()
.
Namespaces
(),
nsnpProvider
)
}
}
nsnpController
:=
nsnetworkpolicy
.
NewNSNetworkPolicyController
(
client
.
Kubernetes
(),
client
.
KubeSphere
()
.
NetworkV1alpha1
(),
kubesphereInformer
.
Network
()
.
V1alpha1
()
.
NamespaceNetworkPolicies
(),
kubernetesInformer
.
Core
()
.
V1
()
.
Services
(),
kubernetesInformer
.
Core
()
.
V1
()
.
Nodes
(),
kubesphereInformer
.
Tenant
()
.
V1alpha1
()
.
Workspaces
(),
kubernetesInformer
.
Core
()
.
V1
()
.
Namespaces
(),
nsnpProvider
)
controllers
:=
map
[
string
]
manager
.
Runnable
{
controllers
:=
map
[
string
]
manager
.
Runnable
{
"virtualservice-controller"
:
vsController
,
"virtualservice-controller"
:
vsController
,
...
@@ -274,6 +288,11 @@ func AddControllers(
...
@@ -274,6 +288,11 @@ func AddControllers(
}
}
for
name
,
ctrl
:=
range
controllers
{
for
name
,
ctrl
:=
range
controllers
{
if
ctrl
==
nil
{
klog
.
V
(
4
)
.
Infof
(
"%s is not going to run due to dependent component disabled."
,
name
)
continue
}
if
err
:=
mgr
.
Add
(
ctrl
);
err
!=
nil
{
if
err
:=
mgr
.
Add
(
ctrl
);
err
!=
nil
{
klog
.
Error
(
err
,
"add controller to manager failed"
,
"name"
,
name
)
klog
.
Error
(
err
,
"add controller to manager failed"
,
"name"
,
name
)
return
err
return
err
...
...
cmd/controller-manager/app/options/options.go
浏览文件 @
5d954202
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/multicluster"
"kubesphere.io/kubesphere/pkg/simple/client/multicluster"
"kubesphere.io/kubesphere/pkg/simple/client/network"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"strings"
"strings"
...
@@ -21,9 +22,11 @@ type KubeSphereControllerManagerOptions struct {
...
@@ -21,9 +22,11 @@ type KubeSphereControllerManagerOptions struct {
DevopsOptions
*
jenkins
.
Options
DevopsOptions
*
jenkins
.
Options
S3Options
*
s3
.
Options
S3Options
*
s3
.
Options
OpenPitrixOptions
*
openpitrix
.
Options
OpenPitrixOptions
*
openpitrix
.
Options
NetworkOptions
*
network
.
Options
MultiClusterOptions
*
multicluster
.
Options
MultiClusterOptions
*
multicluster
.
Options
LeaderElect
bool
LeaderElect
bool
LeaderElection
*
leaderelection
.
LeaderElectionConfig
LeaderElection
*
leaderelection
.
LeaderElectionConfig
WebhookCertDir
string
}
}
func
NewKubeSphereControllerManagerOptions
()
*
KubeSphereControllerManagerOptions
{
func
NewKubeSphereControllerManagerOptions
()
*
KubeSphereControllerManagerOptions
{
...
@@ -32,13 +35,15 @@ func NewKubeSphereControllerManagerOptions() *KubeSphereControllerManagerOptions
...
@@ -32,13 +35,15 @@ func NewKubeSphereControllerManagerOptions() *KubeSphereControllerManagerOptions
DevopsOptions
:
jenkins
.
NewDevopsOptions
(),
DevopsOptions
:
jenkins
.
NewDevopsOptions
(),
S3Options
:
s3
.
NewS3Options
(),
S3Options
:
s3
.
NewS3Options
(),
OpenPitrixOptions
:
openpitrix
.
NewOptions
(),
OpenPitrixOptions
:
openpitrix
.
NewOptions
(),
NetworkOptions
:
network
.
NewNetworkOptions
(),
MultiClusterOptions
:
multicluster
.
NewOptions
(),
MultiClusterOptions
:
multicluster
.
NewOptions
(),
LeaderElection
:
&
leaderelection
.
LeaderElectionConfig
{
LeaderElection
:
&
leaderelection
.
LeaderElectionConfig
{
LeaseDuration
:
30
*
time
.
Second
,
LeaseDuration
:
30
*
time
.
Second
,
RenewDeadline
:
15
*
time
.
Second
,
RenewDeadline
:
15
*
time
.
Second
,
RetryPeriod
:
5
*
time
.
Second
,
RetryPeriod
:
5
*
time
.
Second
,
},
},
LeaderElect
:
false
,
LeaderElect
:
false
,
WebhookCertDir
:
""
,
}
}
return
s
return
s
...
@@ -58,6 +63,7 @@ func (s *KubeSphereControllerManagerOptions) Flags() cliflag.NamedFlagSets {
...
@@ -58,6 +63,7 @@ func (s *KubeSphereControllerManagerOptions) Flags() cliflag.NamedFlagSets {
s
.
DevopsOptions
.
AddFlags
(
fss
.
FlagSet
(
"devops"
),
s
.
DevopsOptions
)
s
.
DevopsOptions
.
AddFlags
(
fss
.
FlagSet
(
"devops"
),
s
.
DevopsOptions
)
s
.
S3Options
.
AddFlags
(
fss
.
FlagSet
(
"s3"
),
s
.
S3Options
)
s
.
S3Options
.
AddFlags
(
fss
.
FlagSet
(
"s3"
),
s
.
S3Options
)
s
.
OpenPitrixOptions
.
AddFlags
(
fss
.
FlagSet
(
"openpitrix"
),
s
.
OpenPitrixOptions
)
s
.
OpenPitrixOptions
.
AddFlags
(
fss
.
FlagSet
(
"openpitrix"
),
s
.
OpenPitrixOptions
)
s
.
NetworkOptions
.
AddFlags
(
fss
.
FlagSet
(
"network"
),
s
.
NetworkOptions
)
s
.
MultiClusterOptions
.
AddFlags
(
fss
.
FlagSet
(
"multicluster"
),
s
.
MultiClusterOptions
)
s
.
MultiClusterOptions
.
AddFlags
(
fss
.
FlagSet
(
"multicluster"
),
s
.
MultiClusterOptions
)
fs
:=
fss
.
FlagSet
(
"leaderelection"
)
fs
:=
fss
.
FlagSet
(
"leaderelection"
)
...
@@ -67,6 +73,11 @@ func (s *KubeSphereControllerManagerOptions) Flags() cliflag.NamedFlagSets {
...
@@ -67,6 +73,11 @@ func (s *KubeSphereControllerManagerOptions) Flags() cliflag.NamedFlagSets {
"Whether to enable leader election. This field should be enabled when controller manager"
+
"Whether to enable leader election. This field should be enabled when controller manager"
+
"deployed with multiple replicas."
)
"deployed with multiple replicas."
)
fs
.
StringVar
(
&
s
.
WebhookCertDir
,
"webhook-cert-dir"
,
s
.
WebhookCertDir
,
""
+
"Certificate directory used to setup webhooks, need tls.crt and tls.key placed inside."
+
"if not set, webhook server would look up the server key and certificate in"
+
"{TempDir}/k8s-webhook-server/serving-certs"
)
kfs
:=
fss
.
FlagSet
(
"klog"
)
kfs
:=
fss
.
FlagSet
(
"klog"
)
local
:=
flag
.
NewFlagSet
(
"klog"
,
flag
.
ExitOnError
)
local
:=
flag
.
NewFlagSet
(
"klog"
,
flag
.
ExitOnError
)
klog
.
InitFlags
(
local
)
klog
.
InitFlags
(
local
)
...
@@ -84,6 +95,7 @@ func (s *KubeSphereControllerManagerOptions) Validate() []error {
...
@@ -84,6 +95,7 @@ func (s *KubeSphereControllerManagerOptions) Validate() []error {
errs
=
append
(
errs
,
s
.
KubernetesOptions
.
Validate
()
...
)
errs
=
append
(
errs
,
s
.
KubernetesOptions
.
Validate
()
...
)
errs
=
append
(
errs
,
s
.
S3Options
.
Validate
()
...
)
errs
=
append
(
errs
,
s
.
S3Options
.
Validate
()
...
)
errs
=
append
(
errs
,
s
.
OpenPitrixOptions
.
Validate
()
...
)
errs
=
append
(
errs
,
s
.
OpenPitrixOptions
.
Validate
()
...
)
errs
=
append
(
errs
,
s
.
NetworkOptions
.
Validate
()
...
)
return
errs
return
errs
}
}
...
...
cmd/controller-manager/app/server.go
浏览文件 @
5d954202
...
@@ -40,6 +40,7 @@ import (
...
@@ -40,6 +40,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"kubesphere.io/kubesphere/pkg/utils/term"
"kubesphere.io/kubesphere/pkg/utils/term"
"os"
"os"
...
@@ -58,6 +59,7 @@ func NewControllerManagerCommand() *cobra.Command {
...
@@ -58,6 +59,7 @@ func NewControllerManagerCommand() *cobra.Command {
DevopsOptions
:
conf
.
DevopsOptions
,
DevopsOptions
:
conf
.
DevopsOptions
,
S3Options
:
conf
.
S3Options
,
S3Options
:
conf
.
S3Options
,
OpenPitrixOptions
:
conf
.
OpenPitrixOptions
,
OpenPitrixOptions
:
conf
.
OpenPitrixOptions
,
NetworkOptions
:
conf
.
NetworkOptions
,
MultiClusterOptions
:
conf
.
MultiClusterOptions
,
MultiClusterOptions
:
conf
.
MultiClusterOptions
,
LeaderElection
:
s
.
LeaderElection
,
LeaderElection
:
s
.
LeaderElection
,
LeaderElect
:
s
.
LeaderElect
,
LeaderElect
:
s
.
LeaderElect
,
...
@@ -111,6 +113,15 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
...
@@ -111,6 +113,15 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
}
}
}
}
var
openpitrixClient
openpitrix
.
Client
if
s
.
OpenPitrixOptions
!=
nil
&&
!
s
.
OpenPitrixOptions
.
IsEmpty
()
{
openpitrixClient
,
err
=
openpitrix
.
NewClient
(
s
.
OpenPitrixOptions
)
if
err
!=
nil
{
klog
.
Errorf
(
"Failed to create openpitrix client %v"
,
err
)
return
err
}
}
var
s3Client
s3
.
Interface
var
s3Client
s3
.
Interface
if
s
.
S3Options
!=
nil
&&
len
(
s
.
S3Options
.
Endpoint
)
!=
0
{
if
s
.
S3Options
!=
nil
&&
len
(
s
.
S3Options
.
Endpoint
)
!=
0
{
s3Client
,
err
=
s3
.
NewS3Client
(
s
.
S3Options
)
s3Client
,
err
=
s3
.
NewS3Client
(
s
.
S3Options
)
...
@@ -125,7 +136,7 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
...
@@ -125,7 +136,7 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
run
:=
func
(
ctx
context
.
Context
)
{
run
:=
func
(
ctx
context
.
Context
)
{
klog
.
V
(
0
)
.
Info
(
"setting up manager"
)
klog
.
V
(
0
)
.
Info
(
"setting up manager"
)
mgr
,
err
:=
manager
.
New
(
kubernetesClient
.
Config
(),
manager
.
Options
{})
mgr
,
err
:=
manager
.
New
(
kubernetesClient
.
Config
(),
manager
.
Options
{
CertDir
:
s
.
WebhookCertDir
})
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
Fatalf
(
"unable to set up overall controller manager: %v"
,
err
)
klog
.
Fatalf
(
"unable to set up overall controller manager: %v"
,
err
)
}
}
...
@@ -146,7 +157,7 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
...
@@ -146,7 +157,7 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
klog
.
Fatal
(
"Unable to create namespace controller"
)
klog
.
Fatal
(
"Unable to create namespace controller"
)
}
}
if
err
:=
AddControllers
(
mgr
,
kubernetesClient
,
informerFactory
,
devopsClient
,
s3Client
,
s
.
MultiClusterOptions
.
Enable
,
stopCh
);
err
!=
nil
{
if
err
:=
addControllers
(
mgr
,
kubernetesClient
,
informerFactory
,
devopsClient
,
s3Client
,
openpitrixClient
,
s
.
MultiClusterOptions
.
Enable
,
s
.
NetworkOptions
.
EnableNetworkPolicy
,
stopCh
);
err
!=
nil
{
klog
.
Fatalf
(
"unable to register controllers to the manager: %v"
,
err
)
klog
.
Fatalf
(
"unable to register controllers to the manager: %v"
,
err
)
}
}
...
@@ -190,9 +201,6 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
...
@@ -190,9 +201,6 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
// add a uniquifier so that two processes on the same host don't accidentally both become active
// add a uniquifier so that two processes on the same host don't accidentally both become active
id
=
id
+
"_"
+
string
(
uuid
.
NewUUID
())
id
=
id
+
"_"
+
string
(
uuid
.
NewUUID
())
// TODO: change lockType to lease
// once we finished moving to Kubernetes v1.16+, we
// change lockType to lease
lock
,
err
:=
resourcelock
.
New
(
resourcelock
.
LeasesResourceLock
,
lock
,
err
:=
resourcelock
.
New
(
resourcelock
.
LeasesResourceLock
,
"kubesphere-system"
,
"kubesphere-system"
,
"ks-controller-manager"
,
"ks-controller-manager"
,
...
...
pkg/apis/cluster/v1alpha1/cluster_types.go
浏览文件 @
5d954202
...
@@ -92,6 +92,9 @@ const (
...
@@ -92,6 +92,9 @@ const (
// Cluster is all available for requests
// Cluster is all available for requests
ClusterReady
ClusterConditionType
=
"Ready"
ClusterReady
ClusterConditionType
=
"Ready"
// Openpitrix runtime is created
ClusterOpenPitrixRuntimeReady
ClusterConditionType
=
"OpenPitrixRuntimeReady"
)
)
type
ClusterCondition
struct
{
type
ClusterCondition
struct
{
...
...
pkg/controller/cluster/cluster_controller.go
浏览文件 @
5d954202
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
clusterclient
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/cluster/v1alpha1"
clusterclient
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/cluster/v1alpha1"
clusterinformer
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/cluster/v1alpha1"
clusterinformer
"kubesphere.io/kubesphere/pkg/client/informers/externalversions/cluster/v1alpha1"
clusterlister
"kubesphere.io/kubesphere/pkg/client/listers/cluster/v1alpha1"
clusterlister
"kubesphere.io/kubesphere/pkg/client/listers/cluster/v1alpha1"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"math/rand"
"math/rand"
"net/http"
"net/http"
"reflect"
"reflect"
...
@@ -50,7 +51,8 @@ const (
...
@@ -50,7 +51,8 @@ const (
// 5ms, 10ms, 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1.3s, 2.6s, 5.1s, 10.2s, 20.4s, 41s, 82s
// 5ms, 10ms, 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1.3s, 2.6s, 5.1s, 10.2s, 20.4s, 41s, 82s
maxRetries
=
15
maxRetries
=
15
kubefedNamespace
=
"kube-federation-system"
kubefedNamespace
=
"kube-federation-system"
openpitrixRuntime
=
"openpitrix.io/runtime"
// Actually host cluster name can be anything, there is only necessary when calling JoinFederation function
// Actually host cluster name can be anything, there is only necessary when calling JoinFederation function
hostClusterName
=
"kubesphere"
hostClusterName
=
"kubesphere"
...
@@ -98,6 +100,8 @@ type clusterController struct {
...
@@ -98,6 +100,8 @@ type clusterController struct {
clusterLister
clusterlister
.
ClusterLister
clusterLister
clusterlister
.
ClusterLister
clusterHasSynced
cache
.
InformerSynced
clusterHasSynced
cache
.
InformerSynced
openpitrixClient
openpitrix
.
Client
queue
workqueue
.
RateLimitingInterface
queue
workqueue
.
RateLimitingInterface
workerLoopPeriod
time
.
Duration
workerLoopPeriod
time
.
Duration
...
@@ -112,6 +116,7 @@ func NewClusterController(
...
@@ -112,6 +116,7 @@ func NewClusterController(
config
*
rest
.
Config
,
config
*
rest
.
Config
,
clusterInformer
clusterinformer
.
ClusterInformer
,
clusterInformer
clusterinformer
.
ClusterInformer
,
clusterClient
clusterclient
.
ClusterInterface
,
clusterClient
clusterclient
.
ClusterInterface
,
openpitrixClient
openpitrix
.
Client
,
)
*
clusterController
{
)
*
clusterController
{
broadcaster
:=
record
.
NewBroadcaster
()
broadcaster
:=
record
.
NewBroadcaster
()
...
@@ -127,6 +132,7 @@ func NewClusterController(
...
@@ -127,6 +132,7 @@ func NewClusterController(
client
:
client
,
client
:
client
,
hostConfig
:
config
,
hostConfig
:
config
,
clusterClient
:
clusterClient
,
clusterClient
:
clusterClient
,
openpitrixClient
:
openpitrixClient
,
queue
:
workqueue
.
NewNamedRateLimitingQueue
(
workqueue
.
DefaultControllerRateLimiter
(),
"cluster"
),
queue
:
workqueue
.
NewNamedRateLimitingQueue
(
workqueue
.
DefaultControllerRateLimiter
(),
"cluster"
),
workerLoopPeriod
:
time
.
Second
,
workerLoopPeriod
:
time
.
Second
,
clusterMap
:
make
(
map
[
string
]
*
clusterData
),
clusterMap
:
make
(
map
[
string
]
*
clusterData
),
...
@@ -316,6 +322,18 @@ func (c *clusterController) syncCluster(key string) error {
...
@@ -316,6 +322,18 @@ func (c *clusterController) syncCluster(key string) error {
}
}
}
}
// clean up openpitrix runtime of the cluster
if
_
,
ok
:=
cluster
.
Annotations
[
openpitrixRuntime
];
ok
{
if
c
.
openpitrixClient
!=
nil
{
err
=
c
.
openpitrixClient
.
CleanupRuntime
(
cluster
.
Name
)
if
err
!=
nil
{
klog
.
Errorf
(
"Unable to delete openpitrix for cluster %s, error %v"
,
cluster
.
Name
,
err
)
return
err
}
}
delete
(
cluster
.
Annotations
,
openpitrixRuntime
)
}
// remove our cluster finalizer
// remove our cluster finalizer
finalizers
:=
sets
.
NewString
(
cluster
.
ObjectMeta
.
Finalizers
...
)
finalizers
:=
sets
.
NewString
(
cluster
.
ObjectMeta
.
Finalizers
...
)
finalizers
.
Delete
(
clusterv1alpha1
.
Finalizer
)
finalizers
.
Delete
(
clusterv1alpha1
.
Finalizer
)
...
@@ -532,6 +550,22 @@ func (c *clusterController) syncCluster(key string) error {
...
@@ -532,6 +550,22 @@ func (c *clusterController) syncCluster(key string) error {
c
.
updateClusterCondition
(
cluster
,
clusterNotReadyCondition
)
c
.
updateClusterCondition
(
cluster
,
clusterNotReadyCondition
)
}
}
if
c
.
openpitrixClient
!=
nil
{
// OpenPitrix is enabled, create runtime
if
cluster
.
GetAnnotations
()
==
nil
{
cluster
.
Annotations
=
make
(
map
[
string
]
string
)
}
if
_
,
ok
=
cluster
.
Annotations
[
openpitrixRuntime
];
!
ok
{
err
=
c
.
openpitrixClient
.
UpsertRuntime
(
cluster
.
Name
,
string
(
cluster
.
Spec
.
Connection
.
KubeConfig
))
if
err
!=
nil
{
klog
.
Errorf
(
"Failed to create runtime for cluster %s, error %v"
,
cluster
.
Name
,
err
)
return
err
}
else
{
cluster
.
Annotations
[
openpitrixRuntime
]
=
cluster
.
Name
}
}
}
if
!
reflect
.
DeepEqual
(
oldCluster
,
cluster
)
{
if
!
reflect
.
DeepEqual
(
oldCluster
,
cluster
)
{
_
,
err
=
c
.
clusterClient
.
Update
(
cluster
)
_
,
err
=
c
.
clusterClient
.
Update
(
cluster
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
test/testdata/certs/tls.crt
0 → 100644
浏览文件 @
5d954202
-----BEGIN CERTIFICATE-----
MIICyDCCAbCgAwIBAgIBADANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwprdWJl
c3BoZXJlMB4XDTIwMDMyNTEwMTcxNloXDTMwMDMyMzEwMTcxNlowFTETMBEGA1UE
AxMKa3ViZXNwaGVyZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM5t
5FTkBKKAhxbuL4V5ltOLGAfJVhCp+FOQPKRjRjtsle+TkhdnBx87VVMKDVTyQUxX
ZVq4/S89XomwLhiwUmV9KN9Dv+fsFlD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kQUFPWV7INAlbYs3n98oDbKyjLly
anw10qkCgYEAijYeIU+njMLLcWiIHlDfrNA3Se7oGflbclIcT/JjyUwFOkE5YnQO
n+PdfG4tGg5XHp+bts/2zV6t5noPKVq1uid+nlR+NHGRign+UjwSGblEshShF8Yl
LbOiLqBMi6XP23glm/jXHSezjG/1uvkW7+92jmNlh6Knax7+YJcxqJ8=
-----END RSA PRIVATE KEY-----
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录