-
Notifications
You must be signed in to change notification settings - Fork 9
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
CNF-11871: Add abiltiy to save patches and load them as acceptable diffs #45
CNF-11871: Add abiltiy to save patches and load them as acceptable diffs #45
Conversation
@nocturnalastro: This pull request references CNF-11871 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.17.0" version, but no target version was set. In response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -173,6 +177,10 @@ func NewCmd(f kcmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Comma | |||
"In local mode will try to match all resources passed to the command") | |||
|
|||
cmd.Flags().StringVarP(&options.OutputFormat, "output", "o", "", fmt.Sprintf(`Output format. One of: (%s)`, strings.Join(OutputFormats, ", "))) | |||
|
|||
cmd.Flags().StringVarP(&options.PatchesSavePath, "patches-save-path", "p", "", "Path file where patches should be saved.") |
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.
Readme with an exmaple use case please!
So this cover what Dave was asking yeah? Giving customer to silence diffs overtime? (explanation of this would be nice under PR description/or README)
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 think its enough for this review, still have some more comments about the tests but they may change according to the other comments so didn't add them for now
return err | ||
} | ||
} else { | ||
o.patches = make(map[string][]string) |
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.
no need for the if and else clause:
o.patches = make(map[string][]string)
if o.PatchesLoadPath != "" {
o.patches, err = getPatches(o.PatchesLoadPath)
if err != nil {
return err
}
}
@@ -324,6 +324,18 @@ correlationSettings: | |||
|
|||
``` | |||
|
|||
#### Acceptable diffs | |||
|
|||
It is possible save a set of diffs as patches. These can then be passed back into the tools as a set of acceptable diffs. |
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.
it is important that the user can set the known diffs, and not only be able to take all of the diffs and then use all of them as a patch, the user may would want only part of it.
the format of the patch is part of the api of the tool, the user need the ability to modify it by hand or at least some documentation about the format how it works. especially that the patches are wrapped by a mapping
i would add:
- the external docs link on the patches
- basic example on modify of the patch file
an example use , - explanation about the format
@@ -114,6 +115,9 @@ type Options struct { | |||
diffAll bool | |||
ShowManagedFields bool | |||
OutputFormat string | |||
PatchesSavePath string |
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.
why do we need a save path and a load path?
i think instead you can have only a patch file and a re save flag (or better name)
because anyway if someone is using the load ad the save at the same time, the new patch will contain all of the patches specified in the loaded one.
what do you think? anyway i think that its not clear enough in the docs what happens if you use both of the save and load at the same time
|
||
patch, err := obj.getPatch() | ||
if err != nil { | ||
klog.Error(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.
as we discussed in a different pr context move to ignore errors
@@ -518,11 +583,41 @@ func (obj InfoObject) Name() string { | |||
return slug.Make(apiKindNamespaceName(obj.clusterObj)) | |||
} | |||
|
|||
func (obj InfoObject) getPatch() (string, error) { | |||
localRuntime, err := obj.Merged() |
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 am not sure if the patch should created from the version that already contains the patched version (like still not sure about the case if there is a load and save patch at the same time what will each of them include)
i would of expect here to use the object only with the ommited fields (without the load patch)
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.
Yeah good point now that the other PR is merged I'll have to update this one :)
@@ -624,3 +719,20 @@ func (o Output) Print(format string, out io.Writer) (int, error) { | |||
} | |||
return n, nil | |||
} | |||
|
|||
func (o Output) PrintPatches(out io.Writer) (int, 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.
i think its better to create a separate object for the patches, where has both the load function and the print functions. no need to use the ouptput that contains final output of the tool or the diff sum.
also because the patch file extends the api of the command, i think its better that is format is located in one place.
the code is a little to much divided between multiple places, that can make it hard to change and its harder to review.
so i suggest on creating a struct called PatchFile that has list/map of the patchsave object (that can be just patch)
the patch file object can contain the print function (i would call it export instead or save), and also a load function. even put all of the patch functions in a different file
@@ -455,26 +472,49 @@ func (o *Options) Run() error { | |||
clusterObj: &clusterCR, | |||
FieldsToOmit: o.ref.FieldsToOmit, | |||
} | |||
crName := apiKindNamespaceName(&clusterCR) | |||
if patches, ok := o.patches[crName]; ok { |
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.
why are the patches mapped by a specific CR, instead of the corresponding reference.
it can be more stable to changes in the CRS name-namespace-apiversion-kind. and its logical that you would like to supresss a diff because of a field in the ref.
}() | ||
cmd.Run(cmd, []string{}) | ||
} | ||
|
||
// TestCompareRun ensures that Run command calls the right actions | ||
// and returns the expected error. | ||
func TestCompareRun(t *testing.T) { |
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.
please add a test that gets as input the patch file (that is saved in the tests directory) and tests that the diff is supressed, and same for the save option.
because the patch file is part of the api it should be fully tested as a separate file
also it will be super helpful for the review too see examples of the patch file
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/hold |
@nocturnalastro: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
@AlinaSecret @pixelsoccupied Closing this one for now. I'll open up a new once once we've agreed on the design with the new implementation. |
No description provided.