Skip to content

Commit b53779e

Browse files
committed
* Bump up crossplane-runtime to v1.18.0
* Fix linting issue by bumping up build submodules to latest one * Add support for logs that introduced in v1.17.0 * Add support for metrics that introduced in v1.16.0 * Update Delete function that required changes in v1.17.0 * Bump up go version to 1.22 Signed-off-by: Chuan-Yen Chiang <[email protected]>
1 parent 2e0b022 commit b53779e

20 files changed

+285
-297
lines changed

.github/workflows/ci.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ on:
1010

1111
env:
1212
# Common versions
13-
GO_VERSION: '1.21'
14-
GOLANGCI_VERSION: 'v1.54.0'
13+
GO_VERSION: '1.22'
14+
GOLANGCI_VERSION: 'v1.62.2'
1515
DOCKER_BUILDX_VERSION: 'v0.9.1'
1616

1717
# Common users. We can't run a step 'if secrets.XXX != ""' but we can run a
@@ -74,6 +74,8 @@ jobs:
7474
# 'annotations' (i.e. it comments on PRs to point out linter violations).
7575
- name: Lint
7676
uses: golangci/golangci-lint-action@v3
77+
args:
78+
- --out-format=colored-line-number
7779
with:
7880
version: ${{ env.GOLANGCI_VERSION }}
7981

.golangci.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
run:
22
deadline: 2m
33

4-
skip-files:
5-
- "zz_generated\\..+\\.go$"
6-
74
output:
85
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
9-
format: colored-line-number
6+
formats: colored-line-number
107

118
linters-settings:
129
errcheck:
@@ -21,7 +18,8 @@ linters-settings:
2118
# [deprecated] comma-separated list of pairs of the form pkg:regex
2219
# the regex is used to ignore names within pkg. (default "fmt:.*").
2320
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
24-
ignore: fmt:.*,io/ioutil:^Read.*
21+
exclude-functions:
22+
- fmt:.*,io/ioutil:^Read.*
2523

2624
govet:
2725
# report about shadowed variables
@@ -104,7 +102,6 @@ linters-settings:
104102

105103
linters:
106104
enable:
107-
- megacheck
108105
- govet
109106
- gocyclo
110107
- gocritic
@@ -115,6 +112,9 @@ linters:
115112
- unconvert
116113
- misspell
117114
- nakedret
115+
- gosimple
116+
- staticcheck
117+
- unused
118118

119119
presets:
120120
- bugs
@@ -123,6 +123,9 @@ linters:
123123

124124

125125
issues:
126+
# Excluding files
127+
exclude-files:
128+
- "zz_generated\\..+\\.go$"
126129
# Excluding configuration per-path and per-linter
127130
exclude-rules:
128131
# Exclude some linters from running on tests files.

apis/sample/v1alpha1/zz_generated.deepcopy.go

+3-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/sample/v1alpha1/zz_generated.managed.go

+3-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/sample/v1alpha1/zz_generated.managedlist.go

+3-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.deepcopy.go

+3-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.pc.go

+3-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.pcu.go

+3-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.pculist.go

+3-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/provider/main.go

+45-4
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,35 @@ package main
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"os"
2223
"path/filepath"
2324
"time"
2425

26+
"google.golang.org/grpc"
27+
"google.golang.org/grpc/credentials/insecure"
28+
29+
"github.com/crossplane/provider-template/internal/version"
30+
2531
"gopkg.in/alecthomas/kingpin.v2"
2632
kerrors "k8s.io/apimachinery/pkg/api/errors"
2733
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2834
"k8s.io/client-go/tools/leaderelection/resourcelock"
2935
ctrl "sigs.k8s.io/controller-runtime"
3036
"sigs.k8s.io/controller-runtime/pkg/cache"
3137
"sigs.k8s.io/controller-runtime/pkg/log/zap"
38+
"sigs.k8s.io/controller-runtime/pkg/metrics"
3239

3340
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
3441
"github.com/crossplane/crossplane-runtime/pkg/controller"
3542
"github.com/crossplane/crossplane-runtime/pkg/feature"
3643
"github.com/crossplane/crossplane-runtime/pkg/logging"
3744
"github.com/crossplane/crossplane-runtime/pkg/ratelimiter"
45+
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
3846
"github.com/crossplane/crossplane-runtime/pkg/resource"
47+
"github.com/crossplane/crossplane-runtime/pkg/statemetrics"
48+
49+
changelogsv1alpha1 "github.com/crossplane/crossplane-runtime/apis/changelogs/proto/v1alpha1"
3950

4051
"github.com/crossplane/provider-template/apis"
4152
"github.com/crossplane/provider-template/apis/v1alpha1"
@@ -47,15 +58,18 @@ func main() {
4758
var (
4859
app = kingpin.New(filepath.Base(os.Args[0]), "Template support for Crossplane.").DefaultEnvars()
4960
debug = app.Flag("debug", "Run with debug logging.").Short('d').Bool()
50-
leaderElection = app.Flag("leader-election", "Use leader election for the controller manager.").Short('l').Default("false").OverrideDefaultFromEnvar("LEADER_ELECTION").Bool()
61+
leaderElection = app.Flag("leader-election", "Use leader election for the controller manager.").Short('l').Default("false").Envar("LEADER_ELECTION").Bool()
62+
63+
syncInterval = app.Flag("sync", "How often all resources will be double-checked for drift from the desired state.").Short('s').Default("1h").Duration()
64+
pollInterval = app.Flag("poll", "How often individual resources will be checked for drift from the desired state").Default("1m").Duration()
65+
pollStateMetricInterval = app.Flag("poll-state-metric", "State metric recording interval").Default("5s").Duration()
5166

52-
syncInterval = app.Flag("sync", "How often all resources will be double-checked for drift from the desired state.").Short('s').Default("1h").Duration()
53-
pollInterval = app.Flag("poll", "How often individual resources will be checked for drift from the desired state").Default("1m").Duration()
5467
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()
5568

5669
namespace = app.Flag("namespace", "Namespace used to set as default scope in default secret store config.").Default("crossplane-system").Envar("POD_NAMESPACE").String()
5770
enableExternalSecretStores = app.Flag("enable-external-secret-stores", "Enable support for ExternalSecretStores.").Default("false").Envar("ENABLE_EXTERNAL_SECRET_STORES").Bool()
5871
enableManagementPolicies = app.Flag("enable-management-policies", "Enable support for Management Policies.").Default("false").Envar("ENABLE_MANAGEMENT_POLICIES").Bool()
72+
enableChangeLogs = app.Flag("enable-change-logs", "Enable support for capturing change logs during reconciliation.").Default("false").Envar("ENABLE_CHANGE_LOGS").Bool()
5973
)
6074
kingpin.MustParse(app.Parse(os.Args[1:]))
6175

@@ -80,7 +94,7 @@ func main() {
8094

8195
// controller-runtime uses both ConfigMaps and Leases for leader
8296
// election by default. Leases expire after 15 seconds, with a
83-
// 10 second renewal deadline. We've observed leader loss due to
97+
// 10 seconds renewal deadline. We've observed leader loss due to
8498
// renewal deadlines being exceeded when under high load - i.e.
8599
// hundreds of reconciles per second and ~200rps to the API
86100
// server. Switching to Leases only and longer leases appears to
@@ -94,12 +108,23 @@ func main() {
94108
kingpin.FatalIfError(err, "Cannot create controller manager")
95109
kingpin.FatalIfError(apis.AddToScheme(mgr.GetScheme()), "Cannot add Template APIs to scheme")
96110

111+
metricRecorder := managed.NewMRMetricRecorder()
112+
stateMetrics := statemetrics.NewMRStateMetrics()
113+
114+
metrics.Registry.MustRegister(metricRecorder)
115+
metrics.Registry.MustRegister(stateMetrics)
116+
97117
o := controller.Options{
98118
Logger: log,
99119
MaxConcurrentReconciles: *maxReconcileRate,
100120
PollInterval: *pollInterval,
101121
GlobalRateLimiter: ratelimiter.NewGlobal(*maxReconcileRate),
102122
Features: &feature.Flags{},
123+
MetricOptions: &controller.MetricOptions{
124+
PollStateMetricInterval: *pollStateMetricInterval,
125+
MRMetrics: metricRecorder,
126+
MRStateMetrics: stateMetrics,
127+
},
103128
}
104129

105130
if *enableExternalSecretStores {
@@ -126,6 +151,22 @@ func main() {
126151
log.Info("Alpha feature enabled", "flag", features.EnableAlphaManagementPolicies)
127152
}
128153

154+
if *enableChangeLogs {
155+
o.Features.Enable(feature.EnableAlphaChangeLogs)
156+
log.Info("Alpha feature enabled", "flag", feature.EnableAlphaChangeLogs)
157+
socketPath := "/var/run/change-logs/change-logs.sock"
158+
159+
conn, err := grpc.NewClient("unix://"+socketPath, grpc.WithTransportCredentials(insecure.NewCredentials()))
160+
kingpin.FatalIfError(err, "failed to create change logs client connection")
161+
162+
clo := controller.ChangeLogOptions{
163+
ChangeLogger: managed.NewGRPCChangeLogger(
164+
changelogsv1alpha1.NewChangeLogServiceClient(conn),
165+
managed.WithProviderVersion(fmt.Sprintf("provider-template: %s", version.Version))),
166+
}
167+
o.ChangeLogOptions = &clo
168+
}
169+
129170
kingpin.FatalIfError(template.Setup(mgr, o), "Cannot setup Template controllers")
130171
kingpin.FatalIfError(mgr.Start(ctrl.SetupSignalHandler()), "Cannot start controller manager")
131172
}

0 commit comments

Comments
 (0)