Skip to content

Commit

Permalink
Merge pull request #529 from rramkumar1/master
Browse files Browse the repository at this point in the history
Managed Certs integration: Fix code so that informers are not instantiated if managed certs is not enabled
  • Loading branch information
k8s-ci-robot committed Oct 30, 2018
2 parents fdfb8b8 + 7001e2b commit 9200ebc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func main() {
ctxConfig := ingctx.ControllerContextConfig{
NEGEnabled: enableNEG,
BackendConfigEnabled: flags.F.EnableBackendConfig,
ManagedCertificateEnabled: flags.F.Features.ManagedCertificates,
Namespace: flags.F.WatchNamespace,
ResyncPeriod: flags.F.ResyncPeriod,
DefaultBackendSvcPortID: defaultBackendServicePortID,
Expand Down
41 changes: 24 additions & 17 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ type ControllerContext struct {

// ControllerContextConfig encapsulates some settings that are tunable via command line flags.
type ControllerContextConfig struct {
NEGEnabled bool
BackendConfigEnabled bool
Namespace string
ResyncPeriod time.Duration
NEGEnabled bool
BackendConfigEnabled bool
ManagedCertificateEnabled bool
Namespace string
ResyncPeriod time.Duration
// DefaultBackendSvcPortID is the ServicePortID for the system default backend.
DefaultBackendSvcPortID utils.ServicePortID
HealthCheckPath string
Expand All @@ -91,24 +92,26 @@ func NewControllerContext(
config ControllerContextConfig) *ControllerContext {

context := &ControllerContext{
KubeClient: kubeClient,
Cloud: cloud,
ClusterNamer: namer,
ControllerContextConfig: config,
IngressInformer: informerv1beta1.NewIngressInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
ServiceInformer: informerv1.NewServiceInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
PodInformer: informerv1.NewPodInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
NodeInformer: informerv1.NewNodeInformer(kubeClient, config.ResyncPeriod, utils.NewNamespaceIndexer()),
ManagedCertificateInformer: managedcertificatesv1alpha1.NewManagedCertificateInformer(mcrtClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
recorders: map[string]record.EventRecorder{},
healthChecks: make(map[string]func() error),
KubeClient: kubeClient,
Cloud: cloud,
ClusterNamer: namer,
ControllerContextConfig: config,
IngressInformer: informerv1beta1.NewIngressInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
ServiceInformer: informerv1.NewServiceInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
PodInformer: informerv1.NewPodInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
NodeInformer: informerv1.NewNodeInformer(kubeClient, config.ResyncPeriod, utils.NewNamespaceIndexer()),
recorders: map[string]record.EventRecorder{},
healthChecks: make(map[string]func() error),
}
if config.NEGEnabled {
context.EndpointInformer = informerv1.NewEndpointsInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer())
}
if config.BackendConfigEnabled {
context.BackendConfigInformer = informerbackendconfig.NewBackendConfigInformer(backendConfigClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer())
}
if config.ManagedCertificateEnabled {
context.ManagedCertificateInformer = managedcertificatesv1alpha1.NewManagedCertificateInformer(mcrtClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer())
}

return context
}
Expand All @@ -120,14 +123,16 @@ func (ctx *ControllerContext) HasSynced() bool {
ctx.ServiceInformer.HasSynced,
ctx.PodInformer.HasSynced,
ctx.NodeInformer.HasSynced,
ctx.ManagedCertificateInformer.HasSynced,
}
if ctx.EndpointInformer != nil {
funcs = append(funcs, ctx.EndpointInformer.HasSynced)
}
if ctx.BackendConfigInformer != nil {
funcs = append(funcs, ctx.BackendConfigInformer.HasSynced)
}
if ctx.ManagedCertificateInformer != nil {
funcs = append(funcs, ctx.ManagedCertificateInformer.HasSynced)
}
for _, f := range funcs {
if !f() {
return false
Expand Down Expand Up @@ -183,13 +188,15 @@ func (ctx *ControllerContext) Start(stopCh chan struct{}) {
go ctx.ServiceInformer.Run(stopCh)
go ctx.PodInformer.Run(stopCh)
go ctx.NodeInformer.Run(stopCh)
go ctx.ManagedCertificateInformer.Run(stopCh)
if ctx.EndpointInformer != nil {
go ctx.EndpointInformer.Run(stopCh)
}
if ctx.BackendConfigInformer != nil {
go ctx.BackendConfigInformer.Run(stopCh)
}
if ctx.ManagedCertificateInformer != nil {
go ctx.ManagedCertificateInformer.Run(stopCh)
}
}

// IngressesForService gets all the Ingresses that reference a Service.
Expand Down
8 changes: 7 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ func NewLoadBalancerController(
broadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{
Interface: ctx.KubeClient.Core().Events(""),
})

healthChecker := healthchecks.NewHealthChecker(ctx.Cloud, ctx.HealthCheckPath, ctx.DefaultBackendHealthCheckPath, ctx.ClusterNamer, ctx.DefaultBackendSvcPortID.Service)
instancePool := instances.NewNodePool(ctx.Cloud, ctx.ClusterNamer)
backendPool := backends.NewPool(ctx.Cloud, ctx.ClusterNamer, true)
mcrtLister := mcrtv1alpha1.NewManagedCertificateLister(ctx.ManagedCertificateInformer.GetIndexer())

var mcrtLister mcrtv1alpha1.ManagedCertificateLister
if ctx.ManagedCertificateEnabled {
mcrtLister = mcrtv1alpha1.NewManagedCertificateLister(ctx.ManagedCertificateInformer.GetIndexer())
}

lbc := LoadBalancerController{
ctx: ctx,
ingLister: utils.StoreToIngressLister{Store: ctx.IngressInformer.GetStore()},
Expand Down

0 comments on commit 9200ebc

Please sign in to comment.