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

Split up nodejs SDK into multiple files #480

Merged
merged 6 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

### Improvements

- None
- Split up nodejs SDK into multiple files (https://github.com/pulumi/pulumi-kubernetes/pull/480)

### Bug fixes

- Check for unexpected RPC ID and return an error (https://github.com/pulumi/pulumi-kubernetes/pull/475)

- Fix an issue where the Python `pulumi_kubernetes` package was depending on an older `pulumi` package.

## 0.21.0 (Released March 6, 2019)
Expand Down
41 changes: 40 additions & 1 deletion cmd/pulumi-gen-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func main() {
}

func writeNodeJSClient(data map[string]interface{}, outdir, templateDir string) {
inputAPIts, ouputAPIts, providerts, helmts, packagejson, err := gen.NodeJSClient(data, templateDir)
inputAPIts, ouputAPIts, providerts, helmts, indexts, packagejson, groupsts, err := gen.NodeJSClient(
data, templateDir)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -87,11 +88,49 @@ func writeNodeJSClient(data map[string]interface{}, outdir, templateDir string)
panic(err)
}

for groupName, group := range groupsts {
groupDir := fmt.Sprintf("%s/%s", outdir, groupName)
err = os.MkdirAll(groupDir, 0700)
if err != nil {
panic(err)
}

for versionName, version := range group.Versions {
versionDir := fmt.Sprintf("%s/%s", groupDir, versionName)
err = os.MkdirAll(versionDir, 0700)
if err != nil {
panic(err)
}

for kindName, kind := range version.Kinds {
err = ioutil.WriteFile(fmt.Sprintf("%s/%s.ts", versionDir, kindName), []byte(kind), 0777)
if err != nil {
panic(err)
}
}

err = ioutil.WriteFile(fmt.Sprintf("%s/%s.ts", versionDir, "index"), []byte(version.Index), 0777)
if err != nil {
panic(err)
}
}

err = ioutil.WriteFile(fmt.Sprintf("%s/%s.ts", groupDir, "index"), []byte(group.Index), 0777)
if err != nil {
panic(err)
}
}

err = ioutil.WriteFile(fmt.Sprintf("%s/helm.ts", outdir), []byte(helmts), 0777)
if err != nil {
panic(err)
}

err = ioutil.WriteFile(fmt.Sprintf("%s/index.ts", outdir), []byte(indexts), 0777)
if err != nil {
panic(err)
}

err = ioutil.WriteFile(fmt.Sprintf("%s/package.json", outdir), []byte(packagejson), 0777)
if err != nil {
panic(err)
Expand Down
49 changes: 49 additions & 0 deletions pkg/gen/nodejs-templates/kind.ts.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

import * as pulumi from "@pulumi/pulumi";
import * as inputApi from "../../types/input";
import * as outputApi from "../../types/output";

{{Comment}}
export class {{Kind}} extends pulumi.CustomResource {
{{#Properties}}
{{Comment}}
public readonly {{Name}}: pulumi.Output<{{{PropType}}}>;

{{/Properties}}
/**
* Get the state of an existing `{{Kind}}` resource, as identified by `id`.
* Typically this ID is of the form <namespace>/<name>; if <namespace> is omitted, then (per
* Kubernetes convention) the ID becomes default/<name>.
*
* Pulumi will keep track of this resource using `name` as the Pulumi ID.
*
* @param name _Unique_ name used to register this resource with Pulumi.
* @param id An ID for the Kubernetes resource to retrieve. Takes the form
* <namespace>/<name> or <name>.
* @param opts Uniquely specifies a CustomResource to select.
*/
public static get(name: string, id: pulumi.Input<pulumi.ID>, opts?: pulumi.CustomResourceOptions): {{Kind}} {
return new {{Kind}}(name, undefined, { ...opts, id: id });
}

public getInputs(): inputApi.{{Group}}.{{Version}}.{{Kind}} { return this.__inputs; }
private readonly __inputs: inputApi.{{Group}}.{{Version}}.{{Kind}};

/**
* Create a {{Group}}.{{Version}}.{{Kind}} resource with the given unique name, arguments, and options.
*
* @param name The _unique_ name of the resource.
* @param args The arguments to use to populate this resource's properties.
* @param opts A bag of options that control this resource's behavior.
*/
constructor(name: string, args?: inputApi.{{Group}}.{{Version}}.{{Kind}}, opts?: pulumi.CustomResourceOptions) {
let inputs: pulumi.Inputs = {};
{{#Properties}}
inputs["{{Name}}"] = {{{DefaultValue}}};
{{/Properties}}
super("kubernetes:{{URNAPIVersion}}:{{Kind}}", name, inputs, opts);
this.__inputs = <any>args;
}
}
8 changes: 8 additions & 0 deletions pkg/gen/nodejs-templates/kindIndex.ts.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

// Export members:
{{#Kinds}}
export * from "./{{Kind}}";
{{/Kinds}}

73 changes: 8 additions & 65 deletions pkg/gen/nodejs-templates/provider.ts.mustache
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

import * as fs from "fs";

import * as pulumi from "@pulumi/pulumi";
import * as inputApi from "./types/input";
import * as outputApi from "./types/output";
import * as jsyaml from "js-yaml";
import * as fs from "fs";
import * as glob from "glob";
import * as jsyaml from "js-yaml";
import fetch from "node-fetch";
import * as k8s from "./index";
import * as inputApi from "./types/input";
import * as outputApi from "./types/output";

export namespace yaml {
export interface ConfigGroupOpts {
Expand Down Expand Up @@ -113,8 +113,8 @@ export namespace yaml {
{{#Groups}}
{{#Versions}}
{{#KindsAndAliases}}
public getResource(groupVersionKind: "{{RawAPIVersion}}/{{Kind}}", name: string): pulumi.Output<{{Group}}.{{Version}}.{{Kind}}>;
public getResource(groupVersionKind: "{{RawAPIVersion}}/{{Kind}}", namespace: string, name: string): pulumi.Output<{{Group}}.{{Version}}.{{Kind}}>;
public getResource(groupVersionKind: "{{RawAPIVersion}}/{{Kind}}", name: string): pulumi.Output<k8s.{{Group}}.{{Version}}.{{Kind}}>;
public getResource(groupVersionKind: "{{RawAPIVersion}}/{{Kind}}", namespace: string, name: string): pulumi.Output<k8s.{{Group}}.{{Version}}.{{Kind}}>;
{{/KindsAndAliases}}
{{/Versions}}
{{/Groups}}
Expand Down Expand Up @@ -293,7 +293,7 @@ export namespace yaml {
case "{{RawAPIVersion}}/{{Kind}}":
return [{
name: `{{RawAPIVersion}}/{{Kind}}::${id}`,
resource: new {{Group}}.{{Version}}.{{Kind}}(id, obj, opts),
resource: new k8s.{{Group}}.{{Version}}.{{Kind}}(id, obj, opts),
}];
{{/KindsAndAliases}}
{{/Versions}}
Expand Down Expand Up @@ -478,60 +478,3 @@ export interface ProviderArgs {
*/
readonly namespace?: pulumi.Input<string>;
}

{{#Groups}}
export namespace {{Group}} {
{{#Versions}}
export namespace {{Version}} {
{{#Kinds}}
{{{Comment}}}
export class {{Kind}} extends pulumi.CustomResource {
{{#Properties}}
{{{Comment}}}
public readonly {{Name}}: pulumi.Output<{{{PropType}}}>;

{{/Properties}}

/**
* Get the state of an existing `{{Kind}}` resource, as identified by `id`.
* Typically this ID is of the form <namespace>/<name>; if <namespace> is omitted, then (per
* Kubernetes convention) the ID becomes default/<name>.
*
* Pulumi will keep track of this resource using `name` as the Pulumi ID.
*
* @param name _Unique_ name used to register this resource with Pulumi.
* @param id An ID for the Kubernetes resource to retrieve. Takes the form
* <namespace>/<name> or <name>.
* @param opts Uniquely specifies a CustomResource to select.
*/
public static get(name: string, id: pulumi.Input<pulumi.ID>, opts?: pulumi.CustomResourceOptions): {{Kind}} {
return new {{Kind}}(name, undefined, { ...opts, id: id });
}

public getInputs(): inputApi.{{Group}}.{{Version}}.{{Kind}} { return this.__inputs; }
private readonly __inputs: inputApi.{{Group}}.{{Version}}.{{Kind}};

/**
* Create a {{Group}}.{{Version}}.{{Kind}} resource with the given unique name, arguments, and options.
*
* @param name The _unique_ name of the resource.
* @param args The arguments to use to populate this resource's properties.
* @param opts A bag of options that control this resource's behavior.
*/
constructor(name: string, args?: inputApi.{{Group}}.{{Version}}.{{Kind}}, opts?: pulumi.CustomResourceOptions) {
let inputs: pulumi.Inputs = {};
{{#Properties}}
inputs["{{Name}}"] = {{{DefaultValue}}};
{{/Properties}}
super("kubernetes:{{URNAPIVersion}}:{{Kind}}", name, inputs, opts);
this.__inputs = <any>args;
}
}

{{/Kinds}}
}

{{/Versions}}
}

{{/Groups}}
15 changes: 15 additions & 0 deletions pkg/gen/nodejs-templates/providerIndex.ts.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

export * from "./provider";
import * as helm from "./helm";
export { helm };

// Import groups
{{#Groups}}
import * as {{Group}} from "./{{Group}}/index";
{{/Groups}}

// Export sub-modules
export { {{#Groups}}{{Group}}, {{/Groups}} };

11 changes: 11 additions & 0 deletions pkg/gen/nodejs-templates/versionIndex.ts.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// *** WARNING: this file was generated by the Pulumi Kubernetes codegen tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

// Import versions:
{{#Versions}}
import * as {{Version}} from "./{{Version}}/index";
{{/Versions}}

// Export sub-modules
export { {{#Versions}}{{Version}}, {{/Versions}} };

83 changes: 74 additions & 9 deletions pkg/gen/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ import (

// --------------------------------------------------------------------------

type GroupTS struct {
Versions map[string]*VersionTS
Index string
}

type VersionTS struct {
Kinds map[string]string
Index string
}

// NodeJSClient will generate a Pulumi Kubernetes provider client SDK for nodejs.
func NodeJSClient(
swagger map[string]interface{}, templateDir string,
) (inputsts, outputsts, providerts, helmts, packagejson string, err error) {
func NodeJSClient(swagger map[string]interface{}, templateDir string,
) (inputsts, outputsts, providerts, helmts, indexts, packagejson string, groupsts map[string]*GroupTS, err error) {
definitions := swagger["definitions"].(map[string]interface{})

groupsSlice := createGroups(definitions, nodeJSInputs())
Expand All @@ -39,7 +48,7 @@ func NodeJSClient(
"Groups": groupsSlice,
})
if err != nil {
return "", "", "", "", "", err
return
}

groupsSlice = createGroups(definitions, nodeJSOutputs())
Expand All @@ -48,33 +57,89 @@ func NodeJSClient(
"Groups": groupsSlice,
})
if err != nil {
return "", "", "", "", "", err
return
}

groupsSlice = createGroups(definitions, nodeJSProvider())
groupsts = make(map[string]*GroupTS)
for _, group := range groupsSlice {
groupTS := &GroupTS{}
for _, version := range group.Versions() {
if groupTS.Versions == nil {
groupTS.Versions = make(map[string]*VersionTS)
}
versionTS := &VersionTS{}
for _, kind := range version.Kinds() {
if versionTS.Kinds == nil {
versionTS.Kinds = make(map[string]string)
}
kindts, err := mustache.RenderFile(fmt.Sprintf("%s/kind.ts.mustache", templateDir),
map[string]interface{}{
"Comment": kind.Comment(),
"Group": group.Group(),
"Kind": kind.Kind(),
"Properties": kind.Properties(),
"Version": version.Version(),
})
if err != nil {
return "", "", "", "", "", "", nil, err
}
versionTS.Kinds[kind.Kind()] = kindts
}

kindIndexTS, err := mustache.RenderFile(fmt.Sprintf("%s/kindIndex.ts.mustache", templateDir),
map[string]interface{}{
"Kinds": version.Kinds(),
})
if err != nil {
return "", "", "", "", "", "", nil, err
}
versionTS.Index = kindIndexTS
groupTS.Versions[version.Version()] = versionTS
}

versionIndexTS, err := mustache.RenderFile(fmt.Sprintf("%s/versionIndex.ts.mustache", templateDir),
map[string]interface{}{
"Versions": group.Versions(),
})
if err != nil {
return "", "", "", "", "", "", nil, err
}
groupTS.Index = versionIndexTS
groupsts[group.Group()] = groupTS
}

providerts, err = mustache.RenderFile(fmt.Sprintf("%s/provider.ts.mustache", templateDir),
map[string]interface{}{
"Groups": groupsSlice,
})
if err != nil {
return "", "", "", "", "", err
return
}

helmts, err = mustache.RenderFile(fmt.Sprintf("%s/helm.ts.mustache", templateDir),
map[string]interface{}{
"Groups": groupsSlice,
})
if err != nil {
return "", "", "", "", "", err
return
}

packagejson, err = mustache.RenderFile(fmt.Sprintf("%s/package.json.mustache", templateDir),
map[string]interface{}{
"ProviderVersion": providerVersion.Version,
})
if err != nil {
return "", "", "", "", "", err
return
}

indexts, err = mustache.RenderFile(fmt.Sprintf("%s/providerIndex.ts.mustache", templateDir),
map[string]interface{}{
"Groups": groupsSlice,
})
if err != nil {
return
}

return inputsts, outputsts, providerts, helmts, packagejson, nil
return inputsts, outputsts, providerts, helmts, indexts, packagejson, groupsts, nil
}
Loading