Skip to content

Commit

Permalink
chore(pkger): refactor return values for Apply/DryRun to enable exten…
Browse files Browse the repository at this point in the history
…ding it

references: #17997
  • Loading branch information
jsteenb2 committed May 28, 2020
1 parent dd69b5f commit 5e7b03b
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 174 deletions.
12 changes: 6 additions & 6 deletions cmd/influx/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ func (b *cmdPkgBuilder) pkgApplyRunEFn(cmd *cobra.Command, args []string) error
pkger.ApplyWithStackID(stackID),
}

drySum, diff, err := svc.DryRun(context.Background(), influxOrgID, 0, pkg, opts...)
dryRunImpact, err := svc.DryRun(context.Background(), influxOrgID, 0, pkg, opts...)
if err != nil {
return err
}

providedSecrets := mapKeys(drySum.MissingSecrets, b.applyOpts.secrets)
providedSecrets := mapKeys(dryRunImpact.Summary.MissingSecrets, b.applyOpts.secrets)
if !isTTY {
const skipDefault = "$$skip-this-key$$"
for _, secretKey := range missingValKeys(providedSecrets) {
Expand All @@ -170,7 +170,7 @@ func (b *cmdPkgBuilder) pkgApplyRunEFn(cmd *cobra.Command, args []string) error
}
}

if err := b.printPkgDiff(diff); err != nil {
if err := b.printPkgDiff(dryRunImpact.Diff); err != nil {
return err
}

Expand All @@ -183,18 +183,18 @@ func (b *cmdPkgBuilder) pkgApplyRunEFn(cmd *cobra.Command, args []string) error
}
}

if b.applyOpts.force != "conflict" && isTTY && diff.HasConflicts() {
if b.applyOpts.force != "conflict" && isTTY && dryRunImpact.Diff.HasConflicts() {
return errors.New("package has conflicts with existing resources and cannot safely apply")
}

opts = append(opts, pkger.ApplyWithSecrets(providedSecrets))

summary, _, err := svc.Apply(context.Background(), influxOrgID, 0, pkg, opts...)
impact, err := svc.Apply(context.Background(), influxOrgID, 0, pkg, opts...)
if err != nil {
return err
}

b.printPkgSummary(summary)
b.printPkgSummary(impact.Summary)

return nil
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/influx/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ func testPkgWritesToBuffer(newCmdFn func(w io.Writer) *cobra.Command, args pkgFi
type fakePkgSVC struct {
initStackFn func(ctx context.Context, userID influxdb.ID, stack pkger.Stack) (pkger.Stack, error)
createFn func(ctx context.Context, setters ...pkger.CreatePkgSetFn) (*pkger.Pkg, error)
dryRunFn func(ctx context.Context, orgID, userID influxdb.ID, pkg *pkger.Pkg) (pkger.Summary, pkger.Diff, error)
applyFn func(ctx context.Context, orgID, userID influxdb.ID, pkg *pkger.Pkg, opts ...pkger.ApplyOptFn) (pkger.Summary, pkger.Diff, error)
dryRunFn func(ctx context.Context, orgID, userID influxdb.ID, pkg *pkger.Pkg) (pkger.PkgImpactSummary, error)
applyFn func(ctx context.Context, orgID, userID influxdb.ID, pkg *pkger.Pkg, opts ...pkger.ApplyOptFn) (pkger.PkgImpactSummary, error)
}

var _ pkger.SVC = (*fakePkgSVC)(nil)
Expand All @@ -736,14 +736,14 @@ func (f *fakePkgSVC) CreatePkg(ctx context.Context, setters ...pkger.CreatePkgSe
panic("not implemented")
}

func (f *fakePkgSVC) DryRun(ctx context.Context, orgID, userID influxdb.ID, pkg *pkger.Pkg, opts ...pkger.ApplyOptFn) (pkger.Summary, pkger.Diff, error) {
func (f *fakePkgSVC) DryRun(ctx context.Context, orgID, userID influxdb.ID, pkg *pkger.Pkg, opts ...pkger.ApplyOptFn) (pkger.PkgImpactSummary, error) {
if f.dryRunFn != nil {
return f.dryRunFn(ctx, orgID, userID, pkg)
}
panic("not implemented")
}

func (f *fakePkgSVC) Apply(ctx context.Context, orgID, userID influxdb.ID, pkg *pkger.Pkg, opts ...pkger.ApplyOptFn) (pkger.Summary, pkger.Diff, error) {
func (f *fakePkgSVC) Apply(ctx context.Context, orgID, userID influxdb.ID, pkg *pkger.Pkg, opts ...pkger.ApplyOptFn) (pkger.PkgImpactSummary, error) {
if f.applyFn != nil {
return f.applyFn(ctx, orgID, userID, pkg, opts...)
}
Expand Down
Loading

0 comments on commit 5e7b03b

Please sign in to comment.