-
Notifications
You must be signed in to change notification settings - Fork 220
Commit 425cab5
committed
adds code generation for field comparisons
Adds new code generation functions to `pkg/generate/code` that output Go
code that compares fields of various types and calls `delta.Add()` if a
difference is detected.
For fields with underlying scalar types, the generated code looks like
this:
```go
if *a.ko.Spec.Name != *b.ko.Spec.Name) {
delta.Add("Spec.Name", a.ko.Spec.Name, b.ko.Spec.Name)
}
```
For non-scalar types, generated code recurses over the fields and/or
calls specialized comparison functions in the runtime library's
`pkg/compare` module. Here is an example of a complex underlying field
type and what the generated code might look like:
```go
if ackcompare.HasNilDifference(a.ko.Spec.CreateBucketConfiguration, b.ko.Spec.CreateBucketConfiguration) {
delta.Add("Spec.CreateBucketConfiguration", a.ko.Spec.CreateBucketConfiguration, b.ko.Spec.CreateBucketConfiguration)
} else {
if ackcompare.HasNilDifference(a.ko.Spec.CreateBucketConfiguration.LocationConstraint, b.ko.Spec.CreateBucketConfiguration.LocationConstraint) {
delta.Add("Spec.CreateBucketConfiguration.LocationConstraint", a.ko.Spec.CreateBucketConfiguration.LocationConstraint, b.ko.Spec.CreateBucketConfiguration.LocationConstraint)
} else {
if *a.ko.Spec.CreateBucketConfiguration.LocationConstraint != *b.ko.Spec.CreateBucketConfiguration.LocationConstraint {
delta.Add("Spec.CreateBucketConfiguration.LocationConstraint", a.ko.Spec.CreateBucketConfiguration.LocationConstraint, b.ko.Spec.CreateBucketConfiguration.LocationConstraint)
}
}
}
```1 parent 63ada1d commit 425cab5Copy full SHA for 425cab5
File tree
Expand file treeCollapse file tree
3 files changed
+710
-0
lines changedFilter options
- pkg/generate
- code
- config
Expand file treeCollapse file tree
3 files changed
+710
-0
lines changed
0 commit comments