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

Added dry run flag support for install #129

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added dry run flag support for install
deepankur797 committed Nov 30, 2021
commit 41d7eacf726170dd09cad0d5386f1c2326f68439
4 changes: 3 additions & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
@@ -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
}
}
37 changes: 31 additions & 6 deletions pkg/apps/apps.go
Original file line number Diff line number Diff line change
@@ -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)
}
}