Skip to content

Commit 68de875

Browse files
authored
Merge pull request #118 from cychiang/feat-add-support-for-change-logs
feat: Add change-logs to provider-template, and update templates
2 parents 3cb2ece + 0ccae16 commit 68de875

File tree

14 files changed

+66
-19
lines changed

14 files changed

+66
-19
lines changed

apis/sample/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.pc.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.pcu.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.pculist.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/provider/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ 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"
2528
"gopkg.in/alecthomas/kingpin.v2"
2629
kerrors "k8s.io/apimachinery/pkg/api/errors"
2730
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -31,6 +34,7 @@ import (
3134
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3235
"sigs.k8s.io/controller-runtime/pkg/metrics"
3336

37+
changelogsv1alpha1 "github.com/crossplane/crossplane-runtime/apis/changelogs/proto/v1alpha1"
3438
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
3539
"github.com/crossplane/crossplane-runtime/pkg/controller"
3640
"github.com/crossplane/crossplane-runtime/pkg/feature"
@@ -44,6 +48,7 @@ import (
4448
"github.com/crossplane/provider-template/apis/v1alpha1"
4549
template "github.com/crossplane/provider-template/internal/controller"
4650
"github.com/crossplane/provider-template/internal/features"
51+
"github.com/crossplane/provider-template/internal/version"
4752
)
4853

4954
func main() {
@@ -61,6 +66,8 @@ func main() {
6166
namespace = app.Flag("namespace", "Namespace used to set as default scope in default secret store config.").Default("crossplane-system").Envar("POD_NAMESPACE").String()
6267
enableExternalSecretStores = app.Flag("enable-external-secret-stores", "Enable support for ExternalSecretStores.").Default("false").Envar("ENABLE_EXTERNAL_SECRET_STORES").Bool()
6368
enableManagementPolicies = app.Flag("enable-management-policies", "Enable support for Management Policies.").Default("false").Envar("ENABLE_MANAGEMENT_POLICIES").Bool()
69+
enableChangeLogs = app.Flag("enable-changelogs", "Enable support for capturing change logs during reconciliation.").Default("false").Envar("ENABLE_CHANGE_LOGS").Bool()
70+
changelogsSocketPath = app.Flag("changelogs-socket-path", "Path for changelogs socket (if enabled)").Default("/var/run/changelogs/changelogs.sock").Envar("CHANGELOGS_SOCKET_PATH").String()
6471
)
6572
kingpin.MustParse(app.Parse(os.Args[1:]))
6673

@@ -142,6 +149,21 @@ func main() {
142149
log.Info("Alpha feature enabled", "flag", features.EnableAlphaManagementPolicies)
143150
}
144151

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

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/crossplane/crossplane-tools v0.0.0-20240522174801-1ad3d4c87f21
1010
github.com/google/go-cmp v0.6.0
1111
github.com/pkg/errors v0.9.1
12+
google.golang.org/grpc v1.65.0
1213
gopkg.in/alecthomas/kingpin.v2 v2.2.6
1314
k8s.io/apimachinery v0.31.2
1415
k8s.io/client-go v0.31.2
@@ -77,7 +78,6 @@ require (
7778
golang.org/x/tools v0.26.0 // indirect
7879
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
7980
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
80-
google.golang.org/grpc v1.65.0 // indirect
8181
google.golang.org/protobuf v1.34.2 // indirect
8282
gopkg.in/inf.v0 v0.9.1 // indirect
8383
gopkg.in/yaml.v2 v2.4.0 // indirect

hack/boilerplate.go.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
1+
// SPDX-FileCopyrightText: 2025 The Crossplane Authors <https://crossplane.io>
22
//
33
// SPDX-License-Identifier: Apache-2.0

0 commit comments

Comments
 (0)