From 41d7eacf726170dd09cad0d5386f1c2326f68439 Mon Sep 17 00:00:00 2001 From: deepankur797 Date: Tue, 30 Nov 2021 12:53:06 +0530 Subject: [PATCH 1/2] Added dry run flag support for install --- cmd/cli/main.go | 4 +++- pkg/apps/apps.go | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 4e95795..f4de2df 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -41,6 +41,7 @@ var ( namespace string timeout string debug bool + dryrun bool rootCmd = &cobra.Command{ Use: "kbrew", @@ -216,6 +217,7 @@ func init() { infoCmd.AddCommand(argsCmd) installCmd.PersistentFlags().StringVarP(&timeout, "timeout", "t", "", "time to wait for app components to be in a ready state (default 15m0s)") + installCmd.PersistentFlags().BoolVarP(&dryrun, "dry-run", "", false, "dry run the installation") } func main() { @@ -257,7 +259,7 @@ func manageApp(m apps.Method, args []string) error { printDetails(logger, strings.ToLower(a), m, c) ctxTimeout, cancel := context.WithTimeout(ctx, timeoutDur) defer cancel() - if err := runner.Run(ctxTimeout, strings.ToLower(a), namespace, configFile); err != nil { + if err := runner.Run(ctxTimeout, strings.ToLower(a), namespace, configFile, dryrun); err != nil { return err } } diff --git a/pkg/apps/apps.go b/pkg/apps/apps.go index 96e3cc3..16fa4fa 100644 --- a/pkg/apps/apps.go +++ b/pkg/apps/apps.go @@ -64,7 +64,7 @@ func NewAppRunner(op Method, log *log.Logger, status *log.Status) *AppRunner { } // Run fetches recipe from registry for the app and performs given operation -func (r *AppRunner) Run(ctx context.Context, appName, namespace, appConfigPath string) error { +func (r *AppRunner) Run(ctx context.Context, appName, namespace, appConfigPath string, dryrun bool) error { c, err := config.NewApp(appName, appConfigPath) if err != nil { return err @@ -101,7 +101,32 @@ func (r *AppRunner) Run(ctx context.Context, appName, namespace, appConfigPath s switch r.operation { case Install: - return r.runInstall(ctx, app, c, appName, namespace, appConfigPath) + // skipping install if dry-run + if dryrun { + r.log.Infof("Application to install %v \n", c.App.Name) + r.log.Infof("Application Type %v \nApplication URL %v \n", c.App.Repository.Type, c.App.Repository.URL) + r.log.Info("Pre Install Dependencies\n") + for _, phase := range c.App.PreInstall { + for _, a := range phase.Apps { + r.log.Infof("Application %v\n", a) + } + for _, a := range phase.Steps { + r.log.Infof("Manifest \n%v \n", a) + } + } + r.log.Info("Post Install Dependencies\n") + for _, phase := range c.App.PostInstall { + for _, a := range phase.Apps { + r.log.Infof("Application %v\n", a) + } + for _, a := range phase.Steps { + r.log.Infof("Manifest \n%v \n", a) + } + } + return nil + } else { + return r.runInstall(ctx, app, c, appName, namespace, appConfigPath) + } case Uninstall: return r.runUninstall(ctx, app, c, appName, namespace, appConfigPath) default: @@ -118,7 +143,7 @@ func (r *AppRunner) runInstall(ctx context.Context, app App, c *config.AppConfig r.status.Start(fmt.Sprintf("Setting up pre-install dependencies for %s", appName)) for _, phase := range c.App.PreInstall { for _, a := range phase.Apps { - if err := r.Run(ctx, a, namespace, filepath.Join(filepath.Dir(appConfigPath), a+".yaml")); err != nil { + if err := r.Run(ctx, a, namespace, filepath.Join(filepath.Dir(appConfigPath), a+".yaml"), false); err != nil { return r.handleInstallError(ctx, err, event, app, appName, namespace) } } @@ -143,7 +168,7 @@ func (r *AppRunner) runInstall(ctx context.Context, app App, c *config.AppConfig r.status.Start(fmt.Sprintf("Setting up post-install dependencies for %s", appName)) for _, phase := range c.App.PostInstall { for _, a := range phase.Apps { - if err := r.Run(ctx, a, namespace, filepath.Join(filepath.Dir(appConfigPath), a+".yaml")); err != nil { + if err := r.Run(ctx, a, namespace, filepath.Join(filepath.Dir(appConfigPath), a+".yaml"), false); err != nil { return r.handleInstallError(ctx, err, event, app, appName, namespace) } } @@ -182,7 +207,7 @@ func (r *AppRunner) runUninstall(ctx context.Context, app App, c *config.AppConf // Delete postinstall apps for _, phase := range c.App.PostInstall { for _, a := range phase.Apps { - if err := r.Run(ctx, a, namespace, filepath.Join(filepath.Dir(appConfigPath), a+".yaml")); err != nil { + if err := r.Run(ctx, a, namespace, filepath.Join(filepath.Dir(appConfigPath), a+".yaml"), false); err != nil { return r.handleUninstallError(ctx, err, event, appName, namespace) } } @@ -198,7 +223,7 @@ func (r *AppRunner) runUninstall(ctx context.Context, app App, c *config.AppConf // Delete preinstall apps for _, phase := range c.App.PreInstall { for _, a := range phase.Apps { - if err := r.Run(ctx, a, namespace, filepath.Join(filepath.Dir(appConfigPath), a+".yaml")); err != nil { + if err := r.Run(ctx, a, namespace, filepath.Join(filepath.Dir(appConfigPath), a+".yaml"), false); err != nil { return r.handleUninstallError(ctx, err, event, appName, namespace) } } From b47982a1941be19639b56efe812b411742dbdeda Mon Sep 17 00:00:00 2001 From: deepankur797 Date: Tue, 30 Nov 2021 17:32:45 +0530 Subject: [PATCH 2/2] Removed lint error --- pkg/apps/apps.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/apps/apps.go b/pkg/apps/apps.go index 16fa4fa..f7f7591 100644 --- a/pkg/apps/apps.go +++ b/pkg/apps/apps.go @@ -124,9 +124,9 @@ func (r *AppRunner) Run(ctx context.Context, appName, namespace, appConfigPath s } } return nil - } else { - return r.runInstall(ctx, app, c, appName, namespace, appConfigPath) } + return r.runInstall(ctx, app, c, appName, namespace, appConfigPath) + case Uninstall: return r.runUninstall(ctx, app, c, appName, namespace, appConfigPath) default: