Skip to content

Commit

Permalink
Add sync-strategy field to output of planner (#2171)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:

PlanPreview feature needs this field to build its result.

**Which issue(s) this PR fixes**:

Fixes #

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
-->
```release-note
NONE
```

This PR was merged by Kapetanios.
  • Loading branch information
nghialv committed Jul 2, 2021
1 parent e86b7c2 commit 18679a6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pkg/app/piped/planner/cloudrun/cloudrun.go
Expand Up @@ -66,6 +66,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
// we rely on the user's decision.
switch in.Deployment.Trigger.SyncStrategy {
case model.SyncStrategy_QUICK_SYNC:
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync to deploy image %s and configure all traffic to it (forced via web)", out.Version)
return
Expand All @@ -74,6 +75,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
err = fmt.Errorf("unable to force sync with pipeline because no pipeline was specified")
return
}
out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Sync with pipeline to deploy image %s (forced via web)", out.Version)
return
Expand All @@ -82,13 +84,15 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
// This is the first time to deploy this application or it was unable to retrieve that value.
// We just do the quick sync.
if in.MostRecentSuccessfulCommitHash == "" {
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync to deploy image %s and configure all traffic to it (it seems this is the first deployment)", out.Version)
return
}

// When no pipeline was configured, do the quick sync.
if cfg.Pipeline == nil || len(cfg.Pipeline.Stages) == 0 {
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync to deploy image %s and configure all traffic to it (pipeline was not configured)", out.Version)
return
Expand All @@ -98,12 +102,14 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
ds, err = in.RunningDSP.Get(ctx, ioutil.Discard)
if err == nil {
if lastVersion, e := p.determineVersion(ds.AppDir, cfg.Input.ServiceManifestFile); e == nil {
out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Sync with pipeline to update image from %s to %s", lastVersion, out.Version)
return
}
}

out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = "Sync with the specified pipeline"
return
Expand Down
6 changes: 6 additions & 0 deletions pkg/app/piped/planner/ecs/ecs.go
Expand Up @@ -66,6 +66,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
// we rely on the user's decision.
switch in.Deployment.Trigger.SyncStrategy {
case model.SyncStrategy_QUICK_SYNC:
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync to deploy image %s and configure all traffic to it (forced via web)", out.Version)
return
Expand All @@ -74,6 +75,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
err = fmt.Errorf("unable to force sync with pipeline because no pipeline was specified")
return
}
out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Sync with pipeline to deploy image %s (forced via web)", out.Version)
return
Expand All @@ -82,13 +84,15 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
// If this is the first time to deploy this application or it was unable to retrieve last successful commit,
// we perform the quick sync strategy.
if in.MostRecentSuccessfulCommitHash == "" {
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync to deploy image %s and configure all traffic to it (it seems this is the first deployment)", out.Version)
return
}

// When no pipeline was configured, perform the quick sync.
if cfg.Pipeline == nil || len(cfg.Pipeline.Stages) == 0 {
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync to deploy image %s and configure all traffic to it (pipeline was not configured)", out.Version)
return
Expand All @@ -98,12 +102,14 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
ds, err = in.RunningDSP.Get(ctx, ioutil.Discard)
if err == nil {
if lastVersion, e := determineVersion(ds.AppDir, cfg.Input.TaskDefinitionFile); e == nil {
out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Sync with pipeline to update image from %s to %s", lastVersion, out.Version)
return
}
}

out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = "Sync with the specified pipeline"
return
Expand Down
8 changes: 8 additions & 0 deletions pkg/app/piped/planner/kubernetes/kubernetes.go
Expand Up @@ -101,6 +101,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
// we rely on the user's decision.
switch in.Deployment.Trigger.SyncStrategy {
case model.SyncStrategy_QUICK_SYNC:
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = "Quick sync by applying all manifests (forced via web)"
return
Expand All @@ -109,6 +110,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
err = fmt.Errorf("unable to force sync with pipeline because no pipeline was specified")
return
}
out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = "Sync with the specified pipeline (forced via web)"
return
Expand All @@ -117,6 +119,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
// If the progressive pipeline was not configured
// we have only one choise to do is applying all manifestt.
if cfg.Pipeline == nil || len(cfg.Pipeline.Stages) == 0 {
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = "Quick sync by applying all manifests (no pipeline was configured)"
return
Expand All @@ -131,6 +134,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
return out, err
}
if pipelineRegex.MatchString(in.Deployment.Trigger.Commit.Message) {
out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Sync progressively because the commit message was matching %q", p)
return out, err
Expand All @@ -146,6 +150,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
return out, err
}
if syncRegex.MatchString(in.Deployment.Trigger.Commit.Message) {
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync by applying all manifests because the commit message was matching %q", s)
return out, err
Expand All @@ -156,6 +161,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
// or it was unable to retrieve that value.
// We just apply all manifests.
if in.MostRecentSuccessfulCommitHash == "" {
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = "Quick sync by applying all manifests because it seems this is the first deployment"
return
Expand Down Expand Up @@ -185,10 +191,12 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
out.Summary = desc

if progressive {
out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
return
}

out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
return
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/app/piped/planner/lambda/lambda.go
Expand Up @@ -66,6 +66,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
// we rely on the user's decision.
switch in.Deployment.Trigger.SyncStrategy {
case model.SyncStrategy_QUICK_SYNC:
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync to deploy image %s and configure all traffic to it (forced via web)", out.Version)
return
Expand All @@ -74,6 +75,7 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
err = fmt.Errorf("unable to force sync with pipeline because no pipeline was specified")
return
}
out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Sync with pipeline to deploy image %s (forced via web)", out.Version)
return
Expand All @@ -82,13 +84,15 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
// If this is the first time to deploy this application or it was unable to retrieve last successful commit,
// we perform the quick sync strategy.
if in.MostRecentSuccessfulCommitHash == "" {
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync to deploy image %s and configure all traffic to it (it seems this is the first deployment)", out.Version)
return
}

// When no pipeline was configured, perform the quick sync.
if cfg.Pipeline == nil || len(cfg.Pipeline.Stages) == 0 {
out.SyncStrategy = model.SyncStrategy_QUICK_SYNC
out.Stages = buildQuickSyncPipeline(cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Quick sync to deploy image %s and configure all traffic to it (pipeline was not configured)", out.Version)
return
Expand All @@ -98,12 +102,14 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
ds, err = in.RunningDSP.Get(ctx, ioutil.Discard)
if err == nil {
if lastVersion, e := determineVersion(ds.AppDir, cfg.Input.FunctionManifestFile); e == nil {
out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = fmt.Sprintf("Sync with pipeline to update image from %s to %s", lastVersion, out.Version)
return
}
}

out.SyncStrategy = model.SyncStrategy_PIPELINE
out.Stages = buildProgressivePipeline(cfg.Pipeline, cfg.Input.AutoRollback, time.Now())
out.Summary = "Sync with the specified pipeline"
return
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/piped/planner/planner.go
Expand Up @@ -49,9 +49,10 @@ type Input struct {
}

type Output struct {
Version string
Stages []*model.PipelineStage
Summary string
Version string
SyncStrategy model.SyncStrategy
Summary string
Stages []*model.PipelineStage
}

// MakeInitialStageMetadata makes the initial metadata for the given state configuration.
Expand Down

0 comments on commit 18679a6

Please sign in to comment.