Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
21a5f830
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看板
未验证
提交
21a5f830
编写于
8月 10, 2020
作者:
Z
zryfish
提交者:
GitHub
8月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix unable to setup webhook server under leader election (#2830)
Signed-off-by:
N
Jeff
<
zw0948@gmail.com
>
上级
48e77cbb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
74 addition
and
117 deletion
+74
-117
cmd/controller-manager/app/server.go
cmd/controller-manager/app/server.go
+73
-116
pkg/controller/storage/capability/capability_controller.go
pkg/controller/storage/capability/capability_controller.go
+1
-1
未找到文件。
cmd/controller-manager/app/server.go
浏览文件 @
21a5f830
...
...
@@ -17,22 +17,15 @@ limitations under the License.
package
app
import
(
"context"
"fmt"
"github.com/spf13/cobra"
"k8s.io/api/core/v1"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/client-go/tools/record"
cliflag
"k8s.io/component-base/cli/flag"
"k8s.io/klog"
"k8s.io/klog/klogr"
"kubesphere.io/kubesphere/cmd/controller-manager/app/options"
"kubesphere.io/kubesphere/pkg/apis"
controllerconfig
"kubesphere.io/kubesphere/pkg/apiserver/config"
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme"
"kubesphere.io/kubesphere/pkg/controller/namespace"
"kubesphere.io/kubesphere/pkg/controller/network/nsnetworkpolicy"
"kubesphere.io/kubesphere/pkg/controller/user"
...
...
@@ -46,11 +39,10 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"kubesphere.io/kubesphere/pkg/utils/term"
"os"
application
"sigs.k8s.io/application/controllers"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
"sigs.k8s.io/controller-runtime/pkg/webhook"
application
"sigs.k8s.io/application/controllers"
)
func
NewControllerManagerCommand
()
*
cobra
.
Command
{
...
...
@@ -72,6 +64,8 @@ func NewControllerManagerCommand() *cobra.Command {
LeaderElect
:
s
.
LeaderElect
,
WebhookCertDir
:
s
.
WebhookCertDir
,
}
}
else
{
klog
.
Fatal
(
"Failed to load configuration from disk"
,
err
)
}
cmd
:=
&
cobra
.
Command
{
...
...
@@ -83,7 +77,7 @@ func NewControllerManagerCommand() *cobra.Command {
os
.
Exit
(
1
)
}
if
err
=
R
un
(
s
,
signals
.
SetupSignalHandler
());
err
!=
nil
{
if
err
=
r
un
(
s
,
signals
.
SetupSignalHandler
());
err
!=
nil
{
klog
.
Error
(
err
)
os
.
Exit
(
1
)
}
...
...
@@ -101,13 +95,13 @@ func NewControllerManagerCommand() *cobra.Command {
usageFmt
:=
"Usage:
\n
%s
\n
"
cols
,
_
,
_
:=
term
.
TerminalSize
(
cmd
.
OutOrStdout
())
cmd
.
SetHelpFunc
(
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
fmt
.
Fprintf
(
cmd
.
OutOrStdout
(),
"%s
\n\n
"
+
usageFmt
,
cmd
.
Long
,
cmd
.
UseLine
())
_
,
_
=
fmt
.
Fprintf
(
cmd
.
OutOrStdout
(),
"%s
\n\n
"
+
usageFmt
,
cmd
.
Long
,
cmd
.
UseLine
())
cliflag
.
PrintSections
(
cmd
.
OutOrStdout
(),
namedFlagSets
,
cols
)
})
return
cmd
}
func
R
un
(
s
*
options
.
KubeSphereControllerManagerOptions
,
stopCh
<-
chan
struct
{})
error
{
func
r
un
(
s
*
options
.
KubeSphereControllerManagerOptions
,
stopCh
<-
chan
struct
{})
error
{
kubernetesClient
,
err
:=
k8s
.
NewKubernetesClient
(
s
.
KubernetesOptions
)
if
err
!=
nil
{
klog
.
Errorf
(
"Failed to create kubernetes clientset %v"
,
err
)
...
...
@@ -160,126 +154,89 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
kubernetesClient
.
Snapshot
(),
kubernetesClient
.
ApiExtensions
())
run
:=
func
(
ctx
context
.
Context
)
{
klog
.
V
(
0
)
.
Info
(
"setting up manager"
)
// Use 8443 instead of 443 cause we need root permission to bind port 443
mgr
,
err
:=
manager
.
New
(
kubernetesClient
.
Config
(),
manager
.
Options
{
CertDir
:
s
.
WebhookCertDir
,
Port
:
8443
})
if
err
!=
nil
{
klog
.
Fatalf
(
"unable to set up overall controller manager: %v"
,
err
)
}
klog
.
V
(
0
)
.
Info
(
"setting up scheme"
)
if
err
:=
apis
.
AddToScheme
(
mgr
.
GetScheme
());
err
!=
nil
{
klog
.
Fatalf
(
"unable add APIs to scheme: %v"
,
err
)
}
klog
.
V
(
0
)
.
Info
(
"Setting up controllers"
)
err
=
workspace
.
Add
(
mgr
)
if
err
!=
nil
{
klog
.
Fatal
(
"Unable to create workspace controller"
)
}
err
=
namespace
.
Add
(
mgr
)
if
err
!=
nil
{
klog
.
Fatal
(
"Unable to create namespace controller"
)
}
err
=
(
&
application
.
ApplicationReconciler
{
Scheme
:
mgr
.
GetScheme
(),
Client
:
mgr
.
GetClient
(),
Mapper
:
mgr
.
GetRESTMapper
(),
Log
:
klogr
.
New
(),
})
.
SetupWithManager
(
mgr
)
if
err
!=
nil
{
klog
.
Fatal
(
"Unable to create application controller"
)
}
mgrOptions
:=
manager
.
Options
{
CertDir
:
s
.
WebhookCertDir
,
Port
:
8443
,
}
// TODO(jeff): refactor config with CRD
servicemeshEnabled
:=
s
.
ServiceMeshOptions
!=
nil
&&
len
(
s
.
ServiceMeshOptions
.
IstioPilotHost
)
!=
0
if
err
=
addControllers
(
mgr
,
kubernetesClient
,
informerFactory
,
devopsClient
,
s3Client
,
ldapClient
,
s
.
AuthenticationOptions
,
openpitrixClient
,
s
.
MultiClusterOptions
.
Enable
,
s
.
NetworkOptions
,
servicemeshEnabled
,
s
.
AuthenticationOptions
.
KubectlImage
,
stopCh
);
err
!=
nil
{
klog
.
Fatalf
(
"unable to register controllers to the manager: %v"
,
err
)
if
s
.
LeaderElect
{
mgrOptions
=
manager
.
Options
{
CertDir
:
s
.
WebhookCertDir
,
Port
:
8443
,
LeaderElection
:
s
.
LeaderElect
,
LeaderElectionNamespace
:
"kubesphere-system"
,
LeaderElectionID
:
"ks-controller-manager-leader-election"
,
LeaseDuration
:
&
s
.
LeaderElection
.
LeaseDuration
,
RetryPeriod
:
&
s
.
LeaderElection
.
RetryPeriod
,
RenewDeadline
:
&
s
.
LeaderElection
.
RenewDeadline
,
}
}
// Start cache data after all informer is registered
informerFactory
.
Start
(
stopCh
)
// Setup webhooks
klog
.
Info
(
"setting up webhook server"
)
hookServer
:=
mgr
.
GetWebhookServer
()
klog
.
Info
(
"registering webhooks to the webhook server"
)
hookServer
.
Register
(
"/validate-email-iam-kubesphere-io-v1alpha2-user"
,
&
webhook
.
Admission
{
Handler
:
&
user
.
EmailValidator
{
Client
:
mgr
.
GetClient
()}})
hookServer
.
Register
(
"/validate-nsnp-kubesphere-io-v1alpha1-network"
,
&
webhook
.
Admission
{
Handler
:
&
nsnetworkpolicy
.
NSNPValidator
{
Client
:
mgr
.
GetClient
()}})
klog
.
V
(
0
)
.
Info
(
"Starting the controllers."
)
if
err
=
mgr
.
Start
(
stopCh
);
err
!=
nil
{
klog
.
Fatalf
(
"unable to run the manager: %v"
,
err
)
}
klog
.
V
(
0
)
.
Info
(
"setting up manager"
)
select
{}
// Use 8443 instead of 443 cause we need root permission to bind port 443
mgr
,
err
:=
manager
.
New
(
kubernetesClient
.
Config
(),
mgrOptions
)
if
err
!=
nil
{
klog
.
Fatalf
(
"unable to set up overall controller manager: %v"
,
err
)
}
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
if
err
=
apis
.
AddToScheme
(
mgr
.
GetScheme
());
err
!=
nil
{
klog
.
Fatalf
(
"unable add APIs to scheme: %v"
,
err
)
}
go
func
()
{
<-
stopCh
cancel
(
)
}
()
err
=
workspace
.
Add
(
mgr
)
if
err
!=
nil
{
klog
.
Fatal
(
"Unable to create workspace controller"
)
}
if
!
s
.
LeaderElect
{
run
(
ctx
)
return
nil
err
=
namespace
.
Add
(
mgr
)
if
err
!=
nil
{
klog
.
Fatal
(
"Unable to create namespace controller"
)
}
id
,
err
:=
os
.
Hostname
()
err
=
(
&
application
.
ApplicationReconciler
{
Scheme
:
mgr
.
GetScheme
(),
Client
:
mgr
.
GetClient
(),
Mapper
:
mgr
.
GetRESTMapper
(),
Log
:
klogr
.
New
(),
})
.
SetupWithManager
(
mgr
)
if
err
!=
nil
{
return
err
klog
.
Fatal
(
"Unable to create application controller"
)
}
// add a uniquifier so that two processes on the same host don't accidentally both become active
id
=
id
+
"_"
+
string
(
uuid
.
NewUUID
())
// TODO(jeff): refactor config with CRD
servicemeshEnabled
:=
s
.
ServiceMeshOptions
!=
nil
&&
len
(
s
.
ServiceMeshOptions
.
IstioPilotHost
)
!=
0
if
err
=
addControllers
(
mgr
,
kubernetesClient
,
informerFactory
,
devopsClient
,
s3Client
,
ldapClient
,
s
.
AuthenticationOptions
,
openpitrixClient
,
s
.
MultiClusterOptions
.
Enable
,
s
.
NetworkOptions
,
servicemeshEnabled
,
s
.
AuthenticationOptions
.
KubectlImage
,
stopCh
);
err
!=
nil
{
klog
.
Fatalf
(
"unable to register controllers to the manager: %v"
,
err
)
}
lock
,
err
:=
resourcelock
.
New
(
resourcelock
.
LeasesResourceLock
,
"kubesphere-system"
,
"ks-controller-manager"
,
kubernetesClient
.
Kubernetes
()
.
CoreV1
(),
kubernetesClient
.
Kubernetes
()
.
CoordinationV1
(),
resourcelock
.
ResourceLockConfig
{
Identity
:
id
,
EventRecorder
:
record
.
NewBroadcaster
()
.
NewRecorder
(
scheme
.
Scheme
,
v1
.
EventSource
{
Component
:
"ks-controller-manager"
,
}),
})
// Start cache data after all informer is registered
klog
.
V
(
0
)
.
Info
(
"Starting cache resource from apiserver..."
)
informerFactory
.
Start
(
stopCh
)
if
err
!=
nil
{
klog
.
Fatalf
(
"error creating lock: %v"
,
err
)
}
// Setup webhooks
klog
.
V
(
2
)
.
Info
(
"setting up webhook server"
)
hookServer
:=
mgr
.
GetWebhookServer
()
leaderelection
.
RunOrDie
(
ctx
,
leaderelection
.
LeaderElectionConfig
{
Lock
:
lock
,
LeaseDuration
:
s
.
LeaderElection
.
LeaseDuration
,
RenewDeadline
:
s
.
LeaderElection
.
RenewDeadline
,
RetryPeriod
:
s
.
LeaderElection
.
RetryPeriod
,
Callbacks
:
leaderelection
.
LeaderCallbacks
{
OnStartedLeading
:
run
,
OnStoppedLeading
:
func
()
{
klog
.
Errorf
(
"leadership lost"
)
os
.
Exit
(
0
)
},
},
})
klog
.
V
(
2
)
.
Info
(
"registering webhooks to the webhook server"
)
hookServer
.
Register
(
"/validate-email-iam-kubesphere-io-v1alpha2-user"
,
&
webhook
.
Admission
{
Handler
:
&
user
.
EmailValidator
{
Client
:
mgr
.
GetClient
()}})
hookServer
.
Register
(
"/validate-nsnp-kubesphere-io-v1alpha1-network"
,
&
webhook
.
Admission
{
Handler
:
&
nsnetworkpolicy
.
NSNPValidator
{
Client
:
mgr
.
GetClient
()}})
klog
.
V
(
0
)
.
Info
(
"Starting the controllers."
)
if
err
=
mgr
.
Start
(
stopCh
);
err
!=
nil
{
klog
.
Fatalf
(
"unable to run the manager: %v"
,
err
)
}
return
nil
}
pkg/controller/storage/capability/capability_controller.go
浏览文件 @
21a5f830
...
...
@@ -191,7 +191,7 @@ func (c *StorageCapabilityController) handlerCSIDriver(obj interface{}) {
}
for
_
,
storageClass
:=
range
storageClasses
{
if
storageClass
.
Provisioner
==
csiDriver
.
Name
{
klog
.
Info
(
"enqueue StorageClass when handler csiDriver"
,
storageClass
)
klog
.
V
(
4
)
.
Infof
(
"enqueue StorageClass %s when handling csiDriver"
,
storageClass
.
Name
)
c
.
enqueueStorageClass
(
storageClass
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录