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

feature Implementation: Diff between Revisions #6 #22

Merged
merged 1 commit into from Apr 26, 2018

Conversation

codenio
Copy link
Contributor

@codenio codenio commented Jan 24, 2018

This provides the ability to do a diff on revisions.
I have made some improvements with

  • safer code terminations with (exit 0),
  • Intelligent suggestions for subcommands
  • docs
  • code restructuring.
    kindly have a look, and let me know in case of corrections/bugs.

Thanks..!!

@codenio
Copy link
Contributor Author

codenio commented Jan 26, 2018

@databus23 , any update on this..?

@databus23
Copy link
Owner

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

@codenio
Copy link
Contributor Author

codenio commented Jan 26, 2018

Thanks @databus23, for the prompt response.

I have one more feature request and its implementation in a separate branch feature/rollback-diff for forecasting what a helm rollback would change (revert). My question here is, Can I raise a new pull request ? or include those as part of this pull request ?.

Thanks,
Aananth K

Copy link
Owner

@databus23 databus23 left a 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
Copy link
Owner

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?

Copy link
Contributor Author

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 instance rollback

    In case these points are not appealing, we could work on it.

Copy link
Contributor Author

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

@codenio codenio changed the title feature Implementing: Diff between Revisions #6 feature Implementation: Diff between Revisions #6 Feb 20, 2018
@codenio codenio mentioned this pull request Apr 5, 2018
@sstarcher
Copy link
Contributor

@aananthraj I believe the discussions here might be of help - #34 (comment)

helm diff upgrade was added, but helm diff is aliased to helm diff upgrade

The CLI has been restructured so you can now add revision support if you have time to refactor.

@sfrique
Copy link

sfrique commented Apr 16, 2018

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.

@codenio
Copy link
Contributor Author

codenio commented Apr 20, 2018

@sstarcher thanks for update 👍 , was waiting for this..!!!

@codenio
Copy link
Contributor Author

codenio commented Apr 20, 2018

Hi @databus23 and @sstarcher ,

made suitable changes to include subcommands like

  • revision

    $ helm diff revision -h
    
    This command compares the manifests details of a named release.
    
    It can be used to compare the manifests of 
    
    - lastest REVISION with specified REVISION
     $ helm diff revision [flags] [RELEASE] [REVISION]
    
    - REVISION1 with REVISION2
     $ helm diff revision [flags] [RELEASE] [REVISION1] [REVISION2]
    
    Usage:
     diff revision [flags] [RELEASE] REVISION1 REVISION2
    
    Flags:
       -h, --help   help for revision
    
  • rollback

    $ helm diff rollback -h
    
    This command compares the laset manifests details of a named release 
    with specific revision values to rollback.
    
    It forecasts/visualizes changes, that a helm rollback could perform.
    
    Usage:
      diff rollback [flags] [RELEASE] [REVISION]
    
    Flags:
      -h, --help   help for rollback
    

opinions..?

@codenio
Copy link
Contributor Author

codenio commented Apr 23, 2018

can this be merged..? or still some fixes needed..?

@codenio
Copy link
Contributor Author

codenio commented Apr 25, 2018

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.
@sstarcher can you help here..?
@databus23 opinions..?

Copy link
Owner

@databus23 databus23 left a 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{}
Copy link
Owner

@databus23 databus23 Apr 25, 2018

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.

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Owner

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

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.

Copy link
Contributor Author

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.

Copy link
Owner

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

Copy link
Contributor Author

@codenio codenio Apr 25, 2018

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"
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved it

}

chartCommand := newChartCommand()
Copy link
Owner

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.

Copy link
Contributor Author

@codenio codenio Apr 25, 2018

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,

Copy link
Contributor Author

@codenio codenio Apr 26, 2018

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

Copy link
Owner

@databus23 databus23 Apr 26, 2018

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

Copy link
Contributor Author

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
Copy link
Owner

@databus23 databus23 Apr 26, 2018

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",
Copy link
Owner

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?

Copy link
Contributor Author

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

Copy link
Owner

@databus23 databus23 Apr 26, 2018

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.

@databus23
Copy link
Owner

databus23 commented Apr 26, 2018

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 --suppress and --suppres-secrets flag (They are not shown when running helm diff revison|rollback -h). Can we add them?

Other then that the last remaining bit would be to squash and rebase this so that it can be cleanly merged.

@codenio
Copy link
Contributor Author

codenio commented Apr 26, 2018

Thanks @databus23 for guiding me all the way..!!

Other then that the last remaining bit would be to squash and rebase this so that it can be cleanly merged.

one help, I have never squash multiple commits into a single one before. can u help..?
i tried something and i am not sure, whether it is correct

@sstarcher
Copy link
Contributor

git rebase -i HEAD~4 where 4 is the number of commits to combine

@databus23
Copy link
Owner

Something is messy with the branch. It look fine from the overall changes but can't be merged cleanly in master.

@databus23
Copy link
Owner

databus23 commented Apr 26, 2018

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 aananthraj:feature/revision-diffbranch with a clean commit on top of master.

Here is how I would fix it:

git checkout -b feature/revision-diff-new master
git diff master..feature/revision-diff | patch -p1
git commit -a -m "..."
git push -f aananthraj feature/revision-diff

This is dry coded, might not work but something like this should do the job.

@codenio codenio closed this Apr 26, 2018
@codenio codenio deleted the feature/revision-diff branch April 26, 2018 14:41
@codenio
Copy link
Contributor Author

codenio commented Apr 26, 2018

reopening it in a cleaner way

@codenio codenio reopened this Apr 26, 2018
@databus23
Copy link
Owner

Looks to me like you lost some stuff during your git spelunking.

@databus23
Copy link
Owner

This PR is now missing all of the code changes.
Its just the README. As I said you lost something during your git advanture... :)

@codenio
Copy link
Contributor Author

codenio commented Apr 26, 2018

all in one commit ❤️

  • super clean 😎
  • contains code 😆
  • working fine for me 👍
  • no merge conflicts 😄

screen shot 2018-04-26 at 11 16 54 pm

@databus23 can we..?
waiting for it..!!

@databus23 databus23 merged commit 9beb907 into databus23:master Apr 26, 2018
@databus23
Copy link
Owner

Thanks for you hard work on this!

@databus23
Copy link
Owner

@aananthraj I just noticed that your README changes are missing from this PR. Would you mind re-adding them in a separate commit.

@codenio
Copy link
Contributor Author

codenio commented Apr 27, 2018

sure, tried adding it again in this PR, but looks like the branch is locked after its merge. solution would be

  • create a separate PR
  • Revert the current merge and add the commit here and merge it again.

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.
feeling awesome now. Thanks for making me learn cool stuff about GitHub 😆

@sfrique
Copy link

sfrique commented Apr 27, 2018

I've tested a few revision diffs and a upgrade diff and it seems to be working!
helm diff helps a lot to verify changes before applying them, now it will help to see whats changed over the time.
Thanks a lot for this feature.

databus23 added a commit that referenced this pull request Apr 27, 2018
Readme and Usage Updation : following #22
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.

None yet

4 participants