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

Support configurable reconcile rates #312

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
13 changes: 1 addition & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ crds.clean:

generate: crds.clean

# Ensure a PR is ready for review.
reviewable: generate lint
@go mod tidy

# Ensure branch is clean.
check-diff: reviewable
@$(INFO) checking that branch is clean
@test -z "$$(git status --porcelain)" || $(FAIL)
@$(OK) branch is clean

# integration tests
e2e.run: test-integration

Expand Down Expand Up @@ -127,15 +117,14 @@ export TEST_ASSET_KUBE_APISERVER TEST_ASSET_ETCD

test.init: $(KUBEBUILDER)

.PHONY: cobertura reviewable submodules fallthrough test-integration run manifests crds.clean
.PHONY: cobertura submodules fallthrough test-integration run manifests crds.clean

# ====================================================================================
# Special Targets

define CROSSPLANE_MAKE_HELP
Crossplane Targets:
cobertura Generate a coverage report for cobertura applying exclusions on generated files.
reviewable Ensure a PR is ready for review.
submodules Update the submodules, such as the common build scripts.
run Run crossplane locally, out-of-cluster. Useful for development.

Expand Down
2 changes: 1 addition & 1 deletion build
40 changes: 30 additions & 10 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,30 @@ package main
import (
"os"
"path/filepath"
"time"

"gopkg.in/alecthomas/kingpin.v2"
"k8s.io/client-go/tools/leaderelection/resourcelock"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/crossplane/crossplane-runtime/pkg/controller"
"github.com/crossplane/crossplane-runtime/pkg/logging"
"github.com/crossplane/crossplane-runtime/pkg/ratelimiter"

"github.com/crossplane/provider-azure/apis"
"github.com/crossplane/provider-azure/pkg/controller"
azure "github.com/crossplane/provider-azure/pkg/controller"
)

func main() {
var (
app = kingpin.New(filepath.Base(os.Args[0]), "Azure support for Crossplane.").DefaultEnvars()
debug = app.Flag("debug", "Run with debug logging.").Short('d').Bool()
syncInterval = app.Flag("sync", "Sync interval controls how often all resources will be double checked for drift.").Short('s').Default("1h").Duration()
pollInterval = app.Flag("poll", "Poll interval controls how often an individual resource should be checked for drift.").Default("1m").Duration()
leaderElection = app.Flag("leader-election", "Use leader election for the conroller manager.").Short('l').Default("false").OverrideDefaultFromEnvar("LEADER_ELECTION").Bool()

syncInterval = app.Flag("sync", "How often all resources will be double-checked for drift from the desired state.").Short('s').Default("1h").Duration()
pollInterval = app.Flag("poll", "How often individual resources will be checked for drift from the desired state").Default("1m").Duration()
maxReconcileRate = app.Flag("max-reconcile-rate", "The global maximum rate per second at which resources may checked for drift from the desired state.").Default("10").Int()
)
kingpin.MustParse(app.Parse(os.Args[1:]))

Expand All @@ -50,20 +55,35 @@ func main() {
ctrl.SetLogger(zl)
}

log.Debug("Starting", "sync-period", syncInterval.String())

cfg, err := ctrl.GetConfig()
kingpin.FatalIfError(err, "Cannot get API server rest config")

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
LeaderElection: *leaderElection,
LeaderElectionID: "crossplane-leader-election-provider-azure",
SyncPeriod: syncInterval,
SyncPeriod: syncInterval,

// controller-runtime uses both ConfigMaps and Leases for leader
// election by default. Leases expire after 15 seconds, with a
// 10 second renewal deadline. We've observed leader loss due to
// renewal deadlines being exceeded when under high load - i.e.
// hundreds of reconciles per second and ~200rps to the API
// server. Switching to Leases only and longer leases appears to
// alleviate this.
LeaderElection: *leaderElection,
LeaderElectionID: "crossplane-leader-election-provider-azure",
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaseDuration: func() *time.Duration { d := 60 * time.Second; return &d }(),
RenewDeadline: func() *time.Duration { d := 50 * time.Second; return &d }(),
})
kingpin.FatalIfError(err, "Cannot create controller manager")

o := controller.Options{
Logger: log,
MaxConcurrentReconciles: *maxReconcileRate,
PollInterval: *pollInterval,
GlobalRateLimiter: ratelimiter.NewGlobal(*maxReconcileRate),
}

kingpin.FatalIfError(apis.AddToScheme(mgr.GetScheme()), "Cannot add Azure APIs to scheme")
kingpin.FatalIfError(controller.Setup(mgr, log, ratelimiter.NewDefaultProviderRateLimiter(ratelimiter.DefaultProviderRPS), *pollInterval), "Cannot setup Azure controllers")
kingpin.FatalIfError(azure.Setup(mgr, o), "Cannot setup Azure controllers")
kingpin.FatalIfError(mgr.Start(ctrl.SetupSignalHandler()), "Cannot start controller manager")

}
22 changes: 9 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,25 @@ require (
github.com/Azure/azure-pipeline-go v0.2.2 // indirect
github.com/Azure/azure-sdk-for-go v42.3.0+incompatible
github.com/Azure/azure-storage-blob-go v0.7.0
github.com/Azure/go-autorest/autorest v0.11.1
github.com/Azure/go-autorest/autorest v0.11.12
github.com/Azure/go-autorest/autorest/adal v0.9.5
github.com/Azure/go-autorest/autorest/azure/auth v0.4.0
github.com/Azure/go-autorest/autorest/date v0.3.0
github.com/Azure/go-autorest/autorest/to v0.3.0
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
github.com/crossplane/crossplane-runtime v0.14.0
github.com/crossplane/crossplane-runtime v0.15.1-0.20211202230900-d43d510ec578
github.com/crossplane/crossplane-tools v0.0.0-20210320162312-1baca298c527
github.com/google/go-cmp v0.5.2
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.1.2
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-ieproxy v0.0.0-20190805055040-f9202b1cfdeb // indirect
github.com/mitchellh/copystructure v1.2.0
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/onsi/gomega v1.10.2
github.com/onsi/gomega v1.14.0
github.com/pkg/errors v0.9.1
github.com/satori/go.uuid v1.2.0 // indirect
golang.org/x/tools v0.0.0-20200916195026-c9a70fc28ce3 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
k8s.io/api v0.20.1
k8s.io/apimachinery v0.20.2
k8s.io/client-go v0.20.1
sigs.k8s.io/controller-runtime v0.8.0
sigs.k8s.io/controller-tools v0.4.0
k8s.io/api v0.21.3
k8s.io/apimachinery v0.21.3
k8s.io/client-go v0.21.3
sigs.k8s.io/controller-runtime v0.9.6
sigs.k8s.io/controller-tools v0.6.2
)
Loading