in pkg/k8scontext/context.go [58:168]
func NewContext(kubeClient kubernetes.Interface, crdClient versioned.Interface, multiClusterCrdClient multicluster_versioned.Interface, istioCrdClient istio_versioned.Interface, namespaces []string, resyncPeriod time.Duration, metricStore metricstore.MetricStore, envVariables environment.EnvVariables) *Context {
informerFactory := informers.NewSharedInformerFactory(kubeClient, resyncPeriod)
crdInformerFactory := externalversions.NewSharedInformerFactory(crdClient, resyncPeriod)
multiClusterCrdInformerFactory := multicluster_externalversions.NewSharedInformerFactory(multiClusterCrdClient, resyncPeriod)
istioCrdInformerFactory := istio_externalversions.NewSharedInformerFactoryWithOptions(istioCrdClient, resyncPeriod)
informerCollection := InformerCollection{
Endpoints: informerFactory.Core().V1().Endpoints().Informer(),
Pods: informerFactory.Core().V1().Pods().Informer(),
Secret: informerFactory.Core().V1().Secrets().Informer(),
Service: informerFactory.Core().V1().Services().Informer(),
AzureIngressProhibitedTarget: crdInformerFactory.Azureingressprohibitedtargets().V1().AzureIngressProhibitedTargets().Informer(),
AzureApplicationGatewayBackendPool: crdInformerFactory.Azureapplicationgatewaybackendpools().V1beta1().AzureApplicationGatewayBackendPools().Informer(),
AzureApplicationGatewayRewrite: crdInformerFactory.Azureapplicationgatewayrewrites().V1beta1().AzureApplicationGatewayRewrites().Informer(),
AzureApplicationGatewayInstanceUpdateStatus: crdInformerFactory.Azureapplicationgatewayinstanceupdatestatus().V1beta1().AzureApplicationGatewayInstanceUpdateStatuses().Informer(),
MultiClusterService: multiClusterCrdInformerFactory.Multiclusterservices().V1alpha1().MultiClusterServices().Informer(),
MultiClusterIngress: multiClusterCrdInformerFactory.Multiclusteringresses().V1alpha1().MultiClusterIngresses().Informer(),
IstioGateway: istioCrdInformerFactory.Networking().V1alpha3().Gateways().Informer(),
IstioVirtualService: istioCrdInformerFactory.Networking().V1alpha3().VirtualServices().Informer(),
}
if IsNetworkingV1PackageSupported {
informerCollection.Ingress = informerFactory.Networking().V1().Ingresses().Informer()
} else {
informerCollection.Ingress = informerFactory.Extensions().V1beta1().Ingresses().Informer()
}
cacheCollection := CacheCollection{
Endpoints: informerCollection.Endpoints.GetStore(),
Ingress: informerCollection.Ingress.GetStore(),
Pods: informerCollection.Pods.GetStore(),
Secret: informerCollection.Secret.GetStore(),
Service: informerCollection.Service.GetStore(),
AzureIngressProhibitedTarget: informerCollection.AzureIngressProhibitedTarget.GetStore(),
AzureApplicationGatewayBackendPool: informerCollection.AzureApplicationGatewayBackendPool.GetStore(),
AzureApplicationGatewayRewrite: informerCollection.AzureApplicationGatewayRewrite.GetStore(),
AzureApplicationGatewayInstanceUpdateStatus: informerCollection.AzureApplicationGatewayInstanceUpdateStatus.GetStore(),
MultiClusterService: informerCollection.MultiClusterService.GetStore(),
MultiClusterIngress: informerCollection.MultiClusterIngress.GetStore(),
IstioGateway: informerCollection.IstioGateway.GetStore(),
IstioVirtualService: informerCollection.IstioVirtualService.GetStore(),
}
context := &Context{
kubeClient: kubeClient,
crdClient: crdClient,
multiClusterCrdClient: multiClusterCrdClient,
istioCrdClient: istioCrdClient,
informers: &informerCollection,
ingressSecretsMap: utils.NewThreadsafeMultimap(),
Caches: &cacheCollection,
CertificateSecretStore: NewSecretStore(kubeClient),
Work: make(chan events.Event, workBuffer),
CacheSynced: make(chan interface{}),
MetricStore: metricStore,
namespaces: make(map[string]interface{}),
ingressClassControllerName: envVariables.IngressClassControllerName,
ingressClassResourceName: envVariables.IngressClassResourceName,
ingressClassResourceEnabled: envVariables.IngressClassResourceEnabled,
ingressClassResourceDefault: envVariables.IngressClassResourceDefault,
}
for _, ns := range namespaces {
context.namespaces[ns] = nil
}
h := handlers{context}
resourceHandler := cache.ResourceEventHandlerFuncs{
AddFunc: h.addFunc,
UpdateFunc: h.updateFunc,
DeleteFunc: h.deleteFunc,
}
ingressResourceHandler := cache.ResourceEventHandlerFuncs{
AddFunc: h.ingressAdd,
UpdateFunc: h.ingressUpdate,
DeleteFunc: h.ingressDelete,
}
secretResourceHandler := cache.ResourceEventHandlerFuncs{
AddFunc: h.secretAdd,
UpdateFunc: h.secretUpdate,
DeleteFunc: h.secretDelete,
}
// Register event handlers.
informerCollection.Endpoints.AddEventHandler(resourceHandler)
informerCollection.Ingress.AddEventHandler(ingressResourceHandler)
informerCollection.Pods.AddEventHandler(resourceHandler)
informerCollection.Secret.AddEventHandler(secretResourceHandler)
informerCollection.Service.AddEventHandler(resourceHandler)
informerCollection.AzureIngressProhibitedTarget.AddEventHandler(resourceHandler)
informerCollection.AzureApplicationGatewayRewrite.AddEventHandler(resourceHandler)
informerCollection.AzureApplicationGatewayBackendPool.AddEventHandler(resourceHandler)
informerCollection.AzureApplicationGatewayInstanceUpdateStatus.AddEventHandler(resourceHandler)
informerCollection.MultiClusterService.AddEventHandler(resourceHandler)
informerCollection.MultiClusterIngress.AddEventHandler(resourceHandler)
if IsNetworkingV1PackageSupported {
informerCollection.IngressClass = informerFactory.Networking().V1().IngressClasses().Informer()
informerCollection.IngressClass.AddEventHandler(resourceHandler)
cacheCollection.IngressClass = informerCollection.IngressClass.GetStore()
}
return context
}