Skip to content

Commit

Permalink
delay initial NEG GC by one GC period
Browse files Browse the repository at this point in the history
  • Loading branch information
freehan committed Sep 13, 2018
1 parent 2a05ae3 commit d3654a2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func runControllers(ctx *context.ControllerContext) {

if ctx.NEGEnabled {
// TODO: Refactor NEG to use cloud mocks so ctx.Cloud can be referenced within NewController.
negController := neg.NewController(neg.NewAdapter(ctx.Cloud), ctx, lbc.Translator, ctx.ClusterNamer, flags.F.ResyncPeriod)
negController := neg.NewController(neg.NewAdapter(ctx.Cloud), ctx, lbc.Translator, ctx.ClusterNamer, flags.F.ResyncPeriod, flags.F.NegGCPeriod)
go negController.Run(stopCh)
glog.V(0).Infof("negController started")
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var (
WatchNamespace string
NodePortRanges PortRanges
EnableBackendConfig bool
NegGCPeriod time.Duration

LeaderElection LeaderElectionConfiguration
}{}
Expand Down Expand Up @@ -215,6 +216,8 @@ L7 load balancing. CSV values accepted. Example: -node-port-ranges=80,8080,400-5
`This flag is deprecated. Use -v to control verbosity.`)
flag.Bool("use-real-cloud", false,
`This flag has been deprecated and no longer has any effect.`)
flag.DurationVar(&F.NegGCPeriod, "neg-gc-period", 120*time.Second,
`Relist and garbage collect NEGs this often.`)
}

type RateLimitSpecs struct {
Expand Down
17 changes: 10 additions & 7 deletions pkg/neg/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ import (
"k8s.io/ingress-gce/pkg/utils"
)

const (
// gcPeriod is the interval between NEG garbage collection workflows
gcPeriod = 2 * time.Minute
)

func init() {
// register prometheus metrics
registerMetrics()
Expand All @@ -55,6 +50,7 @@ func init() {
type Controller struct {
manager negSyncerManager
resyncPeriod time.Duration
gcPeriod time.Duration
recorder record.EventRecorder
namer networkEndpointGroupNamer
zoneGetter zoneGetter
Expand All @@ -79,7 +75,8 @@ func NewController(
ctx *context.ControllerContext,
zoneGetter zoneGetter,
namer networkEndpointGroupNamer,
resyncPeriod time.Duration) *Controller {
resyncPeriod time.Duration,
gcPeriod time.Duration) *Controller {
// init event recorder
// TODO: move event recorder initializer to main. Reuse it among controllers.
eventBroadcaster := record.NewBroadcaster()
Expand All @@ -96,6 +93,7 @@ func NewController(
client: ctx.KubeClient,
manager: manager,
resyncPeriod: resyncPeriod,
gcPeriod: gcPeriod,
recorder: recorder,
zoneGetter: zoneGetter,
namer: namer,
Expand Down Expand Up @@ -172,7 +170,12 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
}()

go wait.Until(c.serviceWorker, time.Second, stopCh)
go wait.Until(c.gc, gcPeriod, stopCh)
go func() {
// Wait for gcPeriod to run the first GC
// This is to make sure that all services are fully processed before running GC.
time.Sleep(c.gcPeriod)
wait.Until(c.gc, c.gcPeriod, stopCh)
}()

<-stopCh
}
Expand Down
1 change: 1 addition & 0 deletions pkg/neg/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func newTestController(kubeClient kubernetes.Interface) *Controller {
NewFakeZoneGetter(),
namer,
1*time.Second,
1*time.Second,
)
return controller
}
Expand Down

0 comments on commit d3654a2

Please sign in to comment.