func NewWebhookController(gracePeriodRatio float32, minGracePeriod time.Duration,
core corev1.CoreV1Interface, admission admissionv1beta1.AdmissionregistrationV1beta1Interface,
certClient certclient.CertificatesV1beta1Interface, k8sCaCertFile string,
secretNames, dnsNames, serviceNamespaces []string) (*WebhookController, error) {
...
c := &WebhookController{
gracePeriodRatio: gracePeriodRatio,
minGracePeriod: minGracePeriod,
k8sCaCertFile: k8sCaCertFile,
core: core,
admission: admission,
certClient: certClient,
secretNames: secretNames,
dnsNames: dnsNames,
serviceNamespaces: serviceNamespaces,
certUtil: certutil.NewCertUtil(int(gracePeriodRatio * 100)),
}
// 读取CA.
_, err := reloadCACert(c)
if err != nil {
return nil, err
}
if len(dnsNames) == 0 {
log.Warn("the input services are empty, no services to manage certificates for")
} else {
// watch istio.io/dns-key-and-cert类型的secret
istioSecretSelector := fields.SelectorFromSet(map[string]string{"type": IstioDNSSecretType}).String()
scrtLW := listwatch.MultiNamespaceListerWatcher(serviceNamespaces, func(namespace string) cache.ListerWatcher {
return &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = istioSecretSelector
return core.Secrets(namespace).List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = istioSecretSelector
return core.Secrets(namespace).Watch(context.TODO(), options)
},
}
})
c.scrtStore, c.scrtController =
cache.NewInformer(scrtLW, &v1.Secret{}, secretResyncPeriod, cache.ResourceEventHandlerFuncs{
DeleteFunc: c.scrtDeleted,
UpdateFunc: c.scrtUpdated,
})
}
return c, nil
}