Skip to content
Open
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: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ linters:
- durationcheck
- errchkjson
- errorlint
- forbidigo
- gocheckcompilerdirectives
- gochecksumtype
- goconst
Expand Down Expand Up @@ -46,6 +47,15 @@ linters:
exclude-functions:
- fmt:.*
- io/ioutil:^Read.*
forbidigo:
forbid:
- pattern: ^managed\.NewReconciler$
pkg: ^github\.com/crossplane/crossplane-runtime/v2/pkg/reconciler/managed$
msg: Use common.NewReconciler so the controller applies the provider-wide reconciler options.
- pattern: ^statemetrics\.NewMRStateRecorder$
pkg: ^github\.com/crossplane/crossplane-runtime/v2/pkg/statemetrics$
msg: Use common.AddMRStateRecorder so the controller skips the recorder when no state metrics are configured.
analyze-types: true
goconst:
min-len: 3
min-occurrences: 5
Expand Down Expand Up @@ -92,6 +102,9 @@ linters:
- gocritic
path: _test\.go
text: (unnamedResult|exitAfterDefer)
- linters:
- forbidigo
path: pkg/common/controller\.go
- linters:
- gocritic
text: '(hugeParam|rangeValCopy):'
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ spec:
kubectl apply -f examples/providerconfig/provider.yaml
```

### Poll intervals

The provider checks every managed resource for drift on a timer. These provider
flags set the timer:

| Flag | Default | Description |
| --- | --- | --- |
| `--poll` | `1m` | How often the provider checks each resource. |
| `--min-poll-interval` | `10s` | The shortest interval a resource can request with the `crossplane.io/poll-interval` annotation. The provider also reads it from `MIN_POLL_INTERVAL`. Set it to `0s` to remove the minimum. |
| `--sync` | `1h` | How often the provider reconciles all resources, whatever their poll interval. |

To poll one resource at a different interval, set the
`crossplane.io/poll-interval` annotation to a Go duration such as `5m` or `24h`.
If the value is shorter than `--min-poll-interval`, the provider polls at
`--min-poll-interval`. Each poll makes at least one GitLab API call. Many
resources with a short interval can use up the rate limit of the ProviderConfig
token, and GitLab then throttles every resource that uses that ProviderConfig.

To change a flag, add it to the `args` of the `package-runtime` container in a
`DeploymentRuntimeConfig`.

### Self-rotating service account tokens

The namespaced `groups.gitlab.m.crossplane.io/v1alpha1` `ServiceAccountAccessToken`
Expand Down
23 changes: 14 additions & 9 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
apisCluster "github.com/crossplane-contrib/provider-gitlab/apis/cluster"
apisNamespaced "github.com/crossplane-contrib/provider-gitlab/apis/namespaced"
controllerCluster "github.com/crossplane-contrib/provider-gitlab/pkg/cluster/controller"
"github.com/crossplane-contrib/provider-gitlab/pkg/common"
controllerNamespaced "github.com/crossplane-contrib/provider-gitlab/pkg/namespaced/controller"
)

Expand All @@ -56,6 +57,7 @@ func main() {
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()
minPollInterval = app.Flag("min-poll-interval", "Minimum poll interval a resource may request with the crossplane.io/poll-interval annotation. Shorter values are raised to this minimum.").Default("10s").Envar("MIN_POLL_INTERVAL").Duration()
leaderElection = app.Flag("leader-election", "Use leader election for the conroller manager.").Short('l').Default("false").OverrideDefaultFromEnvar("LEADER_ELECTION").Bool()
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()

Expand All @@ -76,7 +78,7 @@ func main() {
ctrl.SetLogger(zl)
}

log.Debug("Starting", "sync-period", syncInterval.String())
log.Debug("Starting", "sync-period", syncInterval.String(), "poll-interval", pollInterval.String(), "min-poll-interval", minPollInterval.String())

cfg, err := ctrl.GetConfig()
kingpin.FatalIfError(err, "Cannot get API server rest config")
Expand Down Expand Up @@ -118,13 +120,16 @@ func main() {
kingpin.FatalIfError(apisCluster.AddToScheme(mgr.GetScheme()), "Cannot add Gitlab legacy APIs to scheme")
kingpin.FatalIfError(apisNamespaced.AddToScheme(mgr.GetScheme()), "Cannot add Gitlab legacy APIs to scheme")

o := xpcontroller.Options{
Logger: log,
MaxConcurrentReconciles: *maxReconcileRate,
PollInterval: *pollInterval,
GlobalRateLimiter: ratelimiter.NewGlobal(*maxReconcileRate),
Features: &feature.Flags{},
MetricOptions: &mo,
o := common.ControllerOptions{
Options: xpcontroller.Options{
Logger: log,
MaxConcurrentReconciles: *maxReconcileRate,
PollInterval: *pollInterval,
GlobalRateLimiter: ratelimiter.NewGlobal(*maxReconcileRate),
Features: &feature.Flags{},
MetricOptions: &mo,
},
MinPollInterval: *minPollInterval,
}

if *enableManagementPolicies {
Expand All @@ -139,7 +144,7 @@ func main() {
if canSafeStart {
crdGate := new(gate.Gate[schema.GroupVersionKind])
o.Gate = crdGate
kingpin.FatalIfError(customresourcesgate.Setup(mgr, o), "Cannot setup CRD gate")
kingpin.FatalIfError(customresourcesgate.Setup(mgr, o.Options), "Cannot setup CRD gate")
kingpin.FatalIfError(controllerCluster.SetupGated(mgr, o), "Cannot setup Gitlab legacy controllers")
kingpin.FatalIfError(controllerNamespaced.SetupGated(mgr, o), "Cannot setup Gitlab modern controllers")
} else {
Expand Down
6 changes: 3 additions & 3 deletions pkg/cluster/controller/config/zz_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions pkg/cluster/controller/config/zz_setup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 6 additions & 21 deletions pkg/cluster/controller/groups/accesstokens/zz_controller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 6 additions & 21 deletions pkg/cluster/controller/groups/badges/zz_controller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 6 additions & 21 deletions pkg/cluster/controller/groups/deploytokens/zz_controller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading