github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/action/up.go (about)

     1  package action
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/helmwave/helmwave/pkg/clictx"
     7  	"github.com/helmwave/helmwave/pkg/helper"
     8  	"github.com/helmwave/helmwave/pkg/kubedog"
     9  	"github.com/helmwave/helmwave/pkg/plan"
    10  	log "github.com/sirupsen/logrus"
    11  	"github.com/urfave/cli/v2"
    12  )
    13  
    14  var _ Action = (*Up)(nil)
    15  
    16  // Up is a struct for running 'up' command.
    17  type Up struct {
    18  	build     *Build
    19  	dog       *kubedog.Config
    20  	autoBuild bool
    21  }
    22  
    23  // Run is the main function for 'up' command.
    24  func (i *Up) Run(ctx context.Context) error {
    25  	if i.autoBuild {
    26  		if err := i.build.Run(ctx); err != nil {
    27  			return err
    28  		}
    29  	} else {
    30  		i.warnOnBuildFlags(ctx)
    31  	}
    32  
    33  	p, err := plan.NewAndImport(ctx, i.build.plandir)
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	p.Logger().Info("🏗 Plan")
    39  
    40  	return p.Up(ctx, i.dog)
    41  }
    42  
    43  func (i *Up) warnOnBuildFlags(ctx context.Context) {
    44  	cliCtx := clictx.GetCLIFromContext(ctx)
    45  	if cliCtx == nil {
    46  		return
    47  	}
    48  
    49  	for _, buildFlag := range i.build.flags() {
    50  		name := buildFlag.Names()[0]
    51  		if cliCtx.IsSet(name) {
    52  			log.WithField("flag", name).Warn("this flag is used by autobuild (--build) but autobuild is disabled")
    53  		}
    54  	}
    55  }
    56  
    57  // Cmd returns 'up' *cli.Command.
    58  func (i *Up) Cmd() *cli.Command {
    59  	return &cli.Command{
    60  		Name:     "up",
    61  		Category: Step2,
    62  		Usage:    "🚢 apply your plan",
    63  		Flags:    i.flags(),
    64  		Action:   toCtx(i.Run),
    65  	}
    66  }
    67  
    68  // flags return flag set of CLI urfave.
    69  func (i *Up) flags() []cli.Flag {
    70  	// Init sub-structures
    71  	i.dog = &kubedog.Config{}
    72  	i.build = &Build{}
    73  
    74  	self := []cli.Flag{
    75  		flagAutoBuild(&i.autoBuild),
    76  		&cli.BoolFlag{
    77  			Name:        "progress",
    78  			Usage:       "enable progress logs of helm (INFO log level)",
    79  			Value:       false,
    80  			Category:    "KUBEDOG",
    81  			EnvVars:     []string{"HELMWAVE_PROGRESS"},
    82  			Destination: &helper.Helm.Debug,
    83  		},
    84  		&cli.IntFlag{
    85  			Name:    "parallel-limit",
    86  			Usage:   "limit amount of parallel releases",
    87  			EnvVars: []string{"HELMWAVE_PARALLEL_LIMIT"},
    88  			Value:   0,
    89  		},
    90  	}
    91  
    92  	self = append(self, flagsKubedog(i.dog)...)
    93  	self = append(self, i.build.flags()...)
    94  
    95  	return self
    96  }