webhook 配置校验
initConfigValidation
func (s *Server) initConfigValidation(args *PilotArgs) error {
...
log.Info("initializing config validator")
// always start the validation server
params := server.Options{
Schemas: collections.Istio,
DomainSuffix: args.RegistryOptions.KubeOptions.DomainSuffix,
Mux: s.httpsMux,
}
// 根据参数初始化Server
whServer, err := server.New(params)
if err != nil {
return err
}
s.addStartFunc(func(stop <-chan struct{}) error {
whServer.Run(stop)
return nil
})
// 是否校验webhook
if webhookConfigName := validationWebhookConfigName.Get(); webhookConfigName != "" && s.kubeClient != nil {
if webhookConfigName == validationWebhookConfigNameTemplate {
webhookConfigName = strings.ReplaceAll(validationWebhookConfigNameTemplate, validationWebhookConfigNameTemplateVar, args.Namespace)
}
caBundlePath := s.caBundlePath
if hasCustomTLSCerts(args.ServerOptions.TLSOptions) {
caBundlePath = args.ServerOptions.TLSOptions.CaCertFile
}
o := controller.Options{
WatchedNamespace: args.Namespace,
CAPath: caBundlePath,
WebhookConfigName: webhookConfigName,
ServiceName: "istiod",
}
// 初始化webhook controller
whController, err := controller.New(o, s.kubeClient)
if err != nil {
log.Errorf("failed to start validation controller: %v", err)
return err
}
s.addTerminatingStartFunc(func(stop <-chan struct{}) error {
le := leaderelection.NewLeaderElection(args.Namespace, args.PodName, leaderelection.ValidationController, s.kubeClient)
le.AddRunFunction(func(leaderStop <-chan struct{}) {
log.Infof("Starting validation controller")
// 启动controller
whController.Start(leaderStop)
})
le.Run(stop)
return nil
})
}
return nil
}校验规则
如果启用了webhook配置校验则将通过
检查mutatingwebhookc 配置是否有效填充CABundle和FailurePolicy
Last updated
Was this helpful?