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
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
namespace string
timeout string
debug bool
dryrun bool

rootCmd = &cobra.Command{
Use: "kbrew",
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}
}
Expand Down
35 changes: 30 additions & 5 deletions pkg/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,7 +101,32 @@ func (r *AppRunner) Run(ctx context.Context, appName, namespace, appConfigPath s

switch r.operation {
case Install:
// 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
}
return r.runInstall(ctx, app, c, appName, namespace, appConfigPath)

case Uninstall:
return r.runUninstall(ctx, app, c, appName, namespace, appConfigPath)
default:
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down