Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename claims to installations #2053

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/porter/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions pkg/cnab/provider/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand All @@ -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))
}
Expand All @@ -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()
Expand Down
30 changes: 15 additions & 15 deletions pkg/cnab/provider/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
26 changes: 13 additions & 13 deletions pkg/cnab/provider/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/porter/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/porter/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
8 changes: 4 additions & 4 deletions pkg/porter/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions pkg/porter/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
48 changes: 24 additions & 24 deletions pkg/porter/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/porter/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/porter/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/porter/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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")
}
Expand Down
Loading