Skip to content

Commit

Permalink
Fix storage backend ID for TypeInstance from nested workflow (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Kuziemko authored May 4, 2022
1 parent 5ebe084 commit dd61711
Show file tree
Hide file tree
Showing 22 changed files with 2,822 additions and 30 deletions.
3 changes: 2 additions & 1 deletion pkg/hub/client/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func (s *FileSystemClient) ListTypes(ctx context.Context, opts ...public.TypeOpt
Path: typeRev.Metadata.Path,
},
Spec: &hubpublicgraphql.TypeSpec{
JSONSchema: typeRev.Spec.JSONSchema,
JSONSchema: typeRev.Spec.JSONSchema,
AdditionalRefs: typeRev.Spec.AdditionalRefs,
},
}},
})
Expand Down
14 changes: 12 additions & 2 deletions pkg/sdk/renderer/argo/dedicated_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func (r *dedicatedRenderer) RenderTemplateSteps(ctx context.Context, workflow *W

// 3.9 Add TypeInstances to the upload graph
inputArtifacts := r.tplInputArguments[step.Template]
typeInstancesBackends, err := r.policyEnforcedCli.ListTypeInstancesBackendsBasedOnPolicy(ctx, rootimpl.Rule, rootimpl.Revision)
typeInstancesBackends, err := r.policyEnforcedCli.ListTypeInstancesBackendsBasedOnPolicy(ctx, rule, implementation)
if err != nil {
return nil, errors.Wrap(err, "while resolving TypeInstance Backend based on Policy")
}
Expand Down Expand Up @@ -982,6 +982,16 @@ func (r *dedicatedRenderer) addOutputTypeInstancesToGraph(step *WorkflowStep, pr
stepOutputBackendAlias = ptr.StringPtrToString(output.Backend)
name = addPrefix(prefix, output.From)
r.tryReplaceTypeInstanceName(output.Name, name)

for i := range mappings {
if mappings[i].Name == name {
mappings[name] = artefactNameWithBackend{
Name: output.Name,
Backend: mappings[i].Backend,
}
delete(mappings, i)
}
}
} else {
// if the TypeInstance was not defined in capact-outputTypeInstances, then just prefix it
name = addPrefix(prefix, item.TypeInstanceName)
Expand Down Expand Up @@ -1041,7 +1051,7 @@ func (r *dedicatedRenderer) addOutputTypeInstancesToGraph(step *WorkflowStep, pr
}

func (*dedicatedRenderer) selectBackendAlias(upperStep, resolvedStep string) (*string, error) {
if upperStep != "" && resolvedStep != "" {
if upperStep != "" && resolvedStep != "" && upperStep != resolvedStep {
return nil, errors.Errorf("cannot override backend on capact-outputTypeInstances")
}
for _, alias := range []string{upperStep, resolvedStep} {
Expand Down
37 changes: 37 additions & 0 deletions pkg/sdk/renderer/argo/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ import (
"capact.io/capact/pkg/sdk/apis/0.0.1/types"
)

func fixHelmStorageGlobalPolicy() policy.Policy {
return policy.Policy{
Interface: policy.InterfacePolicy{
Default: &policy.InterfaceDefault{
Inject: &policy.DefaultInject{
RequiredTypeInstances: []policy.RequiredTypeInstanceToInject{
{
TypeInstanceReference: policy.TypeInstanceReference{
ID: "a35a0c04-6153-4fe9-8d49-9ec35a0e86e",
Description: ptr.String("Helm release"),
},
},
{
TypeInstanceReference: policy.TypeInstanceReference{
ID: "b1fcdf4c-f3e3-4b90-ba37-f8ca40c620e2",
Description: ptr.String("Helm template"),
},
},
},
},
},
Rules: policy.InterfaceRulesList{
{
Interface: types.ManifestRefWithOptRevision{
Path: "cap.*",
},
OneOf: []policy.Rule{
{
ImplementationConstraints: policy.ImplementationConstraints{},
},
},
},
},
},
}
}

func fixGCPGlobalPolicy() policy.Policy {
return policy.Policy{
Interface: policy.InterfacePolicy{
Expand Down
10 changes: 10 additions & 0 deletions pkg/sdk/renderer/argo/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ func TestRenderHappyPathWithCustomPolicies(t *testing.T) {
userParameterCollection types.ParametersCollection
policy policy.Policy
}{
{
name: "Mattermost workflow with storage backends",
ref: types.InterfaceRef{
Path: "cap.interface.productivity.mattermost.install",
},
userParameterCollection: types.ParametersCollection{
"input-parameters": `{"host":"mattermost.local"}`,
},
policy: fixHelmStorageGlobalPolicy(),
},
{
name: "Mattermost with CloudSQL PostgreSQL installation with GCP SA injected",
ref: types.InterfaceRef{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ args:
name: inject-runner-context-step
template: inject-runner-context
- - arguments: {}
name: inject-input-type-instances-2-0-step
template: inject-input-type-instances-2-0
name: inject-input-type-instances-3-0-step
template: inject-input-type-instances-3-0
- - arguments: {}
name: populate-input-parameters-step
template: populate-input-parameters
Expand Down Expand Up @@ -258,7 +258,7 @@ args:
resources: {}
inputs: {}
metadata: {}
name: inject-input-type-instances-2-0
name: inject-input-type-instances-3-0
outputs:
artifacts:
- globalName: gcp-sa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ args:
name: rds-instance
steps:
- - arguments: {}
name: inject-input-type-instances-5-0-step
template: inject-input-type-instances-5-0
name: inject-input-type-instances-6-0-step
template: inject-input-type-instances-6-0
- - arguments:
artifacts:
- from: '{{inputs.artifacts.input-parameters}}'
Expand Down Expand Up @@ -869,7 +869,7 @@ args:
resources: {}
inputs: {}
metadata: {}
name: inject-input-type-instances-5-0
name: inject-input-type-instances-6-0
outputs:
artifacts:
- globalName: aws-credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ args:
name: postgresql
steps:
- - arguments: {}
name: inject-input-type-instances-0-0-step
template: inject-input-type-instances-0-0
name: inject-input-type-instances-1-0-step
template: inject-input-type-instances-1-0
- - arguments:
artifacts:
- from: '{{inputs.artifacts.input-parameters}}'
Expand Down Expand Up @@ -592,7 +592,7 @@ args:
resources: {}
inputs: {}
metadata: {}
name: inject-input-type-instances-0-0
name: inject-input-type-instances-1-0
outputs:
artifacts:
- globalName: gcp-sa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ args:
name: postgresql
steps:
- - arguments: {}
name: inject-input-type-instances-4-0-step
template: inject-input-type-instances-4-0
name: inject-input-type-instances-5-0-step
template: inject-input-type-instances-5-0
- - arguments:
artifacts:
- from: '{{inputs.artifacts.input-parameters}}'
Expand Down Expand Up @@ -653,7 +653,7 @@ args:
resources: {}
inputs: {}
metadata: {}
name: inject-input-type-instances-4-0
name: inject-input-type-instances-5-0
outputs:
artifacts:
- globalName: gcp-sa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,14 +950,14 @@ args:
outputs: {}
steps:
- - arguments: {}
name: inject-input-type-instances-1-1-step
template: inject-input-type-instances-1-1
name: inject-input-type-instances-2-1-step
template: inject-input-type-instances-2-1
- - arguments: {}
name: inject-runner-context-step
template: inject-runner-context
- - arguments: {}
name: inject-input-type-instances-1-0-step
template: inject-input-type-instances-1-0
name: inject-input-type-instances-2-0-step
template: inject-input-type-instances-2-0
- - arguments: {}
name: populate-input-parameters-step
template: populate-input-parameters
Expand Down Expand Up @@ -1072,7 +1072,7 @@ args:
resources: {}
inputs: {}
metadata: {}
name: inject-input-type-instances-1-0
name: inject-input-type-instances-2-0
outputs:
artifacts:
- globalName: postgresql
Expand Down Expand Up @@ -1122,7 +1122,7 @@ args:
resources: {}
inputs: {}
metadata: {}
name: inject-input-type-instances-1-1
name: inject-input-type-instances-2-1
outputs:
artifacts:
- globalName: postgresql
Expand Down
Loading

0 comments on commit dd61711

Please sign in to comment.