From 71e82342e724933e750bbfe8a6848b447be952f7 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Tue, 3 May 2022 13:50:57 -0500 Subject: [PATCH] Rename claims to installations In v1 we stopped storing claims directly, which are runtime documents passed to bundles representing the current action. Instead we now store documents that better represent the installation, and a run of a bundle, using terms that we use in Porter, and not CNAB terms that were kind of misapplied over time as we evolved the data we stored. Signed-off-by: Carolyn Van Slyck --- cmd/porter/logs.go | 2 +- pkg/cnab/provider/action.go | 16 +++--- pkg/cnab/provider/helpers.go | 30 +++++------ pkg/cnab/provider/runtime.go | 26 ++++----- pkg/porter/apply.go | 2 +- pkg/porter/delete.go | 4 +- pkg/porter/delete_test.go | 8 +-- pkg/porter/dependencies.go | 16 +++--- pkg/porter/helpers.go | 48 ++++++++--------- pkg/porter/install.go | 4 +- pkg/porter/invoke.go | 2 +- pkg/porter/lifecycle.go | 4 +- pkg/porter/lifecycle_integration_test.go | 4 +- pkg/porter/list.go | 4 +- pkg/porter/list_test.go | 18 +++---- pkg/porter/logs.go | 12 ++--- pkg/porter/logs_test.go | 18 +++---- pkg/porter/outputs.go | 10 ++-- pkg/porter/outputs_test.go | 6 +-- pkg/porter/parameters.go | 2 +- pkg/porter/parameters_test.go | 52 +++++++++--------- pkg/porter/porter.go | 52 +++++++++--------- pkg/porter/reconcile.go | 4 +- pkg/porter/runs.go | 2 +- pkg/porter/runs_test.go | 22 ++++---- pkg/porter/show.go | 4 +- pkg/porter/show_test.go | 12 ++--- pkg/porter/uninstall.go | 4 +- pkg/porter/upgrade.go | 4 +- ...e_provider.go => installation_provider.go} | 4 +- ...rs.go => installation_provider_helpers.go} | 36 ++++++------- .../{claimstore.go => installation_store.go} | 54 +++++++++---------- ...ore_test.go => installation_store_test.go} | 45 ++++++++-------- pkg/storage/migrations/manager.go | 6 +-- pkg/storage/migrations/manager_test.go | 6 +-- pkg/storage/schema.go | 3 -- tests/integration/dependencies_test.go | 34 ++++++------ tests/integration/install_test.go | 2 +- tests/integration/invoke_test.go | 4 +- tests/integration/rebuild_test.go | 3 -- tests/integration/sensitive_data_test.go | 6 +-- 41 files changed, 294 insertions(+), 301 deletions(-) rename pkg/storage/{claim_storage_provider.go => installation_provider.go} (96%) rename pkg/storage/{claim_storage_provider_helpers.go => installation_provider_helpers.go} (59%) rename pkg/storage/{claimstore.go => installation_store.go} (76%) rename pkg/storage/{claimstore_test.go => installation_store_test.go} (90%) diff --git a/cmd/porter/logs.go b/cmd/porter/logs.go index 6cd349cd0..b82d979a7 100644 --- a/cmd/porter/logs.go +++ b/cmd/porter/logs.go @@ -45,7 +45,7 @@ Either display the logs from a specific run of a bundle with --run, or use --ins "Namespace in which the installation is defined. Defaults to the global namespace.") f.StringVarP(&opts.Name, "installation", "i", "", "The installation that generated the logs.") - f.StringVarP(&opts.ClaimID, "run", "r", "", + f.StringVarP(&opts.RunID, "run", "r", "", "The bundle run that generated the logs.") return cmd diff --git a/pkg/cnab/provider/action.go b/pkg/cnab/provider/action.go index 3513984d5..9dd8dded0 100644 --- a/pkg/cnab/provider/action.go +++ b/pkg/cnab/provider/action.go @@ -72,7 +72,7 @@ func (r *Runtime) AddFiles(ctx context.Context, args ActionArguments) cnabaction } // Add claim.json to file list as well, if exists - claim, err := r.claims.GetLastRun(ctx, args.Installation.Namespace, args.Installation.Name) + claim, err := r.installations.GetLastRun(ctx, args.Installation.Namespace, args.Installation.Name) if err == nil { claimBytes, err := json.Marshal(claim) if err != nil { @@ -218,18 +218,18 @@ func (r *Runtime) SaveRun(ctx context.Context, installation storage.Installation // update installation record to use run id ecoded parameters instead of // installation id installation.Parameters.Parameters = run.ParameterOverrides.Parameters - err := r.claims.UpsertInstallation(ctx, installation) + err := r.installations.UpsertInstallation(ctx, installation) if err != nil { return span.Error(fmt.Errorf("error saving the installation record before executing the bundle: %w", err)) } result := run.NewResult(status) - err = r.claims.InsertRun(ctx, run) + err = r.installations.InsertRun(ctx, run) if err != nil { return span.Error(fmt.Errorf("error saving the installation run record before executing the bundle: %w", err)) } - err = r.claims.InsertResult(ctx, result) + err = r.installations.InsertResult(ctx, result) if err != nil { return span.Error(fmt.Errorf("error saving the installation status record before executing the bundle: %w", err)) } @@ -252,13 +252,13 @@ func (r *Runtime) SaveOperationResult(ctx context.Context, opResult driver.Opera var bigerr *multierror.Error bigerr = multierror.Append(bigerr, opResult.Error) - err := r.claims.InsertResult(ctx, result) + err := r.installations.InsertResult(ctx, result) if err != nil { bigerr = multierror.Append(bigerr, errors.Wrapf(err, "error adding %s result for %s run of installation %s\n%#v", result.Status, run.Action, installation, result)) } installation.ApplyResult(run, result) - err = r.claims.UpdateInstallation(ctx, installation) + err = r.installations.UpdateInstallation(ctx, installation) if err != nil { bigerr = multierror.Append(bigerr, errors.Wrapf(err, "error updating installation record for %s\n%#v", installation, installation)) } @@ -269,7 +269,7 @@ func (r *Runtime) SaveOperationResult(ctx context.Context, opResult driver.Opera if err != nil { bigerr = multierror.Append(bigerr, errors.Wrapf(err, "error sanitizing sensitive %s output for %s run of installation %s\n%#v", output.Name, run.Action, installation, output)) } - err = r.claims.InsertOutput(ctx, output) + err = r.installations.InsertOutput(ctx, output) if err != nil { bigerr = multierror.Append(bigerr, errors.Wrapf(err, "error adding %s output for %s run of installation %s\n%#v", output.Name, run.Action, installation, output)) } @@ -283,7 +283,7 @@ func (r *Runtime) SaveOperationResult(ctx context.Context, opResult driver.Opera func (r *Runtime) appendFailedResult(ctx context.Context, opErr error, run storage.Run) error { saveResult := func() error { result := run.NewResult(cnab.StatusFailed) - return r.claims.InsertResult(ctx, result) + return r.installations.InsertResult(ctx, result) } resultErr := saveResult() diff --git a/pkg/cnab/provider/helpers.go b/pkg/cnab/provider/helpers.go index 29be7a3fc..84ea423d7 100644 --- a/pkg/cnab/provider/helpers.go +++ b/pkg/cnab/provider/helpers.go @@ -20,39 +20,39 @@ var _ CNABProvider = &TestRuntime{} type TestRuntime struct { *Runtime - TestStorage storage.TestStore - TestClaims *storage.TestClaimProvider - TestCredentials *storage.TestCredentialSetProvider - TestParameters *storage.TestParameterSetProvider - TestConfig *config.TestConfig + TestStorage storage.TestStore + TestInstallations *storage.TestInstallationProvider + TestCredentials *storage.TestCredentialSetProvider + TestParameters *storage.TestParameterSetProvider + TestConfig *config.TestConfig } func NewTestRuntime(t *testing.T) *TestRuntime { tc := config.NewTestConfig(t) testStorage := storage.NewTestStore(tc) testSecrets := secrets.NewTestSecretsProvider() - testClaims := storage.NewTestClaimProviderFor(tc.TestContext.T, testStorage) + testInstallations := storage.NewTestInstallationProviderFor(tc.TestContext.T, testStorage) testCredentials := storage.NewTestCredentialProviderFor(tc.TestContext.T, testStorage, testSecrets) testParameters := storage.NewTestParameterProviderFor(tc.TestContext.T, testStorage, testSecrets) - return NewTestRuntimeFor(tc, testClaims, testCredentials, testParameters, testSecrets) + return NewTestRuntimeFor(tc, testInstallations, testCredentials, testParameters, testSecrets) } -func NewTestRuntimeFor(tc *config.TestConfig, testClaims *storage.TestClaimProvider, testCredentials *storage.TestCredentialSetProvider, testParameters *storage.TestParameterSetProvider, testSecrets secrets.Store) *TestRuntime { +func NewTestRuntimeFor(tc *config.TestConfig, testInstallations *storage.TestInstallationProvider, testCredentials *storage.TestCredentialSetProvider, testParameters *storage.TestParameterSetProvider, testSecrets secrets.Store) *TestRuntime { return &TestRuntime{ - Runtime: NewRuntime(tc.Config, testClaims, testCredentials, testSecrets, storage.NewSanitizer(testParameters, testSecrets)), - TestStorage: storage.TestStore{}, - TestClaims: testClaims, - TestCredentials: testCredentials, - TestParameters: testParameters, - TestConfig: tc, + Runtime: NewRuntime(tc.Config, testInstallations, testCredentials, testSecrets, storage.NewSanitizer(testParameters, testSecrets)), + TestStorage: storage.TestStore{}, + TestInstallations: testInstallations, + TestCredentials: testCredentials, + TestParameters: testParameters, + TestConfig: tc, } } func (t *TestRuntime) Close() error { var bigErr *multierror.Error - bigErr = multierror.Append(bigErr, t.TestClaims.Close()) + bigErr = multierror.Append(bigErr, t.TestInstallations.Close()) bigErr = multierror.Append(bigErr, t.TestCredentials.Close()) bigErr = multierror.Append(bigErr, t.TestParameters.Close()) diff --git a/pkg/cnab/provider/runtime.go b/pkg/cnab/provider/runtime.go index 9f3ce6d41..095382d59 100644 --- a/pkg/cnab/provider/runtime.go +++ b/pkg/cnab/provider/runtime.go @@ -12,22 +12,22 @@ var _ CNABProvider = &Runtime{} type Runtime struct { *config.Config - credentials storage.CredentialSetProvider - parameters storage.ParameterSetProvider - secrets secrets.Store - claims storage.ClaimProvider - sanitizer *storage.Sanitizer - Extensions cnab.ProcessedExtensions + credentials storage.CredentialSetProvider + parameters storage.ParameterSetProvider + secrets secrets.Store + installations storage.InstallationProvider + sanitizer *storage.Sanitizer + Extensions cnab.ProcessedExtensions } -func NewRuntime(c *config.Config, claims storage.ClaimProvider, credentials storage.CredentialSetProvider, secrets secrets.Store, sanitizer *storage.Sanitizer) *Runtime { +func NewRuntime(c *config.Config, installations storage.InstallationProvider, credentials storage.CredentialSetProvider, secrets secrets.Store, sanitizer *storage.Sanitizer) *Runtime { return &Runtime{ - Config: c, - claims: claims, - credentials: credentials, - secrets: secrets, - sanitizer: sanitizer, - Extensions: cnab.ProcessedExtensions{}, + Config: c, + installations: installations, + credentials: credentials, + secrets: secrets, + sanitizer: sanitizer, + Extensions: cnab.ProcessedExtensions{}, } } diff --git a/pkg/porter/apply.go b/pkg/porter/apply.go index f7044ed08..88a12e255 100644 --- a/pkg/porter/apply.go +++ b/pkg/porter/apply.go @@ -76,7 +76,7 @@ func (p *Porter) InstallationApply(ctx context.Context, opts ApplyOptions) error return err } - installation, err := p.Claims.GetInstallation(ctx, inputInstallation.Namespace, inputInstallation.Name) + installation, err := p.Installations.GetInstallation(ctx, inputInstallation.Namespace, inputInstallation.Name) if err != nil { if !errors.Is(err, storage.ErrNotFound{}) { return errors.Wrapf(err, "could not query for an existing installation document for %s", inputInstallation) diff --git a/pkg/porter/delete.go b/pkg/porter/delete.go index bc4a2effd..1f7edae51 100644 --- a/pkg/porter/delete.go +++ b/pkg/porter/delete.go @@ -43,7 +43,7 @@ func (p *Porter) DeleteInstallation(ctx context.Context, opts DeleteOptions) err return err } - installation, err := p.Claims.GetInstallation(ctx, opts.Namespace, opts.Name) + installation, err := p.Installations.GetInstallation(ctx, opts.Namespace, opts.Name) if err != nil { return errors.Wrapf(err, "unable to read status for installation %s", opts.Name) } @@ -53,5 +53,5 @@ func (p *Porter) DeleteInstallation(ctx context.Context, opts DeleteOptions) err } fmt.Fprintf(p.Out, installationDeleteTmpl, opts.Name) - return p.Claims.RemoveInstallation(ctx, opts.Namespace, opts.Name) + return p.Installations.RemoveInstallation(ctx, opts.Namespace, opts.Name) } diff --git a/pkg/porter/delete_test.go b/pkg/porter/delete_test.go index d0374e6f2..3ef4e2bfa 100644 --- a/pkg/porter/delete_test.go +++ b/pkg/porter/delete_test.go @@ -58,9 +58,9 @@ func TestDeleteInstallation(t *testing.T) { // Create test claim if tc.lastAction != "" { - i := p.TestClaims.CreateInstallation(storage.NewInstallation("", "test")) - c := p.TestClaims.CreateRun(i.NewRun(tc.lastAction)) - _ = p.TestClaims.CreateResult(c.NewResult(tc.lastActionStatus)) + i := p.TestInstallations.CreateInstallation(storage.NewInstallation("", "test")) + c := p.TestInstallations.CreateRun(i.NewRun(tc.lastAction)) + _ = p.TestInstallations.CreateResult(c.NewResult(tc.lastActionStatus)) } opts := DeleteOptions{} @@ -75,7 +75,7 @@ func TestDeleteInstallation(t *testing.T) { require.NoError(t, err, "expected DeleteInstallation to succeed") } - _, err = p.Claims.GetInstallation(ctx, "", "test") + _, err = p.Installations.GetInstallation(ctx, "", "test") if tc.installationRemains { require.NoError(t, err, "expected installation to exist") } else { diff --git a/pkg/porter/dependencies.go b/pkg/porter/dependencies.go index 28534fef0..28a580223 100644 --- a/pkg/porter/dependencies.go +++ b/pkg/porter/dependencies.go @@ -19,9 +19,9 @@ type dependencyExecutioner struct { *config.Config porter *Porter - Resolver BundleResolver - CNAB cnabprovider.CNABProvider - Claims storage.ClaimProvider + Resolver BundleResolver + CNAB cnabprovider.CNABProvider + Installations storage.InstallationProvider parentInstallation storage.Installation parentAction BundleAction @@ -45,7 +45,7 @@ func newDependencyExecutioner(p *Porter, installation storage.Installation, acti Config: p.Config, Resolver: resolver, CNAB: p.CNAB, - Claims: p.Claims, + Installations: p.Installations, } } @@ -136,7 +136,7 @@ func (e *dependencyExecutioner) identifyDependencies(ctx context.Context) error bun = cachedBundle.Definition } else if e.parentOpts.Name != "" { - c, err := e.Claims.GetLastRun(ctx, e.parentOpts.Namespace, e.parentOpts.Name) + c, err := e.Installations.GetLastRun(ctx, e.parentOpts.Namespace, e.parentOpts.Name) if err != nil { return err } @@ -262,14 +262,14 @@ func (e *dependencyExecutioner) executeDependency(ctx context.Context, dep *queu // we want dependencies and mixins as bundles to work in the future. depName := cnab.BuildPrerequisiteInstallationName(e.parentOpts.Name, dep.Alias) - depInstallation, err := e.Claims.GetInstallation(ctx, e.parentOpts.Namespace, depName) + depInstallation, err := e.Installations.GetInstallation(ctx, e.parentOpts.Namespace, depName) if err != nil { if errors.Is(err, storage.ErrNotFound{}) { depInstallation = storage.NewInstallation(e.parentOpts.Namespace, depName) depInstallation.SetLabel("sh.porter.parentInstallation", e.parentArgs.Installation.String()) // For now, assume it's okay to give the dependency the same credentials as the parent depInstallation.CredentialSets = e.parentInstallation.CredentialSets - if err = e.Claims.InsertInstallation(ctx, depInstallation); err != nil { + if err = e.Installations.InsertInstallation(ctx, depInstallation); err != nil { return err } } else { @@ -317,7 +317,7 @@ func (e *dependencyExecutioner) executeDependency(ctx context.Context, dep *queu // will resolve to false and thus be a no-op if uninstallOpts.shouldDelete() { fmt.Fprintf(e.Out, installationDeleteTmpl, depArgs.Installation) - return e.Claims.RemoveInstallation(ctx, depArgs.Installation.Namespace, depArgs.Installation.Name) + return e.Installations.RemoveInstallation(ctx, depArgs.Installation.Namespace, depArgs.Installation.Name) } return nil } diff --git a/pkg/porter/helpers.go b/pkg/porter/helpers.go index 27d714f96..b549d523b 100644 --- a/pkg/porter/helpers.go +++ b/pkg/porter/helpers.go @@ -30,15 +30,15 @@ import ( type TestPorter struct { *Porter - TestConfig *config.TestConfig - TestStore storage.TestStore - TestClaims *storage.TestClaimProvider - TestCredentials *storage.TestCredentialSetProvider - TestParameters *storage.TestParameterSetProvider - TestCache *cache.TestCache - TestRegistry *cnabtooci.TestRegistry - TestSecrets secrets.Store - TestSanitizer *storage.Sanitizer + TestConfig *config.TestConfig + TestStore storage.TestStore + TestInstallations *storage.TestInstallationProvider + TestCredentials *storage.TestCredentialSetProvider + TestParameters *storage.TestParameterSetProvider + TestCache *cache.TestCache + TestRegistry *cnabtooci.TestRegistry + TestSecrets secrets.Store + TestSanitizer *storage.Sanitizer // original directory where the test was being executed TestDir string @@ -65,7 +65,7 @@ func NewTestPorter(t *testing.T) *TestPorter { testCredentials := storage.NewTestCredentialProviderFor(t, testStore, testSecrets) testParameters := storage.NewTestParameterProviderFor(t, testStore, testSecrets) testCache := cache.NewTestCache(cache.New(tc.Config)) - testClaims := storage.NewTestClaimProviderFor(t, testStore) + testInstallations := storage.NewTestInstallationProviderFor(t, testStore) testRegistry := cnabtooci.NewTestRegistry() p := NewFor(tc.Config, testStore, testSecrets) @@ -74,25 +74,25 @@ func NewTestPorter(t *testing.T) *TestPorter { p.Plugins = plugins.NewTestPluginProvider() p.Cache = testCache p.builder = NewTestBuildProvider() - p.Claims = testClaims + p.Installations = testInstallations p.Credentials = testCredentials p.Parameters = testParameters p.Secrets = testSecrets - p.CNAB = cnabprovider.NewTestRuntimeFor(tc, testClaims, testCredentials, testParameters, testSecrets) + p.CNAB = cnabprovider.NewTestRuntimeFor(tc, testInstallations, testCredentials, testParameters, testSecrets) p.Registry = testRegistry tp := TestPorter{ - Porter: p, - TestConfig: tc, - TestStore: testStore, - TestSecrets: testSecrets, - TestClaims: testClaims, - TestCredentials: testCredentials, - TestParameters: testParameters, - TestCache: testCache, - TestRegistry: testRegistry, - TestSanitizer: storage.NewSanitizer(testParameters, testSecrets), - RepoRoot: tc.TestContext.FindRepoRoot(), + Porter: p, + TestConfig: tc, + TestStore: testStore, + TestSecrets: testSecrets, + TestInstallations: testInstallations, + TestCredentials: testCredentials, + TestParameters: testParameters, + TestCache: testCache, + TestRegistry: testRegistry, + TestSanitizer: storage.NewSanitizer(testParameters, testSecrets), + RepoRoot: tc.TestContext.FindRepoRoot(), } // Start a tracing span for the test, so that we can capture logs @@ -241,7 +241,7 @@ func (p *TestPorter) SanitizeParameters(raw []secrets.Strategy, recordID string, } func (p *TestPorter) CreateOutput(o storage.Output, bun cnab.ExtendedBundle) storage.Output { - return p.TestClaims.CreateOutput(o, func(o *storage.Output) { + return p.TestInstallations.CreateOutput(o, func(o *storage.Output) { output, err := p.TestSanitizer.CleanOutput(context.Background(), *o, bun) require.NoError(p.T(), err) *o = output diff --git a/pkg/porter/install.go b/pkg/porter/install.go index 39126438d..d8a37abf9 100644 --- a/pkg/porter/install.go +++ b/pkg/porter/install.go @@ -63,7 +63,7 @@ func (p *Porter) InstallBundle(ctx context.Context, opts InstallOptions) error { return log.Error(err) } - i, err := p.Claims.GetInstallation(ctx, opts.Namespace, opts.Name) + i, err := p.Installations.GetInstallation(ctx, opts.Namespace, opts.Name) if err == nil { // Validate that we are not overwriting an existing installation if i.IsInstalled() && !opts.Force { @@ -84,7 +84,7 @@ func (p *Porter) InstallBundle(ctx context.Context, opts InstallOptions) error { } i.TrackBundle(bundleRef.Reference) i.Labels = opts.ParseLabels() - err = p.Claims.UpsertInstallation(ctx, i) + err = p.Installations.UpsertInstallation(ctx, i) if err != nil { return errors.Wrap(err, "error saving installation record") } diff --git a/pkg/porter/invoke.go b/pkg/porter/invoke.go index f761b4164..24795fa30 100644 --- a/pkg/porter/invoke.go +++ b/pkg/porter/invoke.go @@ -47,7 +47,7 @@ func (p *Porter) InvokeBundle(ctx context.Context, opts InvokeOptions) error { return err } - installation, err := p.Claims.GetInstallation(ctx, opts.Namespace, opts.Name) + installation, err := p.Installations.GetInstallation(ctx, opts.Namespace, opts.Name) if errors.Is(err, storage.ErrNotFound{}) { action, actionErr := bundleRef.Definition.GetAction(opts.Action) if actionErr != nil { diff --git a/pkg/porter/lifecycle.go b/pkg/porter/lifecycle.go index 09a4bf42c..edfbfde58 100644 --- a/pkg/porter/lifecycle.go +++ b/pkg/porter/lifecycle.go @@ -121,7 +121,7 @@ func (p *Porter) resolveBundleReference(ctx context.Context, opts *BundleActionO } bundleRef = cnab.BundleReference{Definition: bun} } else if opts.Name != "" { // Return the bundle associated with the installation - i, err := p.Claims.GetInstallation(ctx, opts.Namespace, opts.Name) + i, err := p.Installations.GetInstallation(ctx, opts.Namespace, opts.Name) if err != nil { return cnab.BundleReference{}, errors.Wrapf(err, "installation %s/%s not found", opts.Namespace, opts.Name) } @@ -134,7 +134,7 @@ func (p *Porter) resolveBundleReference(ctx context.Context, opts *BundleActionO return cnab.BundleReference{}, err } } else { // The bundle was installed from source - lastRun, err := p.Claims.GetLastRun(ctx, opts.Namespace, opts.Name) + lastRun, err := p.Installations.GetLastRun(ctx, opts.Namespace, opts.Name) if err != nil { return cnab.BundleReference{}, errors.Wrap(err, "could not load the bundle definition from the installation's last run") } diff --git a/pkg/porter/lifecycle_integration_test.go b/pkg/porter/lifecycle_integration_test.go index 0ef13987f..932092f57 100644 --- a/pkg/porter/lifecycle_integration_test.go +++ b/pkg/porter/lifecycle_integration_test.go @@ -74,8 +74,8 @@ func TestResolveBundleReference(t *testing.T) { p := NewTestPorter(t) defer p.Close() - i := p.TestClaims.CreateInstallation(storage.NewInstallation("dev", "example")) - p.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { + i := p.TestInstallations.CreateInstallation(storage.NewInstallation("dev", "example")) + p.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.BundleReference = kahnlatest.String() r.Bundle = buildExampleBundle() r.BundleDigest = kahnlatestHash diff --git a/pkg/porter/list.go b/pkg/porter/list.go index dc516db05..4aced87d4 100644 --- a/pkg/porter/list.go +++ b/pkg/porter/list.go @@ -60,7 +60,7 @@ func parseLabels(raw []string) map[string]string { } // DisplayInstallation holds a subset of pertinent values to be listed from installation data -// originating from its claims, results and outputs records +// originating from its runs, results and outputs records type DisplayInstallation struct { // SchemaType helps when we export the definition so editors can detect the type of document, it's not used by porter. SchemaType string `json:"schemaType" yaml:"schemaType" toml:"schemaType"` @@ -218,7 +218,7 @@ func (p *Porter) ListInstallations(ctx context.Context, opts ListOptions) ([]sto ctx, log := tracing.StartSpan(ctx) defer log.EndSpan() - installations, err := p.Claims.ListInstallations(ctx, opts.GetNamespace(), opts.Name, opts.ParseLabels()) + installations, err := p.Installations.ListInstallations(ctx, opts.GetNamespace(), opts.Name, opts.ParseLabels()) return installations, errors.Wrap(err, "could not list installations") } diff --git a/pkg/porter/list_test.go b/pkg/porter/list_test.go index d04c8081f..815ed8bf4 100644 --- a/pkg/porter/list_test.go +++ b/pkg/porter/list_test.go @@ -13,7 +13,7 @@ import ( func TestNewDisplayInstallation(t *testing.T) { t.Run("installation has been installed", func(t *testing.T) { - cp := storage.NewTestClaimProvider(t) + cp := storage.NewTestInstallationProvider(t) defer cp.Close() i := cp.CreateInstallation(storage.NewInstallation("", "wordpress"), func(i *storage.Installation) { @@ -34,7 +34,7 @@ func TestNewDisplayInstallation(t *testing.T) { }) t.Run("installation has not been installed", func(t *testing.T) { - cp := storage.NewTestClaimProvider(t) + cp := storage.NewTestInstallationProvider(t) defer cp.Close() i := cp.CreateInstallation(storage.NewInstallation("", "wordpress")) @@ -56,12 +56,12 @@ func TestPorter_ListInstallations(t *testing.T) { p := NewTestPorter(t) defer p.Close() - p.TestClaims.CreateInstallation(storage.NewInstallation("", "shared-mysql")) - p.TestClaims.CreateInstallation(storage.NewInstallation("dev", "carolyn-wordpress")) - p.TestClaims.CreateInstallation(storage.NewInstallation("dev", "vaughn-wordpress")) - p.TestClaims.CreateInstallation(storage.NewInstallation("test", "staging-wordpress")) - p.TestClaims.CreateInstallation(storage.NewInstallation("test", "iat-wordpress")) - p.TestClaims.CreateInstallation(storage.NewInstallation("test", "shared-mysql")) + p.TestInstallations.CreateInstallation(storage.NewInstallation("", "shared-mysql")) + p.TestInstallations.CreateInstallation(storage.NewInstallation("dev", "carolyn-wordpress")) + p.TestInstallations.CreateInstallation(storage.NewInstallation("dev", "vaughn-wordpress")) + p.TestInstallations.CreateInstallation(storage.NewInstallation("test", "staging-wordpress")) + p.TestInstallations.CreateInstallation(storage.NewInstallation("test", "iat-wordpress")) + p.TestInstallations.CreateInstallation(storage.NewInstallation("test", "shared-mysql")) t.Run("all-namespaces", func(t *testing.T) { opts := ListOptions{AllNamespaces: true} @@ -91,7 +91,7 @@ func TestPorter_ListInstallations(t *testing.T) { } func TestDisplayInstallation_ConvertToInstallation(t *testing.T) { - cp := storage.NewTestClaimProvider(t) + cp := storage.NewTestInstallationProvider(t) defer cp.Close() i := cp.CreateInstallation(storage.NewInstallation("", "wordpress"), func(i *storage.Installation) { diff --git a/pkg/porter/logs.go b/pkg/porter/logs.go index 8846a65f5..cb87165fc 100644 --- a/pkg/porter/logs.go +++ b/pkg/porter/logs.go @@ -11,7 +11,7 @@ import ( // LogsShowOptions represent options for an installation logs show command type LogsShowOptions struct { sharedOptions - ClaimID string + RunID string } // Installation name passed to the command. @@ -22,7 +22,7 @@ func (o *LogsShowOptions) Installation() string { // Validate validates the provided args, using the provided context, // setting attributes of LogsShowOptions as applicable func (o *LogsShowOptions) Validate(cxt *portercontext.Context) error { - if o.Name != "" && o.ClaimID != "" { + if o.Name != "" && o.RunID != "" { return errors.New("either --installation or --run should be specified, not both") } @@ -32,7 +32,7 @@ func (o *LogsShowOptions) Validate(cxt *portercontext.Context) error { return err } - if o.File == "" && o.Name == "" && o.ClaimID == "" { + if o.File == "" && o.Name == "" && o.RunID == "" { return errors.New("either --installation or --run is required") } @@ -62,9 +62,9 @@ func (p *Porter) GetInstallationLogs(ctx context.Context, opts *LogsShowOptions) } installation := opts.sharedOptions.Name - if opts.ClaimID != "" { - return p.Claims.GetLogs(ctx, opts.ClaimID) + if opts.RunID != "" { + return p.Installations.GetLogs(ctx, opts.RunID) } - return p.Claims.GetLastLogs(ctx, opts.Namespace, installation) + return p.Installations.GetLastLogs(ctx, opts.Namespace, installation) } diff --git a/pkg/porter/logs_test.go b/pkg/porter/logs_test.go index d4c370743..ee6ae5e8b 100644 --- a/pkg/porter/logs_test.go +++ b/pkg/porter/logs_test.go @@ -36,7 +36,7 @@ func TestLogsShowOptions_Validate(t *testing.T) { t.Run("run specified", func(t *testing.T) { c := portercontext.NewTestContext(t) opts := LogsShowOptions{} - opts.ClaimID = "abc123" + opts.RunID = "abc123" err := opts.Validate(c.Context) require.NoError(t, err) @@ -46,7 +46,7 @@ func TestLogsShowOptions_Validate(t *testing.T) { c := portercontext.NewTestContext(t) opts := LogsShowOptions{} opts.Name = "mybun" - opts.ClaimID = "abc123" + opts.RunID = "abc123" err := opts.Validate(c.Context) require.Error(t, err) @@ -68,9 +68,9 @@ func TestPorter_ShowInstallationLogs(t *testing.T) { p := NewTestPorter(t) defer p.Close() - i := p.TestClaims.CreateInstallation(storage.NewInstallation("", "test")) - c := p.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall)) - p.TestClaims.CreateResult(c.NewResult(cnab.StatusSucceeded)) + i := p.TestInstallations.CreateInstallation(storage.NewInstallation("", "test")) + c := p.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall)) + p.TestInstallations.CreateResult(c.NewResult(cnab.StatusSucceeded)) var opts LogsShowOptions opts.Name = "test" @@ -85,13 +85,13 @@ func TestPorter_ShowInstallationLogs(t *testing.T) { p := NewTestPorter(t) defer p.Close() - i := p.TestClaims.CreateInstallation(storage.NewInstallation("", "test")) - c := p.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall)) - r := p.TestClaims.CreateResult(c.NewResult(cnab.StatusSucceeded), func(r *storage.Result) { + i := p.TestInstallations.CreateInstallation(storage.NewInstallation("", "test")) + c := p.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall)) + r := p.TestInstallations.CreateResult(c.NewResult(cnab.StatusSucceeded), func(r *storage.Result) { r.OutputMetadata.SetGeneratedByBundle(cnab.OutputInvocationImageLogs, false) }) - p.TestClaims.CreateOutput(r.NewOutput(cnab.OutputInvocationImageLogs, []byte(testLogs))) + p.TestInstallations.CreateOutput(r.NewOutput(cnab.OutputInvocationImageLogs, []byte(testLogs))) var opts LogsShowOptions opts.Name = "test" diff --git a/pkg/porter/outputs.go b/pkg/porter/outputs.go index 6ff4e0d9f..94a852811 100644 --- a/pkg/porter/outputs.go +++ b/pkg/porter/outputs.go @@ -8,7 +8,7 @@ import ( "get.porter.sh/porter/pkg/cnab" "get.porter.sh/porter/pkg/portercontext" "get.porter.sh/porter/pkg/printer" - claims "get.porter.sh/porter/pkg/storage" + "get.porter.sh/porter/pkg/storage" "github.com/pkg/errors" ) @@ -81,7 +81,7 @@ func (p *Porter) ShowBundleOutput(ctx context.Context, opts *OutputShowOptions) return nil } -func NewDisplayValuesFromOutputs(bun cnab.ExtendedBundle, outputs claims.Outputs) DisplayValues { +func NewDisplayValuesFromOutputs(bun cnab.ExtendedBundle, outputs storage.Outputs) DisplayValues { // Iterate through all Bundle Outputs, fetch their metadata // via their corresponding Definitions and add to rows displayOutputs := make(DisplayValues, 0, outputs.Len()) @@ -120,7 +120,7 @@ func (p *Porter) ListBundleOutputs(ctx context.Context, opts *OutputListOptions) return nil, err } - outputs, err := p.Claims.GetLastOutputs(ctx, opts.Namespace, opts.Name) + outputs, err := p.Installations.GetLastOutputs(ctx, opts.Namespace, opts.Name) if err != nil { return nil, err } @@ -130,7 +130,7 @@ func (p *Porter) ListBundleOutputs(ctx context.Context, opts *OutputListOptions) return nil, err } - c, err := p.Claims.GetLastRun(ctx, opts.Namespace, opts.Name) + c, err := p.Installations.GetLastRun(ctx, opts.Namespace, opts.Name) if err != nil { return nil, err } @@ -165,7 +165,7 @@ func (p *Porter) PrintBundleOutputs(ctx context.Context, opts OutputListOptions) // ReadBundleOutput reads a bundle output from an installation func (p *Porter) ReadBundleOutput(ctx context.Context, outputName, installation, namespace string) (string, error) { - o, err := p.Claims.GetLastOutput(ctx, namespace, installation, outputName) + o, err := p.Installations.GetLastOutput(ctx, namespace, installation, outputName) if err != nil { return "", err } diff --git a/pkg/porter/outputs_test.go b/pkg/porter/outputs_test.go index 872f3b261..a4dafa131 100644 --- a/pkg/porter/outputs_test.go +++ b/pkg/porter/outputs_test.go @@ -104,14 +104,14 @@ func TestPorter_PrintBundleOutputs(t *testing.T) { } extB := cnab.ExtendedBundle{b} - i := p.TestClaims.CreateInstallation(storage.NewInstallation("", "test"), func(i *storage.Installation) { + i := p.TestInstallations.CreateInstallation(storage.NewInstallation("", "test"), func(i *storage.Installation) { i.Parameters.Parameters = p.SanitizeParameters(i.Parameters.Parameters, i.ID, extB) }) - c := p.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { + c := p.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.Bundle = b r.ParameterOverrides.Parameters = p.SanitizeParameters(r.ParameterOverrides.Parameters, r.ID, extB) }) - r := p.TestClaims.CreateResult(c.NewResult(cnab.StatusSucceeded)) + r := p.TestInstallations.CreateResult(c.NewResult(cnab.StatusSucceeded)) p.CreateOutput(r.NewOutput("foo", []byte("foo-output")), extB) p.CreateOutput(r.NewOutput("bar", []byte("bar-output")), extB) p.CreateOutput(r.NewOutput("longfoo", []byte("DFo6Wc2jDhmA7Yt4PbHyh8RO4vVG7leOzK412gf2TXNPJhuCUs1rB29nkJJd4ICimZGpyWpMGalSvDxf")), extB) diff --git a/pkg/porter/parameters.go b/pkg/porter/parameters.go index f3c6ab803..f0874ce22 100644 --- a/pkg/porter/parameters.go +++ b/pkg/porter/parameters.go @@ -642,7 +642,7 @@ func (p *Porter) resolveParameterSources(ctx context.Context, bun cnab.ExtendedB outputName = source.OutputName } - output, err := p.Claims.GetLastOutput(ctx, installation.Namespace, installationName, outputName) + output, err := p.Installations.GetLastOutput(ctx, installation.Namespace, installationName, outputName) if err != nil { // When we can't find the output, skip it and let the parameter be set another way if errors.Is(err, storage.ErrNotFound{}) { diff --git a/pkg/porter/parameters_test.go b/pkg/porter/parameters_test.go index 3faa5f97b..9186e4ddd 100644 --- a/pkg/porter/parameters_test.go +++ b/pkg/porter/parameters_test.go @@ -352,10 +352,10 @@ func Test_loadParameters_ParameterSourcePrecedence(t *testing.T) { b, err := cnab.LoadBundle(r.Context, "bundle.json") require.NoError(t, err, "ProcessBundle failed") - i := r.TestClaims.CreateInstallation(storage.NewInstallation("", "mybun")) - c := r.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.Bundle = b.Bundle }) - cr := r.TestClaims.CreateResult(c.NewResult(cnab.StatusSucceeded)) - r.TestClaims.CreateOutput(cr.NewOutput("foo", []byte("foo_source"))) + i := r.TestInstallations.CreateInstallation(storage.NewInstallation("", "mybun")) + c := r.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.Bundle = b.Bundle }) + cr := r.TestInstallations.CreateResult(c.NewResult(cnab.StatusSucceeded)) + r.TestInstallations.CreateOutput(cr.NewOutput("foo", []byte("foo_source"))) params, err := r.resolveParameters(context.Background(), i, b, cnab.ActionUpgrade, nil) require.NoError(t, err) @@ -380,10 +380,10 @@ func Test_loadParameters_ParameterSourcePrecedence(t *testing.T) { "foo": "foo_override", } - i := r.TestClaims.CreateInstallation(storage.NewInstallation("", "mybun")) - c := r.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall)) - cr := r.TestClaims.CreateResult(c.NewResult(cnab.StatusSucceeded)) - r.TestClaims.CreateOutput(cr.NewOutput("foo", []byte("foo_source"))) + i := r.TestInstallations.CreateInstallation(storage.NewInstallation("", "mybun")) + c := r.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall)) + cr := r.TestInstallations.CreateResult(c.NewResult(cnab.StatusSucceeded)) + r.TestInstallations.CreateOutput(cr.NewOutput("foo", []byte("foo_source"))) params, err := r.resolveParameters(context.Background(), i, b, cnab.ActionUpgrade, overrides) require.NoError(t, err) @@ -404,10 +404,10 @@ func Test_loadParameters_ParameterSourcePrecedence(t *testing.T) { b, err := cnab.LoadBundle(r.Context, "bundle.json") require.NoError(t, err, "ProcessBundle failed") - i := r.TestClaims.CreateInstallation(storage.NewInstallation("", "mybun-mysql")) - c := r.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.Bundle = b.Bundle }) - cr := r.TestClaims.CreateResult(c.NewResult(cnab.StatusSucceeded)) - r.TestClaims.CreateOutput(cr.NewOutput("connstr", []byte("connstr value"))) + i := r.TestInstallations.CreateInstallation(storage.NewInstallation("", "mybun-mysql")) + c := r.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.Bundle = b.Bundle }) + cr := r.TestInstallations.CreateResult(c.NewResult(cnab.StatusSucceeded)) + r.TestInstallations.CreateOutput(cr.NewOutput("connstr", []byte("connstr value"))) params, err := r.resolveParameters(context.Background(), i, b, cnab.ActionUpgrade, nil) require.NoError(t, err) @@ -431,12 +431,12 @@ func Test_loadParameters_ParameterSourcePrecedence(t *testing.T) { // foo is set by a user // bar is set by a parameter source // baz is set by the bundle default - i := r.TestClaims.CreateInstallation(storage.NewInstallation("", "mybun")) - c := r.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall)) - cr := r.TestClaims.CreateResult(c.NewResult(cnab.StatusSucceeded)) - r.TestClaims.CreateOutput(cr.NewOutput("foo", []byte("foo_source"))) - r.TestClaims.CreateOutput(cr.NewOutput("bar", []byte("bar_source"))) - r.TestClaims.CreateOutput(cr.NewOutput("baz", []byte("baz_source"))) + i := r.TestInstallations.CreateInstallation(storage.NewInstallation("", "mybun")) + c := r.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall)) + cr := r.TestInstallations.CreateResult(c.NewResult(cnab.StatusSucceeded)) + r.TestInstallations.CreateOutput(cr.NewOutput("foo", []byte("foo_source"))) + r.TestInstallations.CreateOutput(cr.NewOutput("bar", []byte("bar_source"))) + r.TestInstallations.CreateOutput(cr.NewOutput("baz", []byte("baz_source"))) overrides := map[string]string{"foo": "foo_override"} params, err := r.resolveParameters(context.Background(), i, b, cnab.ActionUpgrade, overrides) @@ -601,15 +601,15 @@ func TestRuntime_ResolveParameterSources(t *testing.T) { bun, err := cnab.LoadBundle(r.Context, "bundle.json") require.NoError(t, err, "ProcessBundle failed") - i := r.TestClaims.CreateInstallation(storage.NewInstallation("", "mybun-mysql")) - c := r.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.Bundle = bun.Bundle }) - cr := r.TestClaims.CreateResult(c.NewResult(cnab.StatusSucceeded)) - r.TestClaims.CreateOutput(cr.NewOutput("connstr", []byte("connstr value"))) + i := r.TestInstallations.CreateInstallation(storage.NewInstallation("", "mybun-mysql")) + c := r.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.Bundle = bun.Bundle }) + cr := r.TestInstallations.CreateResult(c.NewResult(cnab.StatusSucceeded)) + r.TestInstallations.CreateOutput(cr.NewOutput("connstr", []byte("connstr value"))) - i = r.TestClaims.CreateInstallation(storage.NewInstallation("", "mybun")) - c = r.TestClaims.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.Bundle = bun.Bundle }) - cr = r.TestClaims.CreateResult(c.NewResult(cnab.StatusSucceeded)) - r.TestClaims.CreateOutput(cr.NewOutput("bar", []byte("bar value"))) + i = r.TestInstallations.CreateInstallation(storage.NewInstallation("", "mybun")) + c = r.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall), func(r *storage.Run) { r.Bundle = bun.Bundle }) + cr = r.TestInstallations.CreateResult(c.NewResult(cnab.StatusSucceeded)) + r.TestInstallations.CreateOutput(cr.NewOutput("bar", []byte("bar value"))) got, err := r.resolveParameterSources(context.Background(), bun, i) require.NoError(t, err, "resolveParameterSources failed") diff --git a/pkg/porter/porter.go b/pkg/porter/porter.go index 3d91e5a97..ad6499ea3 100644 --- a/pkg/porter/porter.go +++ b/pkg/porter/porter.go @@ -33,18 +33,18 @@ type Porter struct { // or to switch it out for tests. builder build.Builder - Cache cache.BundleCache - Credentials storage.CredentialSetProvider - Parameters storage.ParameterSetProvider - Sanitizer *storage.Sanitizer - Claims storage.ClaimProvider - Registry cnabtooci.RegistryProvider - Templates *templates.Templates - Mixins mixin.MixinProvider - Plugins plugins.PluginProvider - CNAB cnabprovider.CNABProvider - Secrets secrets.Store - Storage storage.Provider + Cache cache.BundleCache + Credentials storage.CredentialSetProvider + Parameters storage.ParameterSetProvider + Sanitizer *storage.Sanitizer + Installations storage.InstallationProvider + Registry cnabtooci.RegistryProvider + Templates *templates.Templates + Mixins mixin.MixinProvider + Plugins plugins.PluginProvider + CNAB cnabprovider.CNABProvider + Secrets secrets.Store + Storage storage.Provider } // New porter client, initialized with useful defaults. @@ -59,24 +59,24 @@ func NewFor(c *config.Config, store storage.Store, secretStorage secrets.Store) cache := cache.New(c) storageManager := migrations.NewManager(c, store) - claimStorage := storage.NewClaimStore(storageManager) + installationStorage := storage.NewInstallationStore(storageManager) credStorage := storage.NewCredentialStore(storageManager, secretStorage) paramStorage := storage.NewParameterStore(storageManager, secretStorage) sanitizerService := storage.NewSanitizer(paramStorage, secretStorage) return &Porter{ - Config: c, - Cache: cache, - Storage: storageManager, - Claims: claimStorage, - Credentials: credStorage, - Parameters: paramStorage, - Secrets: secretStorage, - Registry: cnabtooci.NewRegistry(c.Context), - Templates: templates.NewTemplates(c), - Mixins: mixin.NewPackageManager(c), - Plugins: plugins.NewPackageManager(c), - CNAB: cnabprovider.NewRuntime(c, claimStorage, credStorage, secretStorage, sanitizerService), - Sanitizer: sanitizerService, + Config: c, + Cache: cache, + Storage: storageManager, + Installations: installationStorage, + Credentials: credStorage, + Parameters: paramStorage, + Secrets: secretStorage, + Registry: cnabtooci.NewRegistry(c.Context), + Templates: templates.NewTemplates(c), + Mixins: mixin.NewPackageManager(c), + Plugins: plugins.NewPackageManager(c), + CNAB: cnabprovider.NewRuntime(c, installationStorage, credStorage, secretStorage, sanitizerService), + Sanitizer: sanitizerService, } } diff --git a/pkg/porter/reconcile.go b/pkg/porter/reconcile.go index 7acccef1e..39856ac87 100644 --- a/pkg/porter/reconcile.go +++ b/pkg/porter/reconcile.go @@ -41,7 +41,7 @@ func (p *Porter) ReconcileInstallation(ctx context.Context, opts ReconcileOption // Get the last run of the installation, if available var lastRun *storage.Run - r, err := p.Claims.GetLastRun(ctx, opts.Namespace, opts.Name) + r, err := p.Installations.GetLastRun(ctx, opts.Namespace, opts.Name) neverRun := errors.Is(err, storage.ErrNotFound{}) if err != nil && !neverRun { return err @@ -95,7 +95,7 @@ func (p *Porter) ReconcileInstallation(ctx context.Context, opts ReconcileOption } if !opts.DryRun { - if err = p.Claims.UpsertInstallation(ctx, opts.Installation); err != nil { + if err = p.Installations.UpsertInstallation(ctx, opts.Installation); err != nil { return err } } diff --git a/pkg/porter/runs.go b/pkg/porter/runs.go index 6e6019e57..9779a915b 100644 --- a/pkg/porter/runs.go +++ b/pkg/porter/runs.go @@ -54,7 +54,7 @@ func (p *Porter) ListInstallationRuns(ctx context.Context, opts RunListOptions) var displayRuns DisplayRuns - runs, runResults, err := p.Claims.ListRuns(ctx, opts.Namespace, opts.Name) + runs, runResults, err := p.Installations.ListRuns(ctx, opts.Namespace, opts.Name) if err != nil { return nil, err } diff --git a/pkg/porter/runs_test.go b/pkg/porter/runs_test.go index 561a161d6..d36c8d02a 100644 --- a/pkg/porter/runs_test.go +++ b/pkg/porter/runs_test.go @@ -23,8 +23,8 @@ func TestPorter_ListInstallationRuns(t *testing.T) { run1.NewResult("running") run1.NewResult("succeeded") - p.TestClaims.CreateInstallation(storage.NewInstallation("", installationName1), p.TestClaims.SetMutableInstallationValues) - p.TestClaims.CreateRun(run1) + p.TestInstallations.CreateInstallation(storage.NewInstallation("", installationName1), p.TestInstallations.SetMutableInstallationValues) + p.TestInstallations.CreateRun(run1) installationName2 := "shared-k8s" @@ -34,9 +34,9 @@ func TestPorter_ListInstallationRuns(t *testing.T) { run3 := storage.NewRun("dev", installationName2) run3.NewResult("running") - p.TestClaims.CreateInstallation(storage.NewInstallation("dev", installationName2), p.TestClaims.SetMutableInstallationValues) - p.TestClaims.CreateRun(run2) - p.TestClaims.CreateRun(run3) + p.TestInstallations.CreateInstallation(storage.NewInstallation("dev", installationName2), p.TestInstallations.SetMutableInstallationValues) + p.TestInstallations.CreateRun(run2) + p.TestInstallations.CreateRun(run3) t.Run("global namespace", func(t *testing.T) { opts := RunListOptions{sharedOptions: sharedOptions{ @@ -75,18 +75,18 @@ func TestPorter_PrintInstallationRunsOutput(t *testing.T) { defer p.Close() ctx := context.Background() - installation := p.TestClaims.CreateInstallation(storage.NewInstallation("staging", "shared-k8s"), p.TestClaims.SetMutableInstallationValues) + installation := p.TestInstallations.CreateInstallation(storage.NewInstallation("staging", "shared-k8s"), p.TestInstallations.SetMutableInstallationValues) - installRun := p.TestClaims.CreateRun(installation.NewRun(cnab.ActionInstall), p.TestClaims.SetMutableRunValues) - uninstallRun := p.TestClaims.CreateRun(installation.NewRun(cnab.ActionUninstall), p.TestClaims.SetMutableRunValues) - result := p.TestClaims.CreateResult(installRun.NewResult(cnab.StatusSucceeded), p.TestClaims.SetMutableResultValues) - result2 := p.TestClaims.CreateResult(uninstallRun.NewResult(cnab.StatusSucceeded), p.TestClaims.SetMutableResultValues) + installRun := p.TestInstallations.CreateRun(installation.NewRun(cnab.ActionInstall), p.TestInstallations.SetMutableRunValues) + uninstallRun := p.TestInstallations.CreateRun(installation.NewRun(cnab.ActionUninstall), p.TestInstallations.SetMutableRunValues) + result := p.TestInstallations.CreateResult(installRun.NewResult(cnab.StatusSucceeded), p.TestInstallations.SetMutableResultValues) + result2 := p.TestInstallations.CreateResult(uninstallRun.NewResult(cnab.StatusSucceeded), p.TestInstallations.SetMutableResultValues) installation.ApplyResult(installRun, result) installation.ApplyResult(uninstallRun, result2) installation.Status.Installed = &now - require.NoError(t, p.TestClaims.UpdateInstallation(ctx, installation)) + require.NoError(t, p.TestInstallations.UpdateInstallation(ctx, installation)) opts := RunListOptions{sharedOptions: sharedOptions{ Namespace: "staging", diff --git a/pkg/porter/show.go b/pkg/porter/show.go index c184fba6c..71b3548f0 100644 --- a/pkg/porter/show.go +++ b/pkg/porter/show.go @@ -47,7 +47,7 @@ func (p *Porter) GetInstallation(ctx context.Context, opts ShowOptions) (storage return storage.Installation{}, err } - installation, err := p.Claims.GetInstallation(ctx, opts.Namespace, opts.Name) + installation, err := p.Installations.GetInstallation(ctx, opts.Namespace, opts.Name) if err != nil { return storage.Installation{}, err } @@ -164,7 +164,7 @@ func (p *Porter) ShowInstallation(ctx context.Context, opts ShowOptions) error { } func (p *Porter) generateDisplayInstallation(ctx context.Context, installation storage.Installation) (DisplayInstallation, error) { - run, err := p.Claims.GetRun(ctx, installation.Status.RunID) + run, err := p.Installations.GetRun(ctx, installation.Status.RunID) if err != nil { return DisplayInstallation{}, err } diff --git a/pkg/porter/show_test.go b/pkg/porter/show_test.go index bf16e6c0a..be0471ae8 100644 --- a/pkg/porter/show_test.go +++ b/pkg/porter/show_test.go @@ -44,7 +44,7 @@ func TestPorter_ShowBundle(t *testing.T) { }, } - // Create test claims + // Create test runs writeOnly := true b := bundle.Bundle{ Name: "wordpress", @@ -84,7 +84,7 @@ func TestPorter_ShowBundle(t *testing.T) { } bun := cnab.ExtendedBundle{b} - i := p.TestClaims.CreateInstallation(storage.NewInstallation("dev", "mywordpress"), p.TestClaims.SetMutableInstallationValues, func(i *storage.Installation) { + i := p.TestInstallations.CreateInstallation(storage.NewInstallation("dev", "mywordpress"), p.TestInstallations.SetMutableInstallationValues, func(i *storage.Installation) { if tc.ref != "" { i.TrackBundle(cnab.MustParseOCIReference(tc.ref)) } @@ -103,7 +103,7 @@ func TestPorter_ShowBundle(t *testing.T) { i.Parameters.Parameters = p.SanitizeParameters(i.Parameters.Parameters, i.ID, bun) }) - run := p.TestClaims.CreateRun(i.NewRun(cnab.ActionUpgrade), p.TestClaims.SetMutableRunValues, func(r *storage.Run) { + run := p.TestInstallations.CreateRun(i.NewRun(cnab.ActionUpgrade), p.TestInstallations.SetMutableRunValues, func(r *storage.Run) { r.Bundle = b r.BundleReference = tc.ref r.BundleDigest = "sha256:88d68ef0bdb9cedc6da3a8e341a33e5d2f8bb19d0cf7ec3f1060d3f9eb73cae9" @@ -126,14 +126,14 @@ func TestPorter_ShowBundle(t *testing.T) { }) i.Parameters.Parameters = run.ParameterOverrides.Parameters - err := p.TestClaims.UpsertInstallation(context.Background(), i) + err := p.TestInstallations.UpsertInstallation(context.Background(), i) require.NoError(t, err) - result := p.TestClaims.CreateResult(run.NewResult(cnab.StatusSucceeded), p.TestClaims.SetMutableResultValues) + result := p.TestInstallations.CreateResult(run.NewResult(cnab.StatusSucceeded), p.TestInstallations.SetMutableResultValues) i.ApplyResult(run, result) i.Status.Installed = &now ctx := context.Background() - require.NoError(t, p.TestClaims.UpdateInstallation(ctx, i)) + require.NoError(t, p.TestInstallations.UpdateInstallation(ctx, i)) err = p.ShowInstallation(ctx, opts) require.NoError(t, err, "ShowInstallation failed") diff --git a/pkg/porter/uninstall.go b/pkg/porter/uninstall.go index 1fd18f01c..6b48d2596 100644 --- a/pkg/porter/uninstall.go +++ b/pkg/porter/uninstall.go @@ -78,7 +78,7 @@ func (p *Porter) UninstallBundle(ctx context.Context, opts UninstallOptions) err return err } - installation, err := p.Claims.GetInstallation(ctx, opts.Namespace, opts.Name) + installation, err := p.Installations.GetInstallation(ctx, opts.Namespace, opts.Name) if err != nil { return errors.Wrapf(err, "could not find installation %s/%s", opts.Namespace, opts.Name) } @@ -131,7 +131,7 @@ func (p *Porter) UninstallBundle(ctx context.Context, opts UninstallOptions) err if opts.shouldDelete() { log.Info("deleting installation records") - return p.Claims.RemoveInstallation(ctx, opts.Namespace, opts.Name) + return p.Installations.RemoveInstallation(ctx, opts.Namespace, opts.Name) } return nil } diff --git a/pkg/porter/upgrade.go b/pkg/porter/upgrade.go index e688cb11c..522b3578f 100644 --- a/pkg/porter/upgrade.go +++ b/pkg/porter/upgrade.go @@ -58,7 +58,7 @@ func (p *Porter) UpgradeBundle(ctx context.Context, opts UpgradeOptions) error { } // Sync any changes specified by the user to the installation before running upgrade - i, err := p.Claims.GetInstallation(ctx, opts.Namespace, opts.Name) + i, err := p.Installations.GetInstallation(ctx, opts.Namespace, opts.Name) if err != nil { return errors.Wrapf(err, "could not find installation %s/%s", opts.Namespace, opts.Name) } @@ -77,7 +77,7 @@ func (p *Porter) UpgradeBundle(ctx context.Context, opts UpgradeOptions) error { if err != nil { return err } - err = p.Claims.UpdateInstallation(ctx, i) + err = p.Installations.UpdateInstallation(ctx, i) if err != nil { return err } diff --git a/pkg/storage/claim_storage_provider.go b/pkg/storage/installation_provider.go similarity index 96% rename from pkg/storage/claim_storage_provider.go rename to pkg/storage/installation_provider.go index eb210fb79..75957ccd8 100644 --- a/pkg/storage/claim_storage_provider.go +++ b/pkg/storage/installation_provider.go @@ -4,8 +4,8 @@ import ( "context" ) -// ClaimProvider is an interface for interacting with Porter's claim data. -type ClaimProvider interface { +// InstallationProvider is an interface for interacting with Porter's claim data. +type InstallationProvider interface { // InsertInstallation saves a new Installation document. InsertInstallation(ctx context.Context, installation Installation) error diff --git a/pkg/storage/claim_storage_provider_helpers.go b/pkg/storage/installation_provider_helpers.go similarity index 59% rename from pkg/storage/claim_storage_provider_helpers.go rename to pkg/storage/installation_provider_helpers.go index fe91e5c36..f9ef0423e 100644 --- a/pkg/storage/claim_storage_provider_helpers.go +++ b/pkg/storage/installation_provider_helpers.go @@ -11,7 +11,7 @@ import ( ) var ( - _ ClaimProvider = TestClaimProvider{} + _ InstallationProvider = TestInstallationProvider{} // A fixed now timestamp that we can use for comparisons in tests now = time.Date(2020, time.April, 18, 1, 2, 3, 4, time.UTC) @@ -19,33 +19,33 @@ var ( installationID = "01FZVC5AVP8Z7A78CSCP1EJ604" ) -type TestClaimProvider struct { - ClaimStore +type TestInstallationProvider struct { + InstallationStore TestStore t *testing.T idCounter uint } -func NewTestClaimProvider(t *testing.T) *TestClaimProvider { +func NewTestInstallationProvider(t *testing.T) *TestInstallationProvider { tc := config.NewTestConfig(t) testStore := NewTestStore(tc) - return NewTestClaimProviderFor(t, testStore) + return NewTestInstallationProviderFor(t, testStore) } -func NewTestClaimProviderFor(t *testing.T, testStore TestStore) *TestClaimProvider { - return &TestClaimProvider{ - t: t, - TestStore: testStore, - ClaimStore: NewClaimStore(testStore), +func NewTestInstallationProviderFor(t *testing.T, testStore TestStore) *TestInstallationProvider { + return &TestInstallationProvider{ + t: t, + TestStore: testStore, + InstallationStore: NewInstallationStore(testStore), } } -func (p *TestClaimProvider) Close() error { +func (p *TestInstallationProvider) Close() error { return p.TestStore.Close() } // CreateInstallation creates a new test installation and saves it. -func (p *TestClaimProvider) CreateInstallation(i Installation, transformations ...func(i *Installation)) Installation { +func (p *TestInstallationProvider) CreateInstallation(i Installation, transformations ...func(i *Installation)) Installation { for _, transform := range transformations { transform(&i) } @@ -55,14 +55,14 @@ func (p *TestClaimProvider) CreateInstallation(i Installation, transformations . return i } -func (p *TestClaimProvider) SetMutableInstallationValues(i *Installation) { +func (p *TestInstallationProvider) SetMutableInstallationValues(i *Installation) { i.ID = installationID i.Status.Created = now i.Status.Modified = now } // CreateRun creates a new claim and saves it. -func (p *TestClaimProvider) CreateRun(r Run, transformations ...func(r *Run)) Run { +func (p *TestInstallationProvider) CreateRun(r Run, transformations ...func(r *Run)) Run { for _, transform := range transformations { transform(&r) } @@ -72,14 +72,14 @@ func (p *TestClaimProvider) CreateRun(r Run, transformations ...func(r *Run)) Ru return r } -func (p *TestClaimProvider) SetMutableRunValues(r *Run) { +func (p *TestInstallationProvider) SetMutableRunValues(r *Run) { p.idCounter += 1 r.ID = fmt.Sprintf("%d", p.idCounter) r.Created = now } // CreateResult creates a new result from the specified claim and saves it. -func (p *TestClaimProvider) CreateResult(r Result, transformations ...func(r *Result)) Result { +func (p *TestInstallationProvider) CreateResult(r Result, transformations ...func(r *Result)) Result { for _, transform := range transformations { transform(&r) } @@ -89,14 +89,14 @@ func (p *TestClaimProvider) CreateResult(r Result, transformations ...func(r *Re return r } -func (p *TestClaimProvider) SetMutableResultValues(r *Result) { +func (p *TestInstallationProvider) SetMutableResultValues(r *Result) { p.idCounter += 1 r.ID = fmt.Sprintf("%d", p.idCounter) r.Created = now } // CreateOutput creates a new output from the specified claim and result and saves it. -func (p *TestClaimProvider) CreateOutput(o Output, transformations ...func(o *Output)) Output { +func (p *TestInstallationProvider) CreateOutput(o Output, transformations ...func(o *Output)) Output { for _, transform := range transformations { transform(&o) } diff --git a/pkg/storage/claimstore.go b/pkg/storage/installation_store.go similarity index 76% rename from pkg/storage/claimstore.go rename to pkg/storage/installation_store.go index e27e412ac..338f1d18a 100644 --- a/pkg/storage/claimstore.go +++ b/pkg/storage/installation_store.go @@ -15,26 +15,26 @@ const ( CollectionOutputs = "outputs" ) -var _ ClaimProvider = ClaimStore{} +var _ InstallationProvider = InstallationStore{} -// ClaimStore is a persistent store for claims. -type ClaimStore struct { +// InstallationStore is a persistent store for installation documents. +type InstallationStore struct { store Store encrypt EncryptionHandler decrypt EncryptionHandler } -// NewClaimStore creates a persistent store for claims using the specified +// NewInstallationStore creates a persistent store for installations using the specified // backing datastore. -func NewClaimStore(datastore Store) ClaimStore { - return ClaimStore{ +func NewInstallationStore(datastore Store) InstallationStore { + return InstallationStore{ store: datastore, encrypt: noOpEncryptionHandler, decrypt: noOpEncryptionHandler, } } -func (s ClaimStore) Initialize(ctx context.Context) error { +func (s InstallationStore) Initialize(ctx context.Context) error { ctx, span := tracing.StartSpan(ctx) defer span.EndSpan() @@ -63,7 +63,7 @@ func (s ClaimStore) Initialize(ctx context.Context) error { return span.Error(err) } -func (s ClaimStore) ListInstallations(ctx context.Context, namespace string, name string, labels map[string]string) ([]Installation, error) { +func (s InstallationStore) ListInstallations(ctx context.Context, namespace string, name string, labels map[string]string) ([]Installation, error) { _, log := tracing.StartSpan(ctx) defer log.EndSpan() @@ -77,7 +77,7 @@ func (s ClaimStore) ListInstallations(ctx context.Context, namespace string, nam return out, err } -func (s ClaimStore) ListRuns(ctx context.Context, namespace string, installation string) ([]Run, map[string][]Result, error) { +func (s InstallationStore) ListRuns(ctx context.Context, namespace string, installation string) ([]Run, map[string][]Result, error) { var runs []Run var err error var results []Result @@ -114,7 +114,7 @@ func (s ClaimStore) ListRuns(ctx context.Context, namespace string, installation return runs, resultsMap, err } -func (s ClaimStore) ListResults(ctx context.Context, runID string) ([]Result, error) { +func (s InstallationStore) ListResults(ctx context.Context, runID string) ([]Result, error) { var out []Result opts := FindOptions{ Sort: []string{"_id"}, @@ -126,7 +126,7 @@ func (s ClaimStore) ListResults(ctx context.Context, runID string) ([]Result, er return out, err } -func (s ClaimStore) ListOutputs(ctx context.Context, resultID string) ([]Output, error) { +func (s InstallationStore) ListOutputs(ctx context.Context, resultID string) ([]Output, error) { var out []Output opts := FindOptions{ Sort: []string{"resultId", "name"}, @@ -138,7 +138,7 @@ func (s ClaimStore) ListOutputs(ctx context.Context, resultID string) ([]Output, return out, err } -func (s ClaimStore) GetInstallation(ctx context.Context, namespace string, name string) (Installation, error) { +func (s InstallationStore) GetInstallation(ctx context.Context, namespace string, name string) (Installation, error) { var out Installation opts := FindOptions{ @@ -151,21 +151,21 @@ func (s ClaimStore) GetInstallation(ctx context.Context, namespace string, name return out, err } -func (s ClaimStore) GetRun(ctx context.Context, id string) (Run, error) { +func (s InstallationStore) GetRun(ctx context.Context, id string) (Run, error) { var out Run opts := GetOptions{ID: id} err := s.store.Get(ctx, CollectionRuns, opts, &out) return out, err } -func (s ClaimStore) GetResult(ctx context.Context, id string) (Result, error) { +func (s InstallationStore) GetResult(ctx context.Context, id string) (Result, error) { var out Result opts := GetOptions{ID: id} err := s.store.Get(ctx, CollectionResults, opts, &out) return out, err } -func (s ClaimStore) GetLastRun(ctx context.Context, namespace string, installation string) (Run, error) { +func (s InstallationStore) GetLastRun(ctx context.Context, namespace string, installation string) (Run, error) { var out []Run opts := FindOptions{ Sort: []string{"-_id"}, @@ -185,7 +185,7 @@ func (s ClaimStore) GetLastRun(ctx context.Context, namespace string, installati return out[0], err } -func (s ClaimStore) GetLastOutput(ctx context.Context, namespace string, installation string, name string) (Output, error) { +func (s InstallationStore) GetLastOutput(ctx context.Context, namespace string, installation string, name string) (Output, error) { var out Output opts := FindOptions{ Sort: []string{"-_id"}, @@ -200,7 +200,7 @@ func (s ClaimStore) GetLastOutput(ctx context.Context, namespace string, install return out, err } -func (s ClaimStore) GetLastOutputs(ctx context.Context, namespace string, installation string) (Outputs, error) { +func (s InstallationStore) GetLastOutputs(ctx context.Context, namespace string, installation string) (Outputs, error) { var groupedOutputs []struct { ID string `json:"_id"` LastOutput Output `json:"lastOutput"` @@ -236,7 +236,7 @@ func (s ClaimStore) GetLastOutputs(ctx context.Context, namespace string, instal return NewOutputs(lastOutputs), err } -func (s ClaimStore) GetLogs(ctx context.Context, runID string) (string, bool, error) { +func (s InstallationStore) GetLogs(ctx context.Context, runID string) (string, bool, error) { var out Output opts := FindOptions{ Sort: []string{"resultId"}, // get logs from the last result for a run @@ -253,7 +253,7 @@ func (s ClaimStore) GetLogs(ctx context.Context, runID string) (string, bool, er return string(out.Value), err == nil, err } -func (s ClaimStore) GetLastLogs(ctx context.Context, namespace string, installation string) (string, bool, error) { +func (s InstallationStore) GetLastLogs(ctx context.Context, namespace string, installation string) (string, bool, error) { var out Output opts := FindOptions{ Sort: []string{"-resultId"}, // get logs from the last result for a run @@ -271,7 +271,7 @@ func (s ClaimStore) GetLastLogs(ctx context.Context, namespace string, installat return string(out.Value), err == nil, err } -func (s ClaimStore) InsertInstallation(ctx context.Context, installation Installation) error { +func (s InstallationStore) InsertInstallation(ctx context.Context, installation Installation) error { installation.SchemaVersion = InstallationSchemaVersion opts := InsertOptions{ Documents: []interface{}{installation}, @@ -279,28 +279,28 @@ func (s ClaimStore) InsertInstallation(ctx context.Context, installation Install return s.store.Insert(ctx, CollectionInstallations, opts) } -func (s ClaimStore) InsertRun(ctx context.Context, run Run) error { +func (s InstallationStore) InsertRun(ctx context.Context, run Run) error { opts := InsertOptions{ Documents: []interface{}{run}, } return s.store.Insert(ctx, CollectionRuns, opts) } -func (s ClaimStore) InsertResult(ctx context.Context, result Result) error { +func (s InstallationStore) InsertResult(ctx context.Context, result Result) error { opts := InsertOptions{ Documents: []interface{}{result}, } return s.store.Insert(ctx, CollectionResults, opts) } -func (s ClaimStore) InsertOutput(ctx context.Context, output Output) error { +func (s InstallationStore) InsertOutput(ctx context.Context, output Output) error { opts := InsertOptions{ Documents: []interface{}{output}, } return s.store.Insert(ctx, CollectionOutputs, opts) } -func (s ClaimStore) UpdateInstallation(ctx context.Context, installation Installation) error { +func (s InstallationStore) UpdateInstallation(ctx context.Context, installation Installation) error { installation.SchemaVersion = InstallationSchemaVersion opts := UpdateOptions{ Document: installation, @@ -308,7 +308,7 @@ func (s ClaimStore) UpdateInstallation(ctx context.Context, installation Install return s.store.Update(ctx, CollectionInstallations, opts) } -func (s ClaimStore) UpsertRun(ctx context.Context, run Run) error { +func (s InstallationStore) UpsertRun(ctx context.Context, run Run) error { opts := UpdateOptions{ Upsert: true, Document: run, @@ -316,7 +316,7 @@ func (s ClaimStore) UpsertRun(ctx context.Context, run Run) error { return s.store.Update(ctx, CollectionRuns, opts) } -func (s ClaimStore) UpsertInstallation(ctx context.Context, installation Installation) error { +func (s InstallationStore) UpsertInstallation(ctx context.Context, installation Installation) error { installation.SchemaVersion = InstallationSchemaVersion opts := UpdateOptions{ Upsert: true, @@ -326,7 +326,7 @@ func (s ClaimStore) UpsertInstallation(ctx context.Context, installation Install } // RemoveInstallation and all associated data. -func (s ClaimStore) RemoveInstallation(ctx context.Context, namespace string, name string) error { +func (s InstallationStore) RemoveInstallation(ctx context.Context, namespace string, name string) error { removeInstallation := RemoveOptions{ Filter: bson.M{ "namespace": namespace, diff --git a/pkg/storage/claimstore_test.go b/pkg/storage/installation_store_test.go similarity index 90% rename from pkg/storage/claimstore_test.go rename to pkg/storage/installation_store_test.go index a49d19a11..ae6f05753 100644 --- a/pkg/storage/claimstore_test.go +++ b/pkg/storage/installation_store_test.go @@ -8,12 +8,11 @@ import ( "get.porter.sh/porter/pkg/cnab" "github.com/cnabio/cnab-go/bundle" "github.com/cnabio/cnab-go/bundle/definition" - cnabclaims "github.com/cnabio/cnab-go/claim" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -var _ ClaimProvider = ClaimStore{} +var _ InstallationProvider = InstallationStore{} var b64encode = func(src []byte) ([]byte, error) { dst := make([]byte, base64.StdEncoding.EncodedLen(len(src))) @@ -39,10 +38,10 @@ var exampleBundle = bundle.Bundle{ }, } -// generateClaimData creates test claims, results and outputs -// it returns a claim Provider, and a test cleanup function. +// generateInstallationData creates test installations, runs, results and outputs +// it returns a InstallationStorageProvider, and a test cleanup function. // -// claims/ +// installations/ // foo/ // CLAIM_ID_1 (install) // CLAIM_ID_2 (upgrade) @@ -75,8 +74,8 @@ var exampleBundle = bundle.Bundle{ // RESULT_ID_2/ // RESULT_ID_2_OUTPUT_1 // RESULT_ID_2_OUTPUT_2 -func generateClaimData(t *testing.T) *TestClaimProvider { - cp := NewTestClaimProvider(t) +func generateInstallationData(t *testing.T) *TestInstallationProvider { + cp := NewTestInstallationProvider(t) bun := bundle.Bundle{ Definitions: map[string]*definition.Schema{ @@ -104,12 +103,12 @@ func generateClaimData(t *testing.T) *TestClaimProvider { foo := cp.CreateInstallation(NewInstallation("dev", "foo")) run := cp.CreateRun(foo.NewRun(cnab.ActionInstall), setBun) result := cp.CreateResult(run.NewResult(cnab.StatusSucceeded)) - cp.CreateOutput(result.NewOutput(cnabclaims.OutputInvocationImageLogs, []byte("install logs"))) + cp.CreateOutput(result.NewOutput(cnab.OutputInvocationImageLogs, []byte("install logs"))) cp.CreateOutput(result.NewOutput("output1", []byte("install output1"))) run = cp.CreateRun(foo.NewRun(cnab.ActionUpgrade), setBun) result = cp.CreateResult(run.NewResult(cnab.StatusSucceeded)) - cp.CreateOutput(result.NewOutput(cnabclaims.OutputInvocationImageLogs, []byte("upgrade logs"))) + cp.CreateOutput(result.NewOutput(cnab.OutputInvocationImageLogs, []byte("upgrade logs"))) cp.CreateOutput(result.NewOutput("output1", []byte("upgrade output1"))) cp.CreateOutput(result.NewOutput("output2", []byte("upgrade output2"))) // Test bug in how we read output names by having the name include characters from the result id @@ -149,8 +148,8 @@ func generateClaimData(t *testing.T) *TestClaimProvider { return cp } -func TestClaimStore_Installations(t *testing.T) { - cp := generateClaimData(t) +func TestInstallationStorageProvider_Installations(t *testing.T) { + cp := generateInstallationData(t) defer cp.Close() t.Run("ListInstallations", func(t *testing.T) { @@ -187,8 +186,8 @@ func TestClaimStore_Installations(t *testing.T) { } -func TestClaimStore_DeleteInstallation(t *testing.T) { - cp := generateClaimData(t) +func TestInstallationStorageProvider_DeleteInstallation(t *testing.T) { + cp := generateInstallationData(t) defer cp.Close() installations, err := cp.ListInstallations(context.Background(), "dev", "", nil) @@ -206,12 +205,12 @@ func TestClaimStore_DeleteInstallation(t *testing.T) { require.ErrorIs(t, err, ErrNotFound{}) } -func TestClaimStore_Run(t *testing.T) { - cp := generateClaimData(t) +func TestInstallationStorageProvider_Run(t *testing.T) { + cp := generateInstallationData(t) t.Run("ListRuns", func(t *testing.T) { runs, resultsMap, err := cp.ListRuns(context.Background(), "dev", "foo") - require.NoError(t, err, "Failed to read claims: %s", err) + require.NoError(t, err, "Failed to read bundle runs: %s", err) require.Len(t, runs, 4, "Expected 4 runs") require.Len(t, resultsMap, 4, "Results expected to have 4 runs") @@ -233,7 +232,7 @@ func TestClaimStore_Run(t *testing.T) { runs, _, err := cp.ListRuns(context.Background(), "dev", "foo") require.NoError(t, err, "ListRuns failed") - assert.NotEmpty(t, runs, "no claims were found") + assert.NotEmpty(t, runs, "no runs were found") runID := runs[0].ID c, err := cp.GetRun(context.Background(), runID) @@ -262,8 +261,8 @@ func TestClaimStore_Run(t *testing.T) { }) } -func TestClaimStore_Results(t *testing.T) { - cp := generateClaimData(t) +func TestInstallationStorageProvider_Results(t *testing.T) { + cp := generateInstallationData(t) defer cp.Close() barRuns, resultsMap, err := cp.ListRuns(context.Background(), "dev", "bar") @@ -297,8 +296,8 @@ func TestClaimStore_Results(t *testing.T) { }) } -func TestClaimStore_Outputs(t *testing.T) { - cp := generateClaimData(t) +func TestInstallationStorageProvider_Outputs(t *testing.T) { + cp := generateInstallationData(t) defer cp.Close() fooRuns, _, err := cp.ListRuns(context.Background(), "dev", "foo") @@ -312,7 +311,7 @@ func TestClaimStore_Outputs(t *testing.T) { resultID := fooResult.ID // this result has an output barRuns, _, err := cp.ListRuns(context.Background(), "dev", "bar") - require.NoError(t, err, "ReadAllClaims failed") + require.NoError(t, err, "ListRuns failed") require.Len(t, barRuns, 1, "expected bar to have a run") barRun := barRuns[0] barResults, err := cp.ListResults(context.Background(), barRun.ID) @@ -327,7 +326,7 @@ func TestClaimStore_Outputs(t *testing.T) { assert.Len(t, outputs, 4, "expected 2 outputs") assert.Equal(t, outputs[0].Name, resultID+"-output3") - assert.Equal(t, outputs[1].Name, cnabclaims.OutputInvocationImageLogs) + assert.Equal(t, outputs[1].Name, cnab.OutputInvocationImageLogs) assert.Equal(t, outputs[2].Name, "output1") assert.Equal(t, outputs[3].Name, "output2") }) diff --git a/pkg/storage/migrations/manager.go b/pkg/storage/migrations/manager.go index 3b5f43df1..22bdd6578 100644 --- a/pkg/storage/migrations/manager.go +++ b/pkg/storage/migrations/manager.go @@ -31,8 +31,8 @@ type Manager struct { *config.Config // The underlying storage managed by this instance. It - // shouldn't be used for typed read/access the data, for that use the ClaimsProvider - // or CredentialSetProvider which works with the Storage.Manager. + // shouldn't be used for typed read/access the data, for that storage.InstallationStorageProvider + // or storage.CredentialSetProvider which works with the Manager. store storage.Store // initialized specifies if we have loaded the schema document. @@ -83,7 +83,7 @@ Once your data has been backed up, run the following command to perform the migr m.initialized = true - cs := storage.NewClaimStore(m.store) + cs := storage.NewInstallationStore(m.store) err := cs.Initialize(ctx) if err != nil { return err diff --git a/pkg/storage/migrations/manager_test.go b/pkg/storage/migrations/manager_test.go index 2db9173e9..bd1631034 100644 --- a/pkg/storage/migrations/manager_test.go +++ b/pkg/storage/migrations/manager_test.go @@ -59,7 +59,7 @@ func TestManager_NoMigrationEmptyHome(t *testing.T) { mgr := NewTestManager(config) defer mgr.Close() - claimStore := storage.NewClaimStore(mgr) + claimStore := storage.NewInstallationStore(mgr) _, err := claimStore.ListInstallations(context.Background(), "", "", nil) require.NoError(t, err, "ListInstallations failed") @@ -79,7 +79,7 @@ func TestClaimStorage_HaltOnMigrationRequired(t *testing.T) { tc := config.NewTestConfig(t) mgr := NewTestManager(tc) defer mgr.Close() - claimStore := storage.NewClaimStore(mgr) + claimStore := storage.NewInstallationStore(mgr) schema := storage.NewSchema() schema.Installations = "needs-migration" @@ -110,7 +110,7 @@ func TestClaimStorage_NoMigrationRequiredForEmptyHome(t *testing.T) { mgr := NewTestManager(config) defer mgr.Close() - claimStore := storage.NewClaimStore(mgr) + claimStore := storage.NewInstallationStore(mgr) names, err := claimStore.ListInstallations(context.Background(), "", "", nil) require.NoError(t, err, "ListInstallations failed") diff --git a/pkg/storage/schema.go b/pkg/storage/schema.go index 604e5a21e..71ee07051 100644 --- a/pkg/storage/schema.go +++ b/pkg/storage/schema.go @@ -26,9 +26,6 @@ type Schema struct { // Installations is the schema for the installation documents. Installations schema.Version `json:"installations"` - // Claims is the schema for the old CNAB claim spec. DEPRECATED. - Claims schema.Version `json:"claims,omitempty"` - // Credentials is the schema for the credential spec documents. Credentials schema.Version `json:"credentials"` diff --git a/tests/integration/dependencies_test.go b/tests/integration/dependencies_test.go index c78642445..2d71f88af 100644 --- a/tests/integration/dependencies_test.go +++ b/tests/integration/dependencies_test.go @@ -94,10 +94,10 @@ func installWordpressBundle(p *porter.TestPorter) (namespace string) { require.NoError(p.T(), err, "install of root bundle failed namespace %s", namespace) // Verify that the dependency claim is present - i, err := p.Claims.GetInstallation(ctx, namespace, "wordpress-mysql") + i, err := p.Installations.GetInstallation(ctx, namespace, "wordpress-mysql") require.NoError(p.T(), err, "could not fetch installation status for the dependency") assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the dependency wasn't recorded as being installed successfully") - c, err := p.Claims.GetLastRun(ctx, namespace, i.Name) + c, err := p.Installations.GetLastRun(ctx, namespace, i.Name) require.NoError(p.T(), err, "GetLastRun failed") resolvedParameters, err := p.Sanitizer.RestoreParameterSet(ctx, c.Parameters, cnab.ExtendedBundle{c.Bundle}) require.NoError(p.T(), err, "Resolve run failed") @@ -107,7 +107,7 @@ func installWordpressBundle(p *porter.TestPorter) (namespace string) { // TODO(carolynvs): compare with last parameters set on the installation once we start tracking that // Verify that the bundle claim is present - i, err = p.Claims.GetInstallation(ctx, namespace, "wordpress") + i, err = p.Installations.GetInstallation(ctx, namespace, "wordpress") require.NoError(p.T(), err, "could not fetch claim for the root bundle") assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the root bundle wasn't recorded as being installed successfully") @@ -128,12 +128,12 @@ func cleanupWordpressBundle(p *porter.TestPorter, namespace string) { require.NoError(p.T(), err, "uninstall of root bundle failed") // Verify that the dependency installation is deleted - i, err := p.Claims.GetInstallation(ctx, namespace, "wordpress-mysql") + i, err := p.Installations.GetInstallation(ctx, namespace, "wordpress-mysql") require.ErrorIs(p.T(), err, storage.ErrNotFound{}) require.Equal(p.T(), storage.Installation{}, i) // Verify that the root installation is deleted - i, err = p.Claims.GetInstallation(ctx, namespace, "wordpress") + i, err = p.Installations.GetInstallation(ctx, namespace, "wordpress") require.ErrorIs(p.T(), err, storage.ErrNotFound{}) require.Equal(p.T(), storage.Installation{}, i) } @@ -156,17 +156,17 @@ func upgradeWordpressBundle(p *porter.TestPorter, namespace string) { require.NoError(p.T(), err, "upgrade of root bundle failed") // Verify that the dependency claim is upgraded - i, err := p.Claims.GetInstallation(ctx, namespace, "wordpress-mysql") + i, err := p.Installations.GetInstallation(ctx, namespace, "wordpress-mysql") require.NoError(p.T(), err, "could not fetch claim for the dependency") - c, err := p.Claims.GetLastRun(ctx, i.Namespace, i.Name) + c, err := p.Installations.GetLastRun(ctx, i.Namespace, i.Name) require.NoError(p.T(), err, "GetLastClaim failed") assert.Equal(p.T(), cnab.ActionUpgrade, c.Action, "the dependency wasn't recorded as being upgraded") assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the dependency wasn't recorded as being upgraded successfully") // Verify that the bundle claim is upgraded - i, err = p.Claims.GetInstallation(ctx, namespace, "wordpress") + i, err = p.Installations.GetInstallation(ctx, namespace, "wordpress") require.NoError(p.T(), err, "could not fetch claim for the root bundle") - c, err = p.Claims.GetLastRun(ctx, i.Namespace, i.Name) + c, err = p.Installations.GetLastRun(ctx, i.Namespace, i.Name) require.NoError(p.T(), err, "GetLastClaim failed") assert.Equal(p.T(), cnab.ActionUpgrade, c.Action, "the root bundle wasn't recorded as being upgraded") assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the root bundle wasn't recorded as being upgraded successfully") @@ -189,17 +189,17 @@ func invokeWordpressBundle(p *porter.TestPorter, namespace string) { require.NoError(p.T(), err, "invoke of root bundle failed") // Verify that the dependency claim is invoked - i, err := p.Claims.GetInstallation(ctx, namespace, "wordpress-mysql") + i, err := p.Installations.GetInstallation(ctx, namespace, "wordpress-mysql") require.NoError(p.T(), err, "could not fetch claim for the dependency") - c, err := p.Claims.GetLastRun(ctx, i.Namespace, i.Name) + c, err := p.Installations.GetLastRun(ctx, i.Namespace, i.Name) require.NoError(p.T(), err, "GetLastClaim failed") assert.Equal(p.T(), "ping", c.Action, "the dependency wasn't recorded as being invoked") assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the dependency wasn't recorded as being invoked successfully") // Verify that the bundle claim is invoked - i, err = p.Claims.GetInstallation(ctx, namespace, "wordpress") + i, err = p.Installations.GetInstallation(ctx, namespace, "wordpress") require.NoError(p.T(), err, "could not fetch claim for the root bundle") - c, err = p.Claims.GetLastRun(ctx, i.Namespace, i.Name) + c, err = p.Installations.GetLastRun(ctx, i.Namespace, i.Name) require.NoError(p.T(), err, "GetLastClaim failed") assert.Equal(p.T(), "ping", c.Action, "the root bundle wasn't recorded as being invoked") assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the root bundle wasn't recorded as being invoked successfully") @@ -221,17 +221,17 @@ func uninstallWordpressBundle(p *porter.TestPorter, namespace string) { require.NoError(p.T(), err, "uninstall of root bundle failed") // Verify that the dependency claim is uninstalled - i, err := p.Claims.GetInstallation(ctx, namespace, "wordpress-mysql") + i, err := p.Installations.GetInstallation(ctx, namespace, "wordpress-mysql") require.NoError(p.T(), err, "could not fetch installation for the dependency") - c, err := p.Claims.GetLastRun(ctx, i.Namespace, i.Name) + c, err := p.Installations.GetLastRun(ctx, i.Namespace, i.Name) require.NoError(p.T(), err, "GetLastClaim failed") assert.Equal(p.T(), cnab.ActionUninstall, c.Action, "the dependency wasn't recorded as being uninstalled") assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the dependency wasn't recorded as being uninstalled successfully") // Verify that the bundle claim is uninstalled - i, err = p.Claims.GetInstallation(ctx, namespace, "wordpress") + i, err = p.Installations.GetInstallation(ctx, namespace, "wordpress") require.NoError(p.T(), err, "could not fetch installation for the root bundle") - c, err = p.Claims.GetLastRun(ctx, i.Namespace, i.Name) + c, err = p.Installations.GetLastRun(ctx, i.Namespace, i.Name) require.NoError(p.T(), err, "GetLastClaim failed") assert.Equal(p.T(), cnab.ActionUninstall, c.Action, "the root bundle wasn't recorded as being uninstalled") assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the root bundle wasn't recorded as being uninstalled successfully") diff --git a/tests/integration/install_test.go b/tests/integration/install_test.go index 4297d0b64..504234c85 100644 --- a/tests/integration/install_test.go +++ b/tests/integration/install_test.go @@ -77,7 +77,7 @@ func TestInstall_fileParam(t *testing.T) { output := p.TestConfig.TestContext.GetOutput() require.Contains(t, output, "Hello World!", "expected action output to contain provided file contents") - outputs, err := p.Claims.GetLastOutputs(ctx, "", bundleName) + outputs, err := p.Installations.GetLastOutputs(ctx, "", bundleName) require.NoError(t, err, "GetLastOutput failed") myfile, ok := outputs.GetByName("myfile") require.True(t, ok, "expected myfile output to be persisted") diff --git a/tests/integration/invoke_test.go b/tests/integration/invoke_test.go index 089f9acbc..7dc6c968d 100644 --- a/tests/integration/invoke_test.go +++ b/tests/integration/invoke_test.go @@ -45,9 +45,9 @@ func TestInvokeCustomAction(t *testing.T) { assert.Contains(t, gotOutput, "oh noes my brains", "invoke should have printed a cry for halp") // Verify that the custom action was recorded properly - i, err := p.Claims.GetInstallation(ctx, "", bundleName) + i, err := p.Installations.GetInstallation(ctx, "", bundleName) require.NoError(t, err, "could not fetch installation") - c, err := p.Claims.GetLastRun(ctx, i.Namespace, i.Name) + c, err := p.Installations.GetLastRun(ctx, i.Namespace, i.Name) require.NoError(t, err, "GetLastClaim failed") assert.Equal(t, "zombies", c.Action, "the custom action wasn't recorded in the installation") } diff --git a/tests/integration/rebuild_test.go b/tests/integration/rebuild_test.go index afc137a01..b058d7167 100644 --- a/tests/integration/rebuild_test.go +++ b/tests/integration/rebuild_test.go @@ -73,9 +73,6 @@ func TestRebuild_UpgradeModifiedBundle(t *testing.T) { gotOutput := p.TestConfig.TestContext.GetOutput() buildCount := strings.Count(gotOutput, "Building bundle ===>") assert.Equal(t, 2, buildCount, "expected a rebuild before upgrade") - - // Verify that the bundle's version matches the updated version in the porter.yaml - // TODO: separate ListBundle's printing from fetching claims } func TestRebuild_GenerateCredentialsNewBundle(t *testing.T) { diff --git a/tests/integration/sensitive_data_test.go b/tests/integration/sensitive_data_test.go index b2b625080..2a898186d 100644 --- a/tests/integration/sensitive_data_test.go +++ b/tests/integration/sensitive_data_test.go @@ -34,10 +34,10 @@ func TestSensitiveData(t *testing.T) { err = p.InstallBundle(ctx, installOpts) require.NoError(t, err) - i, err := p.Claims.GetInstallation(ctx, installOpts.Namespace, installOpts.Name) + i, err := p.Installations.GetInstallation(ctx, installOpts.Namespace, installOpts.Name) require.NoError(t, err) - run, err := p.Claims.GetRun(ctx, i.Status.RunID) + run, err := p.Installations.GetRun(ctx, i.Status.RunID) require.NoError(t, err) for _, param := range i.Parameters.Parameters { @@ -57,7 +57,7 @@ func TestSensitiveData(t *testing.T) { } } - outputs, err := p.Claims.GetLastOutputs(ctx, "", bundleName) + outputs, err := p.Installations.GetLastOutputs(ctx, "", bundleName) require.NoError(t, err, "GetLastOutput failed") mylogs, ok := outputs.GetByName("mylogs") require.True(t, ok, "expected mylogs output to be persisted")