-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ECS] Support Plan Preview for ECS #4881
Conversation
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4881 +/- ##
==========================================
+ Coverage 29.23% 29.30% +0.07%
==========================================
Files 318 321 +3
Lines 40591 40835 +244
==========================================
+ Hits 11868 11968 +100
- Misses 27784 27910 +126
- Partials 939 957 +18 ☔ View full report in Codecov by Sentry. |
pkg/diff/diffbycommand.go
Outdated
// DiffBytesByCommand runs the command to compare the given bytes. | ||
func DiffBytesByCommand(command string, oldBytes, newBytes []byte) ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of separate this function from DiffByCommand
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed to merge DiffBytesByCommand()
into DiffByCommand()
.
I used DiffBytesByCommand()
from outside in previous commits, but it is not used now.
pkg/diff/diff.go
Outdated
@@ -97,6 +98,42 @@ func DiffUnstructureds(x, y unstructured.Unstructured, key string, opts ...Optio | |||
return d.result, nil | |||
} | |||
|
|||
// DiffStructs calulates the diff between two struct objects, | |||
// which are not k8s manifests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can imagine this related to this line in your PR description.
Including Diff() func, which compares manifests(i.e. serviceDef&taskDef in ECS) for non-k8s resources like Lambda
But it is still hard to imagine when to use DiffUnstructureds
and DiffStructs
. Maybe we need a better name, or we need to add comments that describe these two functions better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we also should rename this to DiffStructureds
either ways 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I also felt the name DiffStructs
was unclear.
First, I renamed it to DiffStructureds
.
Second, I added comments about which func to use in both DiffUnstructureds
and DiffStructureds
.
commit: 77dcef7
pkg/diff/diff.go
Outdated
opt(d) | ||
} | ||
|
||
d.initIgnoredPaths(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this would work? 🤔 Or could you introduce the possible key for this? Since this key in case of k8s manifests could look like this https://pipecd.dev/docs-v0.47.x/user-guide/managing-application/configuration-drift-detection/#ignore-drift-detection-for-specific-fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, you're right.
It did not work, so I deleted them in dd40abb
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
@khanhtc1202 Thank you for your reviewing, I fixed 3 points. |
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
@khanhtc1202
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the great work! I left some nit and imo comment!
pkg/app/piped/planpreview/ecsdiff.go
Outdated
summary := fmt.Sprintf("%d changes were detected", len(result.Diff.Nodes())) | ||
details := result.Render(provider.DiffRenderOptions{ | ||
UseDiffCommand: true, | ||
}) | ||
fmt.Fprintf(buf, "--- Last Deploy\n+++ Head Commit\n\n%s\n", details) | ||
|
||
return &diffResult{ | ||
summary: summary, | ||
}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] maybe be able to reduce the variable
summary := fmt.Sprintf("%d changes were detected", len(result.Diff.Nodes())) | |
details := result.Render(provider.DiffRenderOptions{ | |
UseDiffCommand: true, | |
}) | |
fmt.Fprintf(buf, "--- Last Deploy\n+++ Head Commit\n\n%s\n", details) | |
return &diffResult{ | |
summary: summary, | |
}, nil | |
details := result.Render(provider.DiffRenderOptions{ | |
UseDiffCommand: true, | |
}) | |
fmt.Fprintf(buf, "--- Last Deploy\n+++ Head Commit\n\n%s\n", details) | |
return &diffResult{ | |
summary: fmt.Sprintf("%d changes were detected", len(result.Diff.Nodes())), | |
}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I fixed
func diffByCommand(command string, old, new ECSManifests) ([]byte, error) { | ||
taskDiff, err := diff.DiffByCommand(command, old.TaskDefinition, new.TaskDefinition) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
serviceDiff, err := diff.DiffByCommand(command, old.ServiceDefinition, new.ServiceDefinition) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return bytes.Join([][]byte{ | ||
[]byte("# 1. ServiceDefinition"), | ||
serviceDiff, | ||
[]byte("\n# 2. TaskDefinition"), | ||
taskDiff, | ||
}, []byte("\n")), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[IMO]
It would be better to define it as renderByCommand
.
I feel the responsibility of the method is to render the diffResult
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I fixed it. 0cb5d29
renderByCommand
is better especially because this func contains the following code.
return bytes.Join([][]byte{
[]byte("# 1. ServiceDefinition"),
serviceDiff,
[]byte("\n# 2. TaskDefinition"),
taskDiff,
}, []byte("\n")), nil
pkg/diff/diffbycommand.go
Outdated
// DiffByCommand converts the given objects into yaml and then runs the command to compare them. | ||
func DiffByCommand(command string, old, new interface{}) ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[IMO]
It would be better to define it as renderByCommand.
I feel the responsibility of the method is to render the diffResult.
Similar to the reason above, how about renaming it as RenderByCommand
and moving it in the render.go
like below↓?
https://github.com/pipe-cd/pipecd/blob/master/pkg/diff/renderer.go#L54
I think the DiffXX methods in the diff pkg return diff.Result
and have the responsibility to extract the differences. It is ideal to unify the interface and the responsivility as much as possible.
WDYT? I want your opinion @t-kikuc @khanhtc1202
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ffjlabo
Thanks, I agree with you.
TBH, when I referred to CloudRun's diff.go, I thought it was confusing and should be renamed and moved.
cf. https://github.com/pipe-cd/pipecd/blob/master/pkg/app/piped/platformprovider/cloudrun/diff.go
pkg/diff/diffbycommand.go
Outdated
func DiffByCommand(command string, old, new interface{}) ([]byte, error) { | ||
oldBytes, err := yaml.Marshal(old) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Check whether the command exists or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I fixed it. c9764e4
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
…into ecs-plan-preview Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@t-kikuc thanks! added one nit comment for test! I'll approve after the fix :)
pkg/diff/renderer_test.go
Outdated
if tc.expectErr { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]
if tc.expectErr { | |
assert.Error(t, err) | |
} else { | |
assert.NoError(t, err) | |
} | |
assert.Equal(t, tc.expectErr, err != nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
…into ecs-plan-preview Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, can't wait to see this on prod 🚀
What this PR does / why we need it:
Diff()
func, which compares manifests(i.e. serviceDef&taskDef in ECS) for non-k8s resources like LambdaWhich issue(s) this PR fixes:
Fixes #4870
Does this PR introduce a user-facing change?: no
How it works:
Plan Preview is a feature for visualizing model-level diff, not file-level diff(
Files Changed
on GitHub covers it).So we can ignore following points in the output:
e.g.
image
in taskdef.yaml ->Image
in planpreview resulte.g.
EnableExecuteCommand
is shown above but I did not specify it.