Skip to content
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

Conversation

nocturnalastro
Copy link
Contributor

No description provided.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 24, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jun 24, 2024

@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.

@nocturnalastro
Copy link
Contributor Author

/cc @pixelsoccupied @AlinaSecret

Copy link

openshift-ci bot commented Jun 24, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from nocturnalastro. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -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.")
Copy link
Contributor

@pixelsoccupied pixelsoccupied Jun 24, 2024

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)

Copy link
Contributor

@AlinaSecret AlinaSecret left a 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)
Copy link
Contributor

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.
Copy link
Contributor

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:

  1. the external docs link on the patches
  2. basic example on modify of the patch file
    an example use ,
  3. explanation about the format

@@ -114,6 +115,9 @@ type Options struct {
diffAll bool
ShowManagedFields bool
OutputFormat string
PatchesSavePath string
Copy link
Contributor

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)
Copy link
Contributor

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()
Copy link
Contributor

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)

Copy link
Contributor Author

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) {
Copy link
Contributor

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 {
Copy link
Contributor

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) {
Copy link
Contributor

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

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2024
@openshift-merge-robot
Copy link

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.

@nocturnalastro
Copy link
Contributor Author

/hold
while discuss the design

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 28, 2024
Copy link

openshift-ci bot commented Jul 18, 2024

@nocturnalastro: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/modtidy ebb2305 link true /test modtidy
ci/prow/unit-report-creator ebb2305 link true /test unit-report-creator
ci/prow/images ebb2305 link true /test images

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.

@nocturnalastro
Copy link
Contributor Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants