Skip to content

Commit

Permalink
Bump to crossplane v1.16 and enable MR metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nolancon committed May 20, 2024
1 parent fecd24e commit 414fbe1
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ LATEST_KUBE_VERSION ?= 1.29
LATEST_KIND_NODE ?= 1.29.2
REPO ?= provider-ceph

CROSSPLANE_VERSION ?= 1.15.0
CROSSPLANE_VERSION ?= 1.16.0
LOCALSTACK_VERSION ?= 2.2
CERT_MANAGER_VERSION ?= 1.14.0

Expand Down
43 changes: 30 additions & 13 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
kcache "sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/webhook"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
Expand All @@ -50,7 +51,9 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/logging"
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/ratelimiter"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/crossplane-runtime/pkg/statemetrics"

"github.com/linode/provider-ceph/apis"
providercephv1alpha1 "github.com/linode/provider-ceph/apis/provider-ceph/v1alpha1"
Expand Down Expand Up @@ -80,19 +83,20 @@ func main() {
leaderElection = app.Flag("leader-election", "Use leader election for the controller manager.").Short('l').Default("false").OverrideDefaultFromEnvar("LEADER_ELECTION").Bool()
leaderRenew = app.Flag("leader-renew", "Set leader election renewal.").Short('r').Default("10s").OverrideDefaultFromEnvar("LEADER_ELECTION_RENEW").Duration()

syncInterval = app.Flag("sync", "How often all resources will be double-checked for drift from the desired state.").Short('s').Default("1h").Duration()
syncTimeout = app.Flag("sync-timeout", "Cache sync timeout.").Default("10s").Duration()
pollInterval = app.Flag("poll", "How often individual resources will be checked for drift from the desired state").Short('p').Default("30m").Duration()
bucketExistsCache = app.Flag("bucket-exists-cache", "How long the provider caches bucket exists result").Short('c').Default("5s").Duration()
reconcileConcurrency = app.Flag("reconcile-concurrency", "Set number of reconciliation loops.").Default("100").Int()
maxReconcileRate = app.Flag("max-reconcile-rate", "The global maximum rate per second at which resources may checked for drift from the desired state.").Default("1000").Int()
reconcileTimeout = app.Flag("reconcile-timeout", "Object reconciliation timeout").Short('t').Default("3s").Duration()
s3Timeout = app.Flag("s3-timeout", "S3 API operations timeout").Default("10s").Duration()
creationGracePeriod = app.Flag("creation-grace-period", "Duration to wait for the external API to report that a newly created external resource exists.").Default("10s").Duration()
tracesEnabled = app.Flag("otel-enable-tracing", "").Default("false").Bool()
tracesExportTimeout = app.Flag("otel-traces-export-timeout", "Timeout when exporting traces").Default("2s").Duration()
tracesExportInterval = app.Flag("otel-traces-export-interval", "Interval at which traces are exported").Default("5s").Duration()
tracesExportAddress = app.Flag("otel-traces-export-address", "Address of otel collector").Default("opentelemetry-collector.opentelemetry:4317").String()
syncInterval = app.Flag("sync", "How often all resources will be double-checked for drift from the desired state.").Short('s').Default("1h").Duration()
syncTimeout = app.Flag("sync-timeout", "Cache sync timeout.").Default("10s").Duration()
pollInterval = app.Flag("poll", "How often individual resources will be checked for drift from the desired state").Short('p').Default("30m").Duration()
pollStateMetricInterval = app.Flag("poll-state-metric", "State metric recording interval").Default("5s").Duration()
bucketExistsCache = app.Flag("bucket-exists-cache", "How long the provider caches bucket exists result").Short('c').Default("5s").Duration()
reconcileConcurrency = app.Flag("reconcile-concurrency", "Set number of reconciliation loops.").Default("100").Int()
maxReconcileRate = app.Flag("max-reconcile-rate", "The global maximum rate per second at which resources may checked for drift from the desired state.").Default("1000").Int()
reconcileTimeout = app.Flag("reconcile-timeout", "Object reconciliation timeout").Short('t').Default("3s").Duration()
s3Timeout = app.Flag("s3-timeout", "S3 API operations timeout").Default("10s").Duration()
creationGracePeriod = app.Flag("creation-grace-period", "Duration to wait for the external API to report that a newly created external resource exists.").Default("10s").Duration()
tracesEnabled = app.Flag("otel-enable-tracing", "").Default("false").Bool()
tracesExportTimeout = app.Flag("otel-traces-export-timeout", "Timeout when exporting traces").Default("2s").Duration()
tracesExportInterval = app.Flag("otel-traces-export-interval", "Interval at which traces are exported").Default("5s").Duration()
tracesExportAddress = app.Flag("otel-traces-export-address", "Address of otel collector").Default("opentelemetry-collector.opentelemetry:4317").String()

kubeClientRate = app.Flag("kube-client-rate", "The global maximum rate per second at how many requests the client can do.").Default("1000").Int()

Expand Down Expand Up @@ -217,6 +221,18 @@ func main() {
httpClient.Transport = otelhttp.NewTransport(httpClient.Transport)
httpClient.Timeout = *syncTimeout

mm := managed.NewMRMetricRecorder()
sm := statemetrics.NewMRStateMetrics()

metrics.Registry.MustRegister(mm)
metrics.Registry.MustRegister(sm)

mo := controller.MetricOptions{
PollStateMetricInterval: *pollStateMetricInterval,
MRMetrics: mm,
MRStateMetrics: sm,
}

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
LeaderElection: *leaderElection,
LeaderElectionID: "crossplane-leader-election-provider-ceph-ibyaiby",
Expand Down Expand Up @@ -251,6 +267,7 @@ func main() {
PollInterval: *pollInterval,
GlobalRateLimiter: ratelimiter.NewGlobal(*maxReconcileRate),
Features: &feature.Flags{},
MetricOptions: &mo,
}

if *enableExternalSecretStores {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.51.1
github.com/aws/aws-sdk-go-v2/service/sts v1.28.1
github.com/aws/smithy-go v1.20.1
github.com/crossplane/crossplane-runtime v1.15.1
github.com/crossplane/crossplane-runtime v1.16.0
github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79
github.com/google/go-cmp v0.6.0
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -52,6 +52,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.20.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dave/jennifer v1.7.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw=
github.com/aws/smithy-go v1.20.1/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crossplane/crossplane-runtime v1.15.1 h1:g1h75tNYOQT152IUNxs8ZgSsRFQKrZN9z69KefMujXs=
github.com/crossplane/crossplane-runtime v1.15.1/go.mod h1:kRcJjJQmBFrR2n/KhwL8wYS7xNfq3D8eK4JliEScOHI=
github.com/crossplane/crossplane-runtime v1.16.0 h1:lz+l0wEB3qowdTmN7t0PZkfuNSvfOoEhQrEYFbYqMow=
github.com/crossplane/crossplane-runtime v1.16.0/go.mod h1:Pz2tdGVMF6KDGzHZOkvKro0nKc8EzK0sb/nSA7pH4Dc=
github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79 h1:HigXs5tEQxWz0fcj8hzbU2UAZgEM7wPe0XRFOsrtF8Y=
github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79/go.mod h1:+e4OaFlOcmr0JvINHl/yvEYBrZawzTgj6pQumOH1SS0=
github.com/dave/jennifer v1.7.0 h1:uRbSBH9UTS64yXbh4FrMHfgfY762RD+C7bUPKODpSJE=
Expand Down
6 changes: 6 additions & 0 deletions internal/controller/bucket/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/ratelimiter"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/crossplane/crossplane-runtime/pkg/statemetrics"

"github.com/linode/provider-ceph/apis/provider-ceph/v1alpha1"
apisv1alpha1 "github.com/linode/provider-ceph/apis/v1alpha1"
Expand Down Expand Up @@ -64,6 +65,11 @@ func Setup(mgr ctrl.Manager, o controller.Options, c *Connector) error {
opts = append(opts, managed.WithManagementPolicies())
}

if err := mgr.Add(statemetrics.NewMRStateRecorder(
mgr.GetClient(), o.Logger, o.MetricOptions.MRStateMetrics, &v1alpha1.BucketList{}, o.MetricOptions.PollStateMetricInterval)); err != nil {
return err
}

r := managed.NewReconciler(mgr, resource.ManagedKind(v1alpha1.BucketGroupVersionKind), opts...)

return ctrl.NewControllerManagedBy(mgr).
Expand Down
7 changes: 7 additions & 0 deletions package/crds/ceph.crossplane.io_providerconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ spec:
A Message containing details about this condition's last transition from
one status to another, if any.
type: string
observedGeneration:
description: |-
ObservedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
type: integer
reason:
description: A Reason for this condition's last transition from
one status to another.
Expand Down
7 changes: 7 additions & 0 deletions package/crds/ceph.crossplane.io_storeconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ spec:
A Message containing details about this condition's last transition from
one status to another, if any.
type: string
observedGeneration:
description: |-
ObservedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
type: integer
reason:
description: A Reason for this condition's last transition from
one status to another.
Expand Down
28 changes: 28 additions & 0 deletions package/crds/provider-ceph.ceph.crossplane.io_buckets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,13 @@ spec:
A Message containing details about this condition's last transition from
one status to another, if any.
type: string
observedGeneration:
description: |-
ObservedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
type: integer
reason:
description: A Reason for this condition's last transition
from one status to another.
Expand Down Expand Up @@ -724,6 +731,13 @@ spec:
A Message containing details about this condition's last transition from
one status to another, if any.
type: string
observedGeneration:
description: |-
ObservedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
type: integer
reason:
description: A Reason for this condition's last transition
from one status to another.
Expand Down Expand Up @@ -770,6 +784,13 @@ spec:
A Message containing details about this condition's last transition from
one status to another, if any.
type: string
observedGeneration:
description: |-
ObservedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
type: integer
reason:
description: A Reason for this condition's last transition from
one status to another.
Expand All @@ -793,6 +814,13 @@ spec:
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
observedGeneration:
description: |-
ObservedGeneration is the latest metadata.generation
which resulted in either a ready state, or stalled due to error
it can not recover from without human intervention.
format: int64
type: integer
type: object
required:
- spec
Expand Down

0 comments on commit 414fbe1

Please sign in to comment.