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

add snapshot commands #95

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rinaldodev
Copy link

No description provided.

updateChannel.NewUpdateChannelCommand(f))
updateChannel.NewUpdateChannelCommand(f),
snapshot.NewSnapshotCommand(f),
validateSnapshot.NewValidateSnapshotCommand(f))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no strong opinion but that be split in 2 snapshot subcommands:

rhoc deployment snapshot create
rhoc deployment snapshot validate

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

},
}

cmdutil.AddClusterAmount(cmd, &opts.clusterAmount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe there should be a way to define for which cluster you want to get the snapshot ? my understading is that you can define a number of cluster for which you want a snapshot but that would be unreliable

Copy link
Author

@rinaldodev rinaldodev Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reasoning was querying for X clusters with status=ready and sorted by age.
Right now I'd rather change the validation mechanism to parse the CSV and query for the same clusters afterwards, as to prevent that from happening.

adding the option to set specific clusters is a valid option and can also be done, but right now I just wanted something more straightforward than figuring out know which are the "important clusters" beforehand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's would be fine, main reason was about the consistency between the save and validate

},
}

cmdutil.AddClusterAmount(cmd, &opts.clusterAmount)
Copy link
Contributor

@lburgazzoli lburgazzoli Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using numbers may be unreliable i.e. the list cluster may return a different order between snapshot creation and snapshot analysis.

if opts.clusterAmount < 1 || opts.clusterAmount > 30 {
return errors.New("clusterAmount must be between 1 and 30")
}
if opts.inputFile == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can mark flags as required instead of having to explicit validate them

const (
CommandName = "snapshot"
CommandAlias = "ss"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why declaring a constant for this package that is only used once, we could as well directly do:

	cmd := &cobra.Command{
		Short:   "Takes a snapshot of deployments in oldest and ready clusters.",
		Use:      "snapshot",

In case there is a valid reason, why make it public when it is never accessed from outside the package.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could change it, but that pattern is followed by basically all of the commands.
I don't know what is the reason behind that pattern being used. @lburgazzoli?

If there is no reason behind it, I can change it if we don't mind it being the different one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we took this commands originally from rhoas and that was the pattern as I recall it was used also outside the package.

we can do whatever make sense for us.

Copy link
Contributor

@lgarciaaco lgarciaaco Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only point I can see having it this way is that you get a good idea about what the package is doing by looking at the top of the file, but even for that purpose there are better ways.

I am just challenging some ideas I know we have been dragging from kas, no strong position whatsoever.

return cmd
}

func run(opts *options) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a pointer here? I think implementing this function by value achieve the same goal

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha ... I've noticed from kas they tend to use pointers everywhere. Imho pointers are a tool in a wide toolset and should not be used just because it is available. The default approach should be to use value implementation instead of reference.

I know it is a copy and paste issue and I am bringing this up to discussion because I saw it earlier this week, sorry for using your PR as a platform :-)

return runComparison(opts.f.IOStreams.Out, opts.inputFile, buffer)
}

func runComparison(out io.Writer, inputFile string, newSnapshot io.Reader) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only food for thoughts.

I wonder if reading the files into bytes and using bytes.Compare is a better solution.

You could also read the files content, md5 it and compare the two hashes.

None of these proposals can show the diff of the files, but it is a trade of I guess

Copy link
Author

@rinaldodev rinaldodev Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to change that code considerably, but keeping the diff is a must. The reason is that we want to run that command before and after a deploy as to make sure it didn't break anything, and if it does break, we need to know what it was.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then your probably want to keep it as it is right now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rinaldodev I converted this to a draft to reflect the fact that there will be some refactoring

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@lburgazzoli lburgazzoli marked this pull request as draft November 24, 2022 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants