-
Notifications
You must be signed in to change notification settings - Fork 267
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
feature Implementation: Diff between Revisions #6 #22
Conversation
@databus23 , any update on this..? |
@aananthraj Ah, I'm sorry I'm swamped at work at the moment. I set myself a reminder to take a look at this later today. |
Thanks @databus23, for the prompt response. I have one more feature request and its implementation in a separate branch Thanks, |
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 for working on this! I've gotten similar requests in the past and never got around to tackle this. I'm very much willing to get this in this time.
I would like to discuss my general remark about the command structure before digging deeper into the code as quite a bit will change if we decide to take a different approach.
README.md
Outdated
|
||
Available Commands: | ||
revision Shows diff between revision's manifests | ||
upgrade visualize changes, that a helm upgrade could perform |
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.
Restructring the command in the proposed way would be backward incompatible. I would very much would like to avoid that. Or at minimum find a clever way to alias the old CLI behaviour.
Otherwise this PR will break existing scripts and pipelines where helm is used.
I'm still liking the idea to maintain a single command helm diff [FROM] [TO]
where FROM
and TO
are more generic.
Something like this:
# latest revision with local chart
helm diff RELEASE local-dir/
#latest revision with latest chart from stable
helm diff RELEASE stable/postgresql
#revision 12 with latest revison
helm diff RELEASE@12
#revision 12 with revision 14
helm diff RELEASE@12 @14
What do you think?
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.
Restructring the command in the proposed way would be backward incompatible.
It is an valid point, that we have to discuss. Those changes were proposed for the following reasons
-
To have resemblance with
helm
's usage patterns/generic usage pattern
eg:# diff on upgrade helm upgrade [RELEASE] [CHART] [flags] helm diff upgrade [RELEASE] [CHART] [flags] # diff on rollback (available as a separate pull request #24) helm rollback [flags] [RELEASE] [REVISION] helm diff rollback [flags] [RELEASE] [REVISION] # diff on revision helm diff revision [flags] [RELEASE] REVISION
-
Features can be modular, clean and would be easy add new features.
For instancerollback
In case these points are not appealing, we could work on it.
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.
hi @databus23,
any updates/suggestions on this?
I couldn't understand the below statement
Otherwise this PR will break existing scripts and pipelines where helm is used
could you elaborate so that it will be helpful for me to fix.
Moreover, I couldn't find any breaking scripts and pipelines while installing the plugin. kindly correct me if am wrong.
Thanks
@aananthraj I believe the discussions here might be of help - #34 (comment)
The CLI has been restructured so you can now add revision support if you have time to refactor. |
I had a small problem trying to build it, then I see the new release. So I will wait for the refactor to test it. Sorry, I current have very limited time. |
@sstarcher thanks for update 👍 , was waiting for this..!!! |
Hi @databus23 and @sstarcher , made suitable changes to include subcommands like
opinions..? |
can this be merged..? or still some fixes needed..? |
I would be happy, if we could close this before 27/04/14, beyond which it would be difficult for me to fix issues with this PR, as I am planning for long break. Hope no issues exist. |
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 for the PR. In general this looks good and I would like to accept it. I made some suggestions in how to cleaner separate the commands and maybe remove some duplication.
cmd/revision.go
Outdated
` | ||
|
||
func revisionCmd() *cobra.Command { | ||
diff := diffCmd{} |
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 would prefer if this could use its own struct and not piggy back on the exiting struct. The general Idea would be that every command has its own struct, to store state and functions.
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.
each subcommand is given a client, as off now both has resemblance, but it could change in feature.
# cmd/revision.go
type revision struct {
release string
client helm.Interface
suppressedKinds []string
revisions []string
}
# cmd/rollback.go
type rollback struct {
release string
client helm.Interface
suppressedKinds []string
revisions []string
}
return errors.New("Too many arguments to Command \"revision\".\nMaximum 3 arguments allowed: release name, revision1, revision2") | ||
} | ||
|
||
if q, _ := cmd.Flags().GetBool("suppress-secrets"); q { |
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 can move this to a global flag?
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.
In my point of view, for executing suppress-secrets
as a global pre-run , we might need to have a common diff object across all the subcommands and it must be made available in root.go
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.
opinions on this..? can this be done in some other way..?
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.
Hmm, you are right. Haven't thought of that, maybe leave it as it is for now. I think its more important to have the command cleanly separated. We can deduplicate later.
cmd/revision.go
Outdated
diff.suppressedKinds = append(diff.suppressedKinds, "Secret") | ||
} | ||
|
||
if nc, _ := cmd.Flags().GetBool("no-color"); nc { |
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.
This can be a global flag for sure, that is shared by all sub commands. And have the effect for done in a Pre
function once for all commands.
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.
we could use PersistentPreRunE,
when we add those flag checks PersistentPreRunE in the root command, all its children commands (upgrade,revision,rollback) will inherit and execute.
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 for this flag its a good fit as it just flips a package level var
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.
Works fine for me.., hope this is ok
func New() *cobra.Command {
chartCommand := newChartCommand()
cmd := &cobra.Command{
Use: "diff",
Short: "Show manifest differences",
//Alias root command to chart subcommand
Args: chartCommand.Args,
// parse the flags and check for actions like suppress-secrets, no-colors
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if nc, _ := cmd.Flags().GetBool("no-color"); nc {
ansi.DisableColors(true)
}
},
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Println(`Command "helm diff" is deprecated, use "helm diff upgrade" instead`)
return chartCommand.RunE(cmd, args)
},
}
// add no-color as global flag
cmd.PersistentFlags().Bool("no-color", false, "remove colors from the output")
// add flagset from chartCommand
cmd.Flags().AddFlagSet(chartCommand.Flags())
cmd.AddCommand(newVersionCmd(), chartCommand)
// add subcommands
cmd.AddCommand(
revisionCmd(),
rollbackCmd(),
)
cmd.SetHelpCommand(&cobra.Command{}) // Disable the help command
return cmd
}
plugin.yaml
Outdated
@@ -5,6 +5,6 @@ version: "2.8.2+2" | |||
usage: "Preview helm upgrade changes as a diff" | |||
description: "Preview helm upgrade changes as a diff" | |||
useTunnel: true | |||
command: "$HELM_PLUGIN_DIR/bin/diff" | |||
command: "$HELM_PLUGIN_DIR/diff" |
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.
this conflicts with master and needs to be reverted.
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.
resolved it
} | ||
|
||
chartCommand := newChartCommand() |
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.
Huh, why remove all this? The aliasing is done to keep backward compatibility. I would like to keep that for a while to make that this doesn't break existing CI systems.
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.
oops...!! I didn't remove it. just rearranged the code syntatically.
It is there, just fitted chartCommand.Args it inside, cobra.command
and placed chartCommand := newChartCommand()
above it
chartCommand := newChartCommand()
cmd := &cobra.Command{
Use: "diff",
Short: "Show manifest differences",
//Alias root command to chart subcommand
Args: chartCommand.Args,
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.
does this need changes/reverting..?, its exactly the same code..!!
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.
Ah, ok my Mistake, thanks for clearing this up. LGTM
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.
removed it
cmd/upgrade.go
Outdated
@@ -20,6 +19,7 @@ type diffCmd struct { | |||
reuseValues bool | |||
resetValues bool | |||
suppressedKinds []string | |||
revisions []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.
this is unused now IMO
cmd/revision.go
Outdated
func revisionCmd() *cobra.Command { | ||
diff := revision{} | ||
revisionCmd := &cobra.Command{ | ||
Use: "revision [flags] [RELEASE] REVISION1 REVISION2", |
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.
When doing some manually tests I was wondering if revision [flags] RELEASE REVISION1 [REVISION2]
would be more correct?
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.
both revision1 and revision2 are mandatory, so how can it be indicated..?
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 seems to me like REVISION2 is not mandatory and defaults to the latest revision. At least I can do helm diff revision $RELEASE 42
.
I think RELEASE1 could even be also be optional and default to $latest-1
. So that a simple helm diff revision
would give you the latest change applied.
I've tested this a bit and I'm quite happy with how it works. I think we are almost done. I noticed that both commands are missing the Other then that the last remaining bit would be to squash and rebase this so that it can be cleanly merged. |
Thanks @databus23 for guiding me all the way..!!
one help, I have never squash multiple commits into a single one before. can u help..? |
git rebase -i HEAD~4 where 4 is the number of commits to combine |
Something is messy with the branch. It look fine from the overall changes but can't be merged cleanly in master. |
I'm not a git guru. For me this very much applies: https://xkcd.com/1597/ I think we can keep this PR if you manage to force push the Here is how I would fix it:
This is dry coded, might not work but something like this should do the job. |
reopening it in a cleaner way |
4b0ee6b
to
81d477f
Compare
Looks to me like you lost some stuff during your git spelunking. |
2b8f694
to
81d477f
Compare
This PR is now missing all of the code changes. |
a5cca6a
to
81d477f
Compare
81d477f
to
72467ef
Compare
all in one commit ❤️
@databus23 can we..? |
Thanks for you hard work on this! |
@aananthraj I just noticed that your README changes are missing from this PR. Would you mind re-adding them in a separate commit. |
sure, tried adding it again in this PR, but looks like the branch is locked after its merge. solution would be
the former look feasible to me. will create a new PR. @databus23 Thanks a lot 🙏 , it took a very long time to make this feature live. |
I've tested a few revision diffs and a upgrade diff and it seems to be working! |
Readme and Usage Updation : following #22
This provides the ability to do a diff on revisions.
I have made some improvements with
kindly have a look, and let me know in case of corrections/bugs.
Thanks..!!