diff --git a/cmd/deploy_app.go b/cmd/deploy_app.go index 65a0c0b..a82a013 100644 --- a/cmd/deploy_app.go +++ b/cmd/deploy_app.go @@ -43,7 +43,7 @@ const ( func deployAppFlags(cmd *cobra.Command) { cmd.Flags().StringSlice(argDeployPlanProviderPriority, []string{bosun.WorkspaceProviderName, bosun.SlotUnstable, bosun.SlotStable}, "Providers in priority order to use to deploy apps (current, stable, unstable, or workspace).") - cmd.Flags().StringSlice(argDeployPlanApps, []string{}, "AppDeploymentProgress to include.") + cmd.Flags().StringSlice(argDeployPlanApps, []string{}, "Apps to include.") cmd.Flags().Bool(argDeployPlanAll, false, "Deploy all apps.") cmd.Flags().String(argDeployAppTag, "", "Tag to use when deploying the app or apps.") cmd.Flags().Bool(argDeployPlanIgnoreDeps, true, "Don't validate dependencies.") diff --git a/cmd/deploy_plan.go b/cmd/deploy_plan.go index 329c05f..ec582c3 100644 --- a/cmd/deploy_plan.go +++ b/cmd/deploy_plan.go @@ -64,18 +64,23 @@ var deployPlanCmd = addCommand(deployCmd, &cobra.Command{ IgnoreDependencies: viper.GetBool(argDeployPlanIgnoreDeps), AutomaticDependencies: viper.GetBool(argDeployPlanAutoDeps), } - update := viper.GetBool(argDeployPlanUpdate) + replace := viper.GetBool(argDeployPlanReplace) var previousPlan *bosun.DeploymentPlan - if update { + + if !replace { + previousPlan, err = bosun.LoadDeploymentPlanFromFile(path) - if err != nil { - return errors.Wrap(err, "could not load existing plan") - } - req.ProviderPriority = previousPlan.ProviderPriority - for _, app := range previousPlan.Apps { - req.Apps = append(req.Apps, app.Name) + if err == nil { + + req.ProviderPriority = previousPlan.ProviderPriority + for _, app := range previousPlan.Apps { + req.Apps = append(req.Apps, app.Name) + } } - } else { + } + + if len(req.Apps) == 0 { + provider := viper.GetString(argDeployPlanProviderPriority) if provider == "" { provider = userChooseProvider(provider) @@ -94,6 +99,7 @@ var deployPlanCmd = addCommand(deployCmd, &cobra.Command{ req.Apps = userChooseApps("Choose apps to deploy", req.Apps) } } + } planCreator := bosun.NewDeploymentPlanCreator(b, p) @@ -139,11 +145,11 @@ var deployPlanCmd = addCommand(deployCmd, &cobra.Command{ func applyDeployPlanFlags(cmd *cobra.Command) { cmd.Flags().String(argDeployPlanPath, "", "Dir where plan should be stored.") cmd.Flags().String(argDeployPlanProviderPriority, "", "Provider to use to deploy apps (current, stable, unstable, or workspace).") - cmd.Flags().StringSlice(argDeployPlanApps, []string{}, "AppDeploymentProgress to include.") + cmd.Flags().StringSlice(argDeployPlanApps, []string{}, "Apps to include.") cmd.Flags().Bool(argDeployPlanAll, false, "Deploy all apps which target the current environment.") cmd.Flags().Bool(argDeployPlanIgnoreDeps, false, "Don't validate dependencies.") cmd.Flags().Bool(argDeployPlanAutoDeps, false, "Automatically include dependencies.") - cmd.Flags().Bool(argDeployPlanUpdate, false, "Update an existing plan rather than creating a new one.") + cmd.Flags().Bool(argDeployPlanReplace, false, "Replace an existing plan rather than updating it if it already exists.") } const ( @@ -153,7 +159,7 @@ const ( argDeployPlanProviderPriority = "providers" argDeployPlanIgnoreDeps = "ignore-deps" argDeployPlanAutoDeps = "auto-deps" - argDeployPlanUpdate = "update" + argDeployPlanReplace = "replace" ) var deployReleasePlanCmd = addCommand(deployPlanCmd, &cobra.Command{ @@ -230,13 +236,26 @@ func releaseDeployPlan(slotDescription string) error { BasedOnHash: basedOnHash, } - pinnedApps, err := r.GetAppManifestsPinnedToRelease() - if err != nil { - return err - } + knownApps, err := r.GetAppManifests() + ctx := b.NewContext() + + if viper.GetBool(argDeployPlanAll) { + ctx.Log().Info("Adding all apps in release to the plan...") + + for _, app := range knownApps { + req.Apps = append(req.Apps, app.Name) + ctx.Log().Infof("Adding %s", app.Name) - for name := range pinnedApps { - req.Apps = append(req.Apps, name) + } + } else { + pinnedApps, pinnedAppsErr := r.GetAppManifestsPinnedToRelease() + if pinnedAppsErr != nil { + return pinnedAppsErr + } + + for name := range pinnedApps { + req.Apps = append(req.Apps, name) + } } planCreator := bosun.NewDeploymentPlanCreator(b, p) diff --git a/cmd/deploy_show.go b/cmd/deploy_show.go index 8fb2eb8..c48d7eb 100644 --- a/cmd/deploy_show.go +++ b/cmd/deploy_show.go @@ -22,20 +22,19 @@ var deployShowCmd = addCommand(deployCmd, &cobra.Command{ } stack, err := b.GetCurrentStack() - if err != nil { - return err - } - - stackBrn := stack.Brn + if err != nil { + return err + } + env := b.GetCurrentEnvironment() - report := plan.GetDeploymentProgressReportForStack(stackBrn) + report := plan.GetDeploymentProgressReportForStack(env, stack) return renderOutput(report) }, }) -func getPlan(b *bosun.Bosun, args []string)(*bosun.DeploymentPlan, error) { +func getPlan(b *bosun.Bosun, args []string) (*bosun.DeploymentPlan, error) { p, err := b.GetCurrentPlatform() if err != nil { @@ -68,4 +67,4 @@ func getPlan(b *bosun.Bosun, args []string)(*bosun.DeploymentPlan, error) { plan, err = bosun.LoadDeploymentPlanFromFile(path) return plan, err -} \ No newline at end of file +} diff --git a/cmd/git_accept.go b/cmd/git_accept.go index 23ce8de..70e86fe 100644 --- a/cmd/git_accept.go +++ b/cmd/git_accept.go @@ -68,7 +68,7 @@ var gitAcceptPullRequestCmd = addCommand(gitCmd, &cobra.Command{ return nil }, }, func(cmd *cobra.Command) { - cmd.Flags().StringSlice(ArgGitAcceptPRAppVersion, []string{}, "AppDeploymentProgress to apply version bump to.") + cmd.Flags().StringSlice(ArgGitAcceptPRAppVersion, []string{}, "app to apply version bump to.") }) const ArgGitAcceptPRAppVersion = "app" diff --git a/cmd/repo.go b/cmd/repo.go index 115ba8e..6fc2273 100644 --- a/cmd/repo.go +++ b/cmd/repo.go @@ -50,7 +50,7 @@ var _ = addCommand(repoCmd, &cobra.Command{ t := tablewriter.NewWriter(os.Stdout) - t.SetHeader([]string{"Name", "Cloned", "Local Dir", "Labels", "AppDeploymentProgress"}) + t.SetHeader([]string{"Name", "Cloned", "Local Dir", "Labels", "App"}) t.SetReflowDuringAutoWrap(false) t.SetAutoWrapText(false) diff --git a/pkg/bosun/deploy.go b/pkg/bosun/deploy.go index 0b83186..545dfd1 100644 --- a/pkg/bosun/deploy.go +++ b/pkg/bosun/deploy.go @@ -205,7 +205,7 @@ func NewDeploy(ctx BosunContext, settings DeploySettings) (*Deploy, error) { appDeployMap[appDeploy.Name] = appDeploy } } else { - return nil, errors.New("either settings.Manifest, settings.AppDeploymentProgress, or settings.AppManifests must be populated") + return nil, errors.New("either settings.Manifest, settings.Apps, or settings.AppManifests must be populated") } if settings.Filter != nil { diff --git a/pkg/bosun/deployment_plan.go b/pkg/bosun/deployment_plan.go index 7acab16..59aa420 100644 --- a/pkg/bosun/deployment_plan.go +++ b/pkg/bosun/deployment_plan.go @@ -5,6 +5,7 @@ import ( "github.com/naveego/bosun/pkg/brns" "github.com/naveego/bosun/pkg/core" "github.com/naveego/bosun/pkg/environment" + "github.com/naveego/bosun/pkg/kube" "github.com/naveego/bosun/pkg/mirror" "github.com/naveego/bosun/pkg/semver" "github.com/naveego/bosun/pkg/values" @@ -159,7 +160,7 @@ func (a AddDeploymentProgressReports) Rows() [][]string { return rows } -func (d *DeploymentPlan) GetDeploymentProgressReportForStack(brn brns.StackBrn) AddDeploymentProgressReports { +func (d *DeploymentPlan) GetDeploymentProgressReportForStack(env *environment.Environment, stack *kube.Stack) AddDeploymentProgressReports { var reports []AppDeploymentProgressReport @@ -175,24 +176,33 @@ func (d *DeploymentPlan) GetDeploymentProgressReportForStack(brn brns.StackBrn) continue } - if progress.Stack != brn.String() { + if progress.Stack != stack.Brn.String() { continue } report.Progress = *progress } - if report.Progress.Hash == plan.Manifest.Hashes.Summarize() { + if env.IsAppDisabled(plan.Name) { + report.Status = "Disabled (by environment)" + report.OutOfSync = true + } else if stack.IsAppDisabled(plan.Name) { + report.Status = "Disabled (by stack)" + report.OutOfSync = true + } else { - report.Status = "Deployed" + if report.Progress.Hash == plan.Manifest.Hashes.Summarize() { - } else { - report.OutOfSync = true + report.Status = "Deployed" - if report.Progress.Timestamp.IsZero() { - report.Status = "Never deployed" } else { - report.Status = "Changed since deployed" + report.OutOfSync = true + + if report.Progress.Timestamp.IsZero() { + report.Status = "Never deployed" + } else { + report.Status = "Changed since deployed" + } } } diff --git a/pkg/bosun/platform.go b/pkg/bosun/platform.go index edba1fd..5206396 100644 --- a/pkg/bosun/platform.go +++ b/pkg/bosun/platform.go @@ -710,10 +710,11 @@ func (p *Platform) SetReleaseManifest(slot string, manifest *ReleaseManifest) { func (p *Platform) GetApps(ctx filter.MatchMapArgContainer) PlatformAppConfigs { + matchArgs := ctx.GetMatchMapArgs() + var out []*PlatformAppConfig for _, app := range p.Apps { - if app.TargetFilters.Matches(ctx.GetMatchMapArgs()) { - + if len(matchArgs) == 0 || app.TargetFilters.Matches(matchArgs) { out = append(out, app) } } diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index 21411a5..a59f696 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -50,7 +50,7 @@ func (e *Environment) GetValueSetCollection() values.ValueSetCollection { } // IsAppDisabled returns true if the app is disabled for the environment. -// AppDeploymentProgress are assumed to be disabled for the environment unless they are in the app list and not marked as disabled +// Apps are assumed to be disabled for the environment unless they are in the app list and not marked as disabled func (e Environment) IsAppDisabled(appName string) bool { v, ok := e.Apps[appName] return !ok || v.Disabled diff --git a/pkg/kube/stack.go b/pkg/kube/stack.go index ebd34e4..5cb410e 100644 --- a/pkg/kube/stack.go +++ b/pkg/kube/stack.go @@ -457,6 +457,10 @@ func (c *Stack) GetAppValueSetCollectionProvider(appName string) values.ValueSet } func (s Stack) IsAppDisabled(name string) bool { + if len(s.StackTemplate.Apps) == 0 { + // if the stack doesn't have an explicit list of apps then all environment apps are enabled + return false + } app, ok := s.StackTemplate.Apps[name] return !(ok && !app.Disabled)