Skip to content

Commit

Permalink
[sdk/nodejs] Avoid circular dependencies in modules (#1558)
Browse files Browse the repository at this point in the history
We had a circular dependency due to the `./yaml` module importing the full root module.  This led to issues like #1422.  At least in the specific case that triggered that error - we do not need to introduce the cycle.

Fixes #1422.

Co-authored-by: Levi Blackstone <levi@pulumi.com>
  • Loading branch information
Luke Hoban and lblackstone authored May 3, 2021
1 parent 6731fdd commit 6393d3a
Show file tree
Hide file tree
Showing 5 changed files with 581 additions and 549 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (Unreleased)

- Avoid circular dependencies in NodeJS SDK modules (https://github.com/pulumi/pulumi-kubernetes/pull/1558)

## 3.1.0 (April 29, 2021)

- Update Helm to v3.5.4 and client-go to v0.20.4 (https://github.com/pulumi/pulumi-kubernetes/pull/1536)
Expand Down
4 changes: 4 additions & 0 deletions provider/cmd/pulumi-gen-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func writeNodeJSClient(pkg *schema.Package, outdir, templateDir string) {
}

templateResources := gen.TemplateResources{}
packages := codegen.StringSet{}
for _, resource := range resources {
if resource.Package == "" {
continue
Expand All @@ -185,10 +186,13 @@ func writeNodeJSClient(pkg *schema.Package, outdir, templateDir string) {
tr.Properties = append(tr.Properties, tp)
}
templateResources.Resources = append(templateResources.Resources, tr)
groupPackage := strings.Split(resource.Package, ".")[0]
packages.Add(groupPackage)
}
sort.Slice(templateResources.Resources, func(i, j int) bool {
return templateResources.Resources[i].Token < templateResources.Resources[j].Token
})
templateResources.Packages = packages.SortedValues()

overlays := map[string][]byte{
"apiextensions/customResource.ts": mustLoadFile(filepath.Join(templateDir, "apiextensions", "customResource.ts")),
Expand Down
12 changes: 7 additions & 5 deletions provider/pkg/gen/nodejs-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import * as pulumi from "@pulumi/pulumi";
import * as fs from "fs";
import * as glob from "glob";
import fetch from "node-fetch";
import * as k8s from "../index";
{{- range .Packages}}
import * as {{.}} from "../{{.}}";
{{- end}}
import * as outputs from "../types/output";
import { getVersion } from "../utilities";

Expand All @@ -40,8 +42,8 @@ export abstract class CollectionComponentResource extends pulumi.ComponentResour
* getResource("apps/v1/Deployment", "nginx")
*/
{{- range .Resources}}
public getResource(groupVersionKind: "{{.GVK}}", name: string): pulumi.Output<k8s.{{.Package}}.{{.Name}}>;
public getResource(groupVersionKind: "{{.GVK}}", namespace: string, name: string): pulumi.Output<k8s.{{.Package}}.{{.Name}}>;
public getResource(groupVersionKind: "{{.GVK}}", name: string): pulumi.Output<{{.Package}}.{{.Name}}>;
public getResource(groupVersionKind: "{{.GVK}}", namespace: string, name: string): pulumi.Output<{{.Package}}.{{.Name}}>;
{{- end}}
public getResource(groupVersionKind: string, namespaceOrName: string, name?: string): pulumi.Output<pulumi.CustomResource> {
return this.getResourceImpl(groupVersionKind, namespaceOrName, name);
Expand Down Expand Up @@ -517,13 +519,13 @@ export interface ConfigOpts {
case "{{.GVK}}":
return [id.apply(id => ({
name: `{{.GVK}}::${id}`,
resource: new k8s.{{.Package}}.{{.Name}}(id, obj, opts),
resource: new {{.Package}}.{{.Name}}(id, obj, opts),
}))];
{{- end}}
default:
return [id.apply(id => ({
name: `${apiVersion}/${kind}::${id}`,
resource: new k8s.apiextensions.CustomResource(id, obj, opts),
resource: new apiextensions.CustomResource(id, obj, opts),
}))];
}
}
1 change: 1 addition & 0 deletions provider/pkg/gen/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (tr TemplateResource) IsListKind() bool {
// TemplateResources holds a list of TemplateResource structs than can be filtered for codegen purposes.
type TemplateResources struct {
Resources []TemplateResource
Packages []string
}

// ListKinds returns a sorted list of resources that are a List kind.
Expand Down
Loading

0 comments on commit 6393d3a

Please sign in to comment.