Skip to content

Commit

Permalink
Create client and informers for Network and GKENetworkParamSet when f…
Browse files Browse the repository at this point in the history
…lag --enable-multi-networking is set.
  • Loading branch information
mmamczur committed Mar 20, 2023
1 parent 9dbf38c commit 8d007b1
Show file tree
Hide file tree
Showing 72 changed files with 5,344 additions and 36 deletions.
11 changes: 10 additions & 1 deletion cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
networkclient "k8s.io/cloud-provider-gcp/crd/client/network/clientset/versioned"
"math/rand"
"os"
"time"
Expand Down Expand Up @@ -159,6 +160,14 @@ func main() {
}
}

var networkClient networkclient.Interface
if flags.F.EnableMultiNetworking {
networkClient, err = networkclient.NewForConfig(kubeConfig)
if err != nil {
klog.Fatalf("Failed to create Network client: %v", err)
}
}

ingClassEnabled := flags.F.EnableIngressGAFields && app.IngressClassEnabled(kubeClient)
var ingParamsClient ingparamsclient.Interface
if ingClassEnabled {
Expand Down Expand Up @@ -204,7 +213,7 @@ func main() {
EnableL4ILBDualStack: flags.F.EnableL4ILBDualStack,
EnableL4NetLBDualStack: flags.F.EnableL4NetLBDualStack,
}
ctx := ingctx.NewControllerContext(kubeConfig, kubeClient, backendConfigClient, frontendConfigClient, svcNegClient, ingParamsClient, svcAttachmentClient, cloud, namer, kubeSystemUID, ctxConfig)
ctx := ingctx.NewControllerContext(kubeConfig, kubeClient, backendConfigClient, frontendConfigClient, svcNegClient, ingParamsClient, svcAttachmentClient, networkClient, cloud, namer, kubeSystemUID, ctxConfig)
go app.RunHTTPServer(ctx.HealthCheck)

if !flags.F.LeaderElection.LeaderElect {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
k8s.io/cloud-provider v0.26.1
k8s.io/cloud-provider-gcp/crd v0.0.0-20230307122835-9283b54f2c6a
k8s.io/component-base v0.26.1
k8s.io/klog/v2 v2.80.1
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ k8s.io/client-go v0.26.1 h1:87CXzYJnAMGaa/IDDfRdhTzxk/wzGZ+/HUQpqgVSZXU=
k8s.io/client-go v0.26.1/go.mod h1:IWNSglg+rQ3OcvDkhY6+QLeasV4OYHDjdqeWkDQZwGE=
k8s.io/cloud-provider v0.26.1 h1:qEZmsGWGptOtVSpeMdTsapHX2BEqIk7rc5MA4caBqE0=
k8s.io/cloud-provider v0.26.1/go.mod h1:6PheIxRySYuRBBxtTUADya8S2rbr18xKi+fhGbLkduc=
k8s.io/cloud-provider-gcp/crd v0.0.0-20230307122835-9283b54f2c6a h1:d335eStRg6A1L8KBmkaYKWR0/sj4unOVHZQTVmA33vA=
k8s.io/cloud-provider-gcp/crd v0.0.0-20230307122835-9283b54f2c6a/go.mod h1:YDxdayH9Du6f2XUhZiRfM2B0vsJ9b7qbrmI2J2dd89Y=
k8s.io/component-base v0.26.1 h1:4ahudpeQXHZL5kko+iDHqLj/FSGAEUnSVO0EBbgDd+4=
k8s.io/component-base v0.26.1/go.mod h1:VHrLR0b58oC035w6YQiBSbtsf0ThuSwXP+p5dD/kAWU=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
Expand Down
86 changes: 56 additions & 30 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
networkclient "k8s.io/cloud-provider-gcp/crd/client/network/clientset/versioned"
informernetwork "k8s.io/cloud-provider-gcp/crd/client/network/informers/externalversions/network/v1"
informergkenetworkparamset "k8s.io/cloud-provider-gcp/crd/client/network/informers/externalversions/network/v1alpha1"
sav1 "k8s.io/ingress-gce/pkg/apis/serviceattachment/v1"
sav1beta1 "k8s.io/ingress-gce/pkg/apis/serviceattachment/v1beta1"
backendconfigclient "k8s.io/ingress-gce/pkg/backendconfig/client/clientset/versioned"
Expand Down Expand Up @@ -79,18 +82,20 @@ type ControllerContext struct {
ControllerContextConfig
ASMConfigController *cmconfig.ConfigMapConfigController

IngressInformer cache.SharedIndexInformer
ServiceInformer cache.SharedIndexInformer
BackendConfigInformer cache.SharedIndexInformer
FrontendConfigInformer cache.SharedIndexInformer
PodInformer cache.SharedIndexInformer
NodeInformer cache.SharedIndexInformer
EndpointSliceInformer cache.SharedIndexInformer
ConfigMapInformer cache.SharedIndexInformer
SvcNegInformer cache.SharedIndexInformer
IngClassInformer cache.SharedIndexInformer
IngParamsInformer cache.SharedIndexInformer
SAInformer cache.SharedIndexInformer
IngressInformer cache.SharedIndexInformer
ServiceInformer cache.SharedIndexInformer
BackendConfigInformer cache.SharedIndexInformer
FrontendConfigInformer cache.SharedIndexInformer
PodInformer cache.SharedIndexInformer
NodeInformer cache.SharedIndexInformer
EndpointSliceInformer cache.SharedIndexInformer
ConfigMapInformer cache.SharedIndexInformer
SvcNegInformer cache.SharedIndexInformer
IngClassInformer cache.SharedIndexInformer
IngParamsInformer cache.SharedIndexInformer
SAInformer cache.SharedIndexInformer
NetworkInformer cache.SharedIndexInformer
GKENetworkParamsInformer cache.SharedIndexInformer

ControllerMetrics *metrics.ControllerMetrics

Expand Down Expand Up @@ -136,30 +141,39 @@ func NewControllerContext(
svcnegClient svcnegclient.Interface,
ingParamsClient ingparamsclient.Interface,
saClient serviceattachmentclient.Interface,
networkClient networkclient.Interface,
cloud *gce.Cloud,
clusterNamer *namer.Namer,
kubeSystemUID types.UID,
config ControllerContextConfig) *ControllerContext {

var networkInformer cache.SharedIndexInformer
var gkeNetworkParamSetInformer cache.SharedIndexInformer
if networkClient != nil {
networkInformer = informernetwork.NewNetworkInformer(networkClient, config.ResyncPeriod, utils.NewNamespaceIndexer())
gkeNetworkParamSetInformer = informergkenetworkparamset.NewGKENetworkParamSetInformer(networkClient, config.ResyncPeriod, utils.NewNamespaceIndexer())
}
context := &ControllerContext{
KubeConfig: kubeConfig,
KubeClient: kubeClient,
SvcNegClient: svcnegClient,
SAClient: saClient,
Cloud: cloud,
ClusterNamer: clusterNamer,
L4Namer: namer.NewL4Namer(string(kubeSystemUID), clusterNamer),
KubeSystemUID: kubeSystemUID,
ControllerMetrics: metrics.NewControllerMetrics(flags.F.MetricsExportInterval, flags.F.L4NetLBProvisionDeadline),
ControllerContextConfig: config,
IngressInformer: informernetworking.NewIngressInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
ServiceInformer: informerv1.NewServiceInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
BackendConfigInformer: informerbackendconfig.NewBackendConfigInformer(backendConfigClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
PodInformer: informerv1.NewPodInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
NodeInformer: informerv1.NewNodeInformer(kubeClient, config.ResyncPeriod, utils.NewNamespaceIndexer()),
SvcNegInformer: informersvcneg.NewServiceNetworkEndpointGroupInformer(svcnegClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
recorders: map[string]record.EventRecorder{},
healthChecks: make(map[string]func() error),
KubeConfig: kubeConfig,
KubeClient: kubeClient,
SvcNegClient: svcnegClient,
SAClient: saClient,
Cloud: cloud,
ClusterNamer: clusterNamer,
L4Namer: namer.NewL4Namer(string(kubeSystemUID), clusterNamer),
KubeSystemUID: kubeSystemUID,
ControllerMetrics: metrics.NewControllerMetrics(flags.F.MetricsExportInterval, flags.F.L4NetLBProvisionDeadline),
ControllerContextConfig: config,
IngressInformer: informernetworking.NewIngressInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
ServiceInformer: informerv1.NewServiceInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
BackendConfigInformer: informerbackendconfig.NewBackendConfigInformer(backendConfigClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
PodInformer: informerv1.NewPodInformer(kubeClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
NodeInformer: informerv1.NewNodeInformer(kubeClient, config.ResyncPeriod, utils.NewNamespaceIndexer()),
SvcNegInformer: informersvcneg.NewServiceNetworkEndpointGroupInformer(svcnegClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer()),
NetworkInformer: networkInformer,
GKENetworkParamsInformer: gkeNetworkParamSetInformer,
recorders: map[string]record.EventRecorder{},
healthChecks: make(map[string]func() error),
}
if config.FrontendConfigEnabled {
context.FrontendConfigInformer = informerfrontendconfig.NewFrontendConfigInformer(frontendConfigClient, config.Namespace, config.ResyncPeriod, utils.NewNamespaceIndexer())
Expand Down Expand Up @@ -261,6 +275,12 @@ func (ctx *ControllerContext) HasSynced() bool {
if ctx.SAInformer != nil {
funcs = append(funcs, ctx.SAInformer.HasSynced)
}
if ctx.NetworkInformer != nil {
funcs = append(funcs, ctx.NetworkInformer.HasSynced)
}
if ctx.GKENetworkParamsInformer != nil {
funcs = append(funcs, ctx.GKENetworkParamsInformer.HasSynced)
}

for _, f := range funcs {
if !f() {
Expand Down Expand Up @@ -342,6 +362,12 @@ func (ctx *ControllerContext) Start(stopCh chan struct{}) {
if ctx.SAInformer != nil {
go ctx.SAInformer.Run(stopCh)
}
if ctx.NetworkInformer != nil {
go ctx.NetworkInformer.Run(stopCh)
}
if ctx.GKENetworkParamsInformer != nil {
go ctx.GKENetworkParamsInformer.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 @@ -72,7 +72,7 @@ func newLoadBalancerController() *LoadBalancerController {
DefaultBackendSvcPort: test.DefaultBeSvcPort,
HealthCheckPath: "/",
}
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, nil, 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 = instancegroups.NewManager(&instancegroups.ManagerConfig{
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 @@ -49,7 +49,7 @@ func newFirewallController() *FirewallController {
DefaultBackendSvcPort: test.DefaultBeSvcPort,
}

ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, nil, nil, fakeGCE, defaultNamer, "" /*kubeSystemUID*/, ctxConfig)
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, nil, 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/l4lb/l4controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func newServiceController(t *testing.T, fakeGCE *gce.Cloud) *L4Controller {
ResyncPeriod: 1 * time.Minute,
NumL4Workers: 5,
}
ctx := context.NewControllerContext(nil, kubeClient, nil, nil, nil, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
ctx := context.NewControllerContext(nil, kubeClient, nil, nil, nil, nil, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
// Add some nodes so that NEG linker kicks in during ILB creation.
nodes, err := test.CreateAndInsertNodes(ctx.Cloud, []string{"instance-1"}, vals.ZoneName)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/l4lb/l4netlbcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func buildContext(vals gce.TestClusterValues) *ingctx.ControllerContext {
NumL4NetLBWorkers: 5,
MaxIGSize: 1000,
}
return ingctx.NewControllerContext(nil, kubeClient, nil, nil, nil, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
return ingctx.NewControllerContext(nil, kubeClient, nil, nil, nil, nil, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig)
}

func newL4NetLBServiceController() *L4NetLBController {
Expand Down
2 changes: 1 addition & 1 deletion pkg/psc/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ func newTestController(clusterType string) *Controller {

flags.F.GKEClusterName = ClusterName
flags.F.GKEClusterType = clusterType
ctx := context.NewControllerContext(nil, kubeClient, nil, nil, nil, nil, saClient, gceClient, resourceNamer, kubeSystemUID, ctxConfig)
ctx := context.NewControllerContext(nil, kubeClient, nil, nil, nil, nil, saClient, nil, gceClient, resourceNamer, kubeSystemUID, ctxConfig)

return NewController(ctx)
}
Expand Down
Loading

0 comments on commit 8d007b1

Please sign in to comment.