Skip to content

Commit

Permalink
Create executev2, and we're going to have to refactor execute normal …
Browse files Browse the repository at this point in the history
…version

Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com>
  • Loading branch information
schristoff committed Oct 22, 2023
1 parent 65e18d0 commit c1b72d8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
9 changes: 9 additions & 0 deletions pkg/cnab/extended_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ func (b *ExtendedBundle) ResolveSharedDeps(bun ExtendedBundle) ([]DependencyLock

q := make([]DependencyLock, 0, len(v2.Requires))
for _, d := range v2.Requires {

//todo(schristoff): make this better?
if d.Sharing.Mode && d.Sharing.Group.Name == "" {
return nil, fmt.Errorf("dont do this")
}
if !d.Sharing.Mode && d.Sharing.Group.Name != "" {
return nil, fmt.Errorf("dont do this either")
}

lock := DependencyLock{
Alias: d.Name,
//note (schristoff): version isnt right
Expand Down
60 changes: 35 additions & 25 deletions pkg/porter/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,23 @@ func (e *dependencyExecutioner) executeDependency(ctx context.Context, dep *queu
ctx, span := tracing.StartSpan(ctx)
defer span.EndSpan()

if dep.SharingMode {
err := e.executeDependencyv2(ctx, dep)
return err
}

//todo(schristoff): Should we untie BuildPreq func from extendedbundle?
eb := cnab.ExtendedBundle{}
depName := eb.BuildPrerequisiteInstallationName(e.parentOpts.Name, dep.Alias)

//this expects depv1 style dependency to be installed as parentName+depName
depName := eb.BuildPrerequisiteInstallationName(e.parentOpts.Name, dep.Alias)
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())

//if using v2, set label for sharing group so we can find it later
if dep.SharingMode {
depInstallation.SetLabel("sh.porter.SharingGroup", dep.SharingGroup)
}
// For now, assume it's okay to give the dependency the same credentials as the parent
depInstallation.CredentialSets = e.parentInstallation.CredentialSets
if err = e.Installations.InsertInstallation(ctx, depInstallation); err != nil {
Expand All @@ -298,26 +300,6 @@ func (e *dependencyExecutioner) executeDependency(ctx context.Context, dep *queu
}
}

//If installation is found, check for v2 Sharing
if dep.SharingMode {
//unsure if this will ever happen, but just in case
if dep.SharingGroup == "" {
return fmt.Errorf("cannot resolve sharing due to empty sharing group")
}
// If it exists and they're in the same group, it'll be either installed or uninstalled
// If installed, wire things up, if uninstalled, error
if dep.SharingGroup == depInstallation.Labels["sh.porter.SharingGroup"] {
if depInstallation.Uninstalled {
return fmt.Errorf("error executing dependency, in uninstalled status %s", depInstallation.Name)
}
//note (schristoff):I think below we wire up params so the only thing needs to be tied is
// credentials maybe?
}
//If we get here, we need to call someone for help
return fmt.Errorf("how are you here?")

}

finalParams, err := e.porter.finalizeParameters(ctx, depInstallation, dep.BundleReference.Definition, e.parentArgs.Action, dep.Parameters)
if err != nil {
return span.Error(fmt.Errorf("error resolving parameters for dependency %s: %w", dep.Alias, err))
Expand Down Expand Up @@ -362,3 +344,31 @@ func (e *dependencyExecutioner) executeDependency(ctx context.Context, dep *queu
}
return nil
}

func (e *dependencyExecutioner) executeDependencyv2(ctx context.Context, dep *queuedDependency) error {
depInstallation, err := e.Installations.GetInstallation(ctx, e.parentOpts.Namespace, dep.Alias)
if err != nil {
if errors.Is(err, storage.ErrNotFound{}) {
depInstallation = storage.NewInstallation(e.parentOpts.Namespace, dep.Alias)
//tood(schristoff): not sure if we still want to have parents here
depInstallation.SetLabel("sh.porter.parentInstallation", e.parentArgs.Installation.String())
depInstallation.SetLabel("sh.porter.SharingGroup", dep.SharingGroup)

// For now, assume it's okay to give the dependency the same credentials as the parent
depInstallation.CredentialSets = e.parentInstallation.CredentialSets
if err = e.Installations.InsertInstallation(ctx, depInstallation); err != nil {
return err

}
return err
}


if dep.SharingGroup == depInstallation.Labels["sh.porter.SharingGroup"] {
if depInstallation.Uninstalled {
return fmt.Errorf("error executing dependency, in uninstalled status %s", depInstallation.Name)
}


return nil
}
2 changes: 1 addition & 1 deletion tests/integration/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func installWordpressBundle(ctx context.Context, p *porter.TestPorter) (namespac
assert.Equal(p.T(), cnab.StatusSucceeded, i.Status.ResultStatus, "the dependency wasn't recorded as being installed successfully")
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})
resolvedParameters, err := p.Sanitizer.RestoreParameterSet(ctx, c.Parameters, cnab.ExtendedBundle{Bundle: c.Bundle})
require.NoError(p.T(), err, "Resolve run failed")
assert.Equal(p.T(), "porter-ci-mysql", resolvedParameters["mysql-name"], "the dependency param value for 'mysql-name' is incorrect")
assert.Equal(p.T(), 2, resolvedParameters["probe-timeout"], "the dependency param value for 'probe-timeout' is incorrect")
Expand Down

0 comments on commit c1b72d8

Please sign in to comment.