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 Apr 12, 2023
1 parent 9677731 commit c1176f5
Show file tree
Hide file tree
Showing 61 changed files with 5,167 additions and 38 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 @@ -160,6 +161,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 @@ -205,7 +214,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.2
k8s.io/client-go v0.26.2
k8s.io/cloud-provider v0.26.2
k8s.io/cloud-provider-gcp/crd v0.0.0-20230322202223-f7280f55e36f
k8s.io/cloud-provider-gcp/providers v0.26.3-0.20230322202223-f7280f55e36f
k8s.io/component-base v0.26.2
k8s.io/klog/v2 v2.80.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=
github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys=
github.com/onsi/ginkgo/v2 v2.6.1 h1:1xQPCjcqYw/J5LchOcp4/2q/jzJFjiAOc25chhnDw+Q=
github.com/onsi/gomega v1.24.2 h1:J/tulyYK6JwBldPViHJReihxxZ+22FHs0piGjQAvoUE=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -620,6 +620,8 @@ k8s.io/client-go v0.26.2 h1:s1WkVujHX3kTp4Zn4yGNFK+dlDXy1bAAkIl+cFAiuYI=
k8s.io/client-go v0.26.2/go.mod h1:u5EjOuSyBa09yqqyY7m3abZeovO/7D/WehVVlZ2qcqU=
k8s.io/cloud-provider v0.26.2 h1:VlLGDayUV5VBpvMSBFqmpz2HHTjBLUw02wuZzNeEsW0=
k8s.io/cloud-provider v0.26.2/go.mod h1:/Am9R0merLIZgVqPTE4Z1JkBcCrp2uXImHCxnvVARxc=
k8s.io/cloud-provider-gcp/crd v0.0.0-20230322202223-f7280f55e36f h1:6gjbpA3IVXjIJRKRqgYQlKc9vPtxlhMABQUI0vB5f0M=
k8s.io/cloud-provider-gcp/crd v0.0.0-20230322202223-f7280f55e36f/go.mod h1:A//VRRwQBcvAI20bbCc5jmxMSegf/DqxDI7XVK9oyYo=
k8s.io/cloud-provider-gcp/providers v0.26.3-0.20230322202223-f7280f55e36f h1:XPbo07vZ+h1xiGFIAN+gmlGm6G8zrZyhf/Xb6jNerTk=
k8s.io/cloud-provider-gcp/providers v0.26.3-0.20230322202223-f7280f55e36f/go.mod h1:dDBqOcDqYsqo7ZM7yuX+6Xg9WiyEPYk1Q9m2oHrnePo=
k8s.io/component-base v0.26.2 h1:IfWgCGUDzrD6wLLgXEstJKYZKAFS2kO+rBRi0p3LqcI=
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"
"k8s.io/cloud-provider-gcp/providers/gce"
sav1 "k8s.io/ingress-gce/pkg/apis/serviceattachment/v1"
sav1beta1 "k8s.io/ingress-gce/pkg/apis/serviceattachment/v1beta1"
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 c1176f5

Please sign in to comment.