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

Handle multiple default providers for different packages. #650

Closed
Closed
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
6 changes: 4 additions & 2 deletions pkg/pulumiyaml/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@
}
}

var defaultProvider *ast.StringExpr
// Map of package name to default provider resource and it's key.
defaultProviders := map[string]*ast.StringExpr{}
for _, kvp := range t.Resources.Entries {
rname, r := kvp.Key.Value, kvp.Value
node := resourceNode(kvp)

// Check if the resource is a default provider
if resourceIsDefaultProvider(node) {
defaultProvider = node.key()
pkg := strings.Split(node.Value.Type.Value, ":")[2]
defaultProviders[pkg] = node.key()
}

cdiags := checkUniqueNode(intermediates, node)
Expand Down Expand Up @@ -215,10 +217,10 @@
}
}

if resourceNodeHasNoExplicitProvider(e) && defaultProvider != name {

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.x)

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.x)

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.x)

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider

Check failure on line 220 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.x)

undefined: defaultProvider
// If the resource has no explicit provider and the default provider is not set, then the
// (implicit) dependency is not yet met.
if defaultProvider != nil && !visit(defaultProvider) {

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider) (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider) (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider) (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider) (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.x)

undefined: defaultProvider

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider) (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider) (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.x)

undefined: defaultProvider

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.x)

undefined: defaultProvider

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider) (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / lint / lint

undefined: defaultProvider) (typecheck)

Check failure on line 223 in pkg/pulumiyaml/sort.go

View workflow job for this annotation

GitHub Actions / test / Test (1.21.x)

undefined: defaultProvider
return false
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/pulumiyaml/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ func TestSortUnordered(t *testing.T) {
assert.Equal(t, "my-object", names[1])
}

func TestSortMultipleDefaultProviders(t *testing.T) {
t.Parallel()

tmpl, diags, err := LoadFile("../tests/testdata/resource-ordering/Pulumi.yaml")
requireNoErrors(t, tmpl, diags)
assert.NoError(t, err)

confNodes := []configNode{}
resources, diags := topologicallySortedResources(tmpl, confNodes)
requireNoErrors(t, tmpl, diags)
names := sortedNames(resources)
assert.Len(t, names, 4)
assert.Equal(t, "provider", names[0])
assert.Equal(t, "alb", names[1])
assert.Equal(t, "testProvider", names[2])
assert.Equal(t, "echo", names[3])
}

func TestSortErrorCycle(t *testing.T) {
t.Parallel()

Expand Down
12 changes: 12 additions & 0 deletions pkg/tests/testdata/resource-ordering/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: aws-yaml
runtime: yaml
plugins:
providers:
- name: testprovider
path: ../../testprovider
resources:
alb:
type: aws:alb:LoadBalancer
Expand All @@ -10,8 +14,16 @@ resources:
subnets:
- subnet-eacf3697
- subnet-939b18f8
echo:
type: testprovider:index:Echo
provider:
defaultProvider: true
type: pulumi:providers:aws
properties:
region: us-west-2
testProvider:
defaultProvider: true
type: pulumi:providers:testprovider
properties:
testInput: ${alb.urn}

7 changes: 6 additions & 1 deletion pkg/tests/testprovider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ var providerSchema = pschema.PackageSpec{
Description: "The provider type for the testprovider package.",
Type: "object",
},
InputProperties: map[string]pschema.PropertySpec{},
InputProperties: map[string]pschema.PropertySpec{
"testInput": {
TypeSpec: pschema.TypeSpec{Type: "string"},
Description: "A test input property.",
},
},
},

Types: map[string]pschema.ComplexTypeSpec{},
Expand Down
Loading