Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for MCI controller to enqueue ingresses #234

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func main() {
}

if flags.F.MultiCluster {
mciController, _ := mci.NewController(ctx, flags.F.ResyncPeriod)
mciController, _ := mci.NewController(ctx, flags.F.ResyncPeriod, lbc)
go mciController.Run(stopCh)
glog.V(0).Infof("Multi-Cluster Ingress Controller started")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type ControllerContext struct {
type MultiClusterContext struct {
RegistryClient crclient.Interface
ClusterInformer cache.SharedIndexInformer
MCIEnabled bool
}

// NewControllerContext returns a new shared set of informers.
Expand All @@ -76,6 +77,7 @@ func NewControllerContext(kubeClient kubernetes.Interface, registryClient crclie
}
if context.MC.RegistryClient != nil {
context.MC.ClusterInformer = crinformerv1alpha1.NewClusterInformer(registryClient, resyncPeriod, newIndexer())
context.MC.MCIEnabled = true
}

return context
Expand Down
18 changes: 18 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ func NewLoadBalancerController(ctx *context.ControllerContext, clusterManager *C
return &lbc, nil
}

// Implements MCIEnqueue
func (lbc *LoadBalancerController) EnqueueAllIngresses() error {
ings, err := lbc.ingLister.ListGCEIngresses()
if err != nil {
return err
}
for _, ing := range ings.Items {
lbc.ingQueue.Enqueue(&ing)
}
return nil
}

// enqueueIngressForService enqueues all the Ingress' for a Service.
func (lbc *LoadBalancerController) enqueueIngressForService(obj interface{}) {
svc := obj.(*apiv1.Service)
Expand Down Expand Up @@ -242,6 +254,12 @@ func (lbc *LoadBalancerController) sync(key string) (retErr error) {
}
glog.V(3).Infof("Syncing %v", key)

if lbc.ctx.MC.MCIEnabled {
// This is a temporary short-circuit to just verify that
// the MCI controller properly queues ingresses.
return nil
}

gceIngresses, err := lbc.ingLister.ListGCEIngresses()
if err != nil {
return err
Expand Down
16 changes: 14 additions & 2 deletions pkg/mci/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ type Controller struct {

clusterSynced cache.InformerSynced
clusterLister cache.Indexer
}

// TODO(rramkumar): Add lister for service extension CRD.
// MCIEnqueue is a interface to allow the MCI controller to enqueue ingresses
// based on events it receives.
type MCIEnqueue interface {
EnqueueAllIngresses() error
}

func NewController(ctx *context.ControllerContext, resyncPeriod time.Duration) (*Controller, error) {
func NewController(ctx *context.ControllerContext, resyncPeriod time.Duration, enqueue MCIEnqueue) (*Controller, error) {
mciController := &Controller{
resyncPeriod: resyncPeriod,
clusterSynced: ctx.MC.ClusterInformer.HasSynced,
Expand All @@ -49,10 +53,18 @@ func NewController(ctx *context.ControllerContext, resyncPeriod time.Duration) (
AddFunc: func(obj interface{}) {
c := obj.(*crv1alpha1.Cluster)
glog.V(3).Infof("Cluster %v added", c.Name)
err := enqueue.EnqueueAllIngresses()
if err != nil {
glog.V(3).Infof("Error enqueuing ingress on cluster add: %v", err)
}
},
DeleteFunc: func(obj interface{}) {
c := obj.(*crv1alpha1.Cluster)
glog.V(3).Infof("Cluster %v deleted", c.Name)
err := enqueue.EnqueueAllIngresses()
if err != nil {
glog.V(3).Infof("Error enqueuing ingress on cluster delete: %v", err)
}
},
UpdateFunc: func(obj, cur interface{}) {
c := obj.(*crv1alpha1.Cluster)
Expand Down