Skip to content

Commit

Permalink
feat: change logs - break apart GVK type field into distinct api_vers…
Browse files Browse the repository at this point in the history
…ion and kind fields

Signed-off-by: Jared Watts <[email protected]>
  • Loading branch information
jbw976 committed Aug 7, 2024
1 parent afb1c6b commit 874a4a4
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 78 deletions.
137 changes: 74 additions & 63 deletions apis/changelogs/proto/v1alpha1/changelog.pb.go

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

21 changes: 12 additions & 9 deletions apis/changelogs/proto/v1alpha1/changelog.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,40 @@ message SendChangeLogRequest {
ChangeLogEntry entry = 1;
}

// ChangeLog represents a single change log entry, with detailed information
// ChangeLogEntry represents a single change log entry, with detailed information
// about the resource that was changed.
message ChangeLogEntry {
// The name and version of the provider that is making the change to the
// resource.
string provider = 1;

// The type of the resource that was changed, e.g. Group, Version, Kind.
string type = 2;
// The API version of the resource that was changed, e.g. Group/Version.
string api_version = 2;

// The kind of the resource that was changed.
string kind = 3;

// The name of the resource that was changed.
string name = 3;
string name = 4;

// The external name of the resource that was changed.
string external_name = 4;
string external_name = 5;

// The type of operation that was performed on the resource, e.g. Create,
// Update, or Delete.
OperationType operation = 5;
OperationType operation = 6;

// A full snapshot of the resource's state, as observed directly before the
// resource was changed.
google.protobuf.Struct snapshot = 6;
google.protobuf.Struct snapshot = 7;

// An optional error message that describes any error encountered while
// performing the operation on the resource.
optional string error_message = 7;
optional string error_message = 8;

// An optional additional details that can be provided for further context
// about the change.
map<string, string> additional_details = 8;
map<string, string> additional_details = 9;
}

// OperationType represents the type of operation that was performed on a
Expand Down
5 changes: 4 additions & 1 deletion pkg/reconciler/managed/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1329,11 +1329,14 @@ func (r *Reconciler) recordChangeLog(ctx context.Context, managed resource.Manag
changeErrMessage = reference.ToPtrValue(changeErr.Error())
}

gvk := managed.GetObjectKind().GroupVersionKind()

// send everything we've got to the change log service
cle := &changelogs.SendChangeLogRequest{
Entry: &changelogs.ChangeLogEntry{
Provider: r.providerVersion,
Type: managed.GetObjectKind().GroupVersionKind().String(),
ApiVersion: gvk.GroupVersion().String(),
Kind: gvk.Kind,
Name: namespacedName,
ExternalName: meta.GetExternalName(managed),
Operation: opType,
Expand Down
12 changes: 7 additions & 5 deletions pkg/reconciler/managed/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,8 @@ func TestRecordChangeLog(t *testing.T) {
{
Entry: &changelogs.ChangeLogEntry{
Provider: "provider-cool:v9.99.999",
Type: (&fake.Managed{}).GetObjectKind().GroupVersionKind().String(),
ApiVersion: (&fake.Managed{}).GetObjectKind().GroupVersionKind().GroupVersion().String(),
Kind: (&fake.Managed{}).GetObjectKind().GroupVersionKind().Kind,
Name: "cool-managed",
ExternalName: "cool-managed",
Operation: changelogs.OperationType_OPERATION_TYPE_CREATE,
Expand Down Expand Up @@ -2772,10 +2773,11 @@ func TestRecordChangeLog(t *testing.T) {
// entry because we're not initializing the managed
// resource with much data in this simulated failure
// test case
Provider: "provider-cool:v9.99.999",
Type: (&fake.Managed{}).GetObjectKind().GroupVersionKind().String(),
Operation: changelogs.OperationType_OPERATION_TYPE_CREATE,
Snapshot: mustObjectAsProtobufStruct(&fake.Managed{}),
Provider: "provider-cool:v9.99.999",
ApiVersion: (&fake.Managed{}).GetObjectKind().GroupVersionKind().GroupVersion().String(),
Kind: (&fake.Managed{}).GetObjectKind().GroupVersionKind().Kind,
Operation: changelogs.OperationType_OPERATION_TYPE_CREATE,
Snapshot: mustObjectAsProtobufStruct(&fake.Managed{}),
},
},
},
Expand Down

0 comments on commit 874a4a4

Please sign in to comment.