Skip to content

Commit

Permalink
Add negClient to ControllerContext
Browse files Browse the repository at this point in the history
  • Loading branch information
swetharepakula committed Jul 16, 2020
1 parent aa9b167 commit 32b9c29
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func main() {
ASMConfigMapNamespace: flags.F.ASMConfigMapBasedConfigNamespace,
ASMConfigMapName: flags.F.ASMConfigMapBasedConfigCMName,
}
ctx := ingctx.NewControllerContext(kubeConfig, kubeClient, backendConfigClient, frontendConfigClient, cloud, namer, kubeSystemUID, ctxConfig)
ctx := ingctx.NewControllerContext(kubeConfig, kubeClient, backendConfigClient, frontendConfigClient, nil, cloud, namer, kubeSystemUID, ctxConfig)
go app.RunHTTPServer(ctx.HealthCheck)

if !flags.F.LeaderElection.LeaderElect {
Expand Down
17 changes: 17 additions & 0 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
frontendconfigclient "k8s.io/ingress-gce/pkg/frontendconfig/client/clientset/versioned"
informerfrontendconfig "k8s.io/ingress-gce/pkg/frontendconfig/client/informers/externalversions/frontendconfig/v1beta1"
"k8s.io/ingress-gce/pkg/metrics"
svcnegclient "k8s.io/ingress-gce/pkg/svcneg/client/clientset/versioned"
informersvcneg "k8s.io/ingress-gce/pkg/svcneg/client/informers/externalversions/svcneg/v1beta1"
"k8s.io/ingress-gce/pkg/utils"
"k8s.io/ingress-gce/pkg/utils/namer"
"k8s.io/klog"
Expand All @@ -57,6 +59,7 @@ const (
type ControllerContext struct {
KubeConfig *rest.Config
KubeClient kubernetes.Interface
SvcNegClient svcnegclient.Interface
DestinationRuleClient dynamic.NamespaceableResourceInterface

Cloud *gce.Cloud
Expand All @@ -76,6 +79,7 @@ type ControllerContext struct {
EndpointInformer cache.SharedIndexInformer
DestinationRuleInformer cache.SharedIndexInformer
ConfigMapInformer cache.SharedIndexInformer
SvcNegInformer cache.SharedIndexInformer

ControllerMetrics *metrics.ControllerMetrics

Expand Down Expand Up @@ -106,6 +110,7 @@ func NewControllerContext(
kubeClient kubernetes.Interface,
backendConfigClient backendconfigclient.Interface,
frontendConfigClient frontendconfigclient.Interface,
svcnegClient svcnegclient.Interface,
cloud *gce.Cloud,
namer *namer.Namer,
kubeSystemUID types.UID,
Expand All @@ -114,6 +119,7 @@ func NewControllerContext(
context := &ControllerContext{
KubeConfig: kubeConfig,
KubeClient: kubeClient,
SvcNegClient: svcnegClient,
Cloud: cloud,
ClusterNamer: namer,
KubeSystemUID: kubeSystemUID,
Expand All @@ -133,6 +139,10 @@ func NewControllerContext(
context.FrontendConfigInformer = informerfrontendconfig.NewFrontendConfigInformer(frontendConfigClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer())
}

if svcnegClient != nil {
context.SvcNegInformer = informersvcneg.NewServiceNetworkEndpointGroupInformer(svcnegClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer())
}

return context
}

Expand Down Expand Up @@ -231,6 +241,10 @@ func (ctx *ControllerContext) HasSynced() bool {
funcs = append(funcs, ctx.ConfigMapInformer.HasSynced)
}

if ctx.SvcNegInformer != nil {
funcs = append(funcs, ctx.SvcNegInformer.HasSynced)
}

for _, f := range funcs {
if !f() {
return false
Expand Down Expand Up @@ -301,6 +315,9 @@ func (ctx *ControllerContext) Start(stopCh chan struct{}) {
if ctx.EnableASMConfigMap && ctx.ConfigMapInformer != nil {
go ctx.ConfigMapInformer.Run(stopCh)
}
if ctx.SvcNegInformer != nil {
go ctx.SvcNegInformer.Run(stopCh)
}
// Export ingress usage metrics.
go ctx.ControllerMetrics.Run(stopCh)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func newLoadBalancerController() *LoadBalancerController {
DefaultBackendSvcPort: test.DefaultBeSvcPort,
HealthCheckPath: "/",
}
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
lbc := NewLoadBalancerController(ctx, stopCh)
// TODO(rramkumar): Fix this so we don't have to override with our fake
lbc.instancePool = instances.NewNodePool(instances.NewFakeInstanceGroups(sets.NewString(), namer), namer, &test.FakeRecorderSource{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func fakeTranslator() *Translator {
DefaultBackendSvcPort: defaultBackend,
HealthCheckPath: "/",
}
ctx := context.NewControllerContext(nil, client, backendConfigClient, nil, nil, defaultNamer, "" /*kubeSystemUID*/, ctxConfig)
ctx := context.NewControllerContext(nil, client, backendConfigClient, nil, nil, nil, defaultNamer, "" /*kubeSystemUID*/, ctxConfig)
gce := &Translator{
ctx: ctx,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/firewalls/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newFirewallController() *FirewallController {
DefaultBackendSvcPort: test.DefaultBeSvcPort,
}

ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, fakeGCE, defaultNamer, "" /*kubeSystemUID*/, ctxConfig)
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, fakeGCE, defaultNamer, "" /*kubeSystemUID*/, ctxConfig)
fwc := NewFirewallController(ctx, []string{"30000-32767"})
fwc.hasSynced = func() bool { return true }

Expand Down
2 changes: 1 addition & 1 deletion pkg/l4/l4controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newServiceController() *L4Controller {
Namespace: api_v1.NamespaceAll,
ResyncPeriod: 1 * time.Minute,
}
ctx := context.NewControllerContext(nil, kubeClient, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
ctx := context.NewControllerContext(nil, kubeClient, nil, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
return NewController(ctx, stopCh)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func newTestController(kubeClient kubernetes.Interface) *Controller {
ASMConfigMapNamespace: "kube-system",
ASMConfigMapName: "ingress-controller-config-test",
}
context := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, gce.NewFakeGCECloud(gce.DefaultTestClusterValues()), namer, "" /*kubeSystemUID*/, ctxConfig)
context := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, gce.NewFakeGCECloud(gce.DefaultTestClusterValues()), namer, "" /*kubeSystemUID*/, ctxConfig)

// Hack the context.Init func.
configMapInformer := informerv1.NewConfigMapInformer(kubeClient, context.Namespace, context.ResyncPeriod, utils.NewNamespaceIndexer())
Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewTestSyncerManager(kubeClient kubernetes.Interface) *syncerManager {
ResyncPeriod: 1 * time.Second,
DefaultBackendSvcPort: defaultBackend,
}
context := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, gce.NewFakeGCECloud(gce.DefaultTestClusterValues()), namer, "" /*kubeSystemUID*/, ctxConfig)
context := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, gce.NewFakeGCECloud(gce.DefaultTestClusterValues()), namer, "" /*kubeSystemUID*/, ctxConfig)

manager := newSyncerManager(
namer,
Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/readiness/reflector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func fakeContext() *context.ControllerContext {
}
fakeGCE := gce.NewFakeGCECloud(gce.DefaultTestClusterValues())
negtypes.MockNetworkEndpointAPIs(fakeGCE)
context := context.NewControllerContext(nil, kubeClient, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
context := context.NewControllerContext(nil, kubeClient, nil, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
return context
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/syncers/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newSyncerTester() *syncerTester {
ResyncPeriod: 1 * time.Second,
DefaultBackendSvcPort: defaultBackend,
}
context := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, namer, "" /*kubeSystemUID*/, ctxConfig)
context := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, nil, namer, "" /*kubeSystemUID*/, ctxConfig)
negSyncerKey := negtypes.NegSyncerKey{
Namespace: testServiceNamespace,
Name: testServiceName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/syncers/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ func newTestTransactionSyncer(fakeGCE negtypes.NetworkEndpointGroupCloud, negTyp
ResyncPeriod: 1 * time.Second,
DefaultBackendSvcPort: defaultBackend,
}
context := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, namer, "" /*kubeSystemUID*/, ctxConfig)
context := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, nil, namer, "" /*kubeSystemUID*/, ctxConfig)
svcPort := negtypes.NegSyncerKey{
Namespace: testNamespace,
Name: testService,
Expand Down
2 changes: 1 addition & 1 deletion pkg/svcneg/svcneg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func CRDMeta() *crd.CRDMeta {
apisneg.GroupName,
"v1beta1",
"ServiceNetworkEndpointGroup",
"ServiceNetworkingEndpointGroupList",
"ServiceNetworkEndpointGroupList",
"servicenetworkendpointgroup",
"servicenetworkendpointgroups",
)
Expand Down

0 comments on commit 32b9c29

Please sign in to comment.