Skip to content

Commit

Permalink
Split up nodejs SDK into multiple files (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Mar 12, 2019
1 parent 4511a47 commit a610ed8
Show file tree
Hide file tree
Showing 229 changed files with 14,084 additions and 12,859 deletions.
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}}

203 changes: 9 additions & 194 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,148 +293,20 @@ 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}}
{{/Groups}}
default:
return [{
name: `${apiVersion}/${kind}::${id}`,
resource: new apiextensions.CustomResource(id, obj, opts),
resource: new k8s.apiextensions.CustomResource(id, obj, opts),
}];
}
}
}

export namespace apiextensions {
/**
* CustomResourceArgs represents a resource definiton we'd use to create an instance of a
* Kubernetes CustomResourceDefinition (CRD). For example, the CoreOS Prometheus operator
* exposes a CRD `monitoring.coreos.com/ServiceMonitor`; to create a `ServiceMonitor`, we'd
* pass a `CustomResourceArgs` containing the `ServiceMonitor` definition to
* `apiextensions.CustomResource`.
*
* NOTE: This type is fairly loose, since other than `apiVersion` and `kind`, there are no
* fields required across all CRDs.
*/
export interface CustomResourceArgs {
/**
* APIVersion defines the versioned schema of this representation of an object. Servers should
* convert recognized schemas to the latest internal value, and may reject unrecognized
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion: pulumi.Input<string>;
/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind: pulumi.Input<string>;
/**
* Standard object metadata; More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.
*/
metadata?: pulumi.Input<inputApi.meta.v1.ObjectMeta>;
[othersFields: string]: pulumi.Input<any>;
}

/**
* CustomResourceGetOptions uniquely identifies a Kubernetes CustomResource, primarily for use
* in supplied to `apiextensions.CustomResource#get`.
*/
export interface CustomResourceGetOptions extends pulumi.CustomResourceOptions {
/**
* apiVersion is the API version of the apiExtensions.CustomResource we wish to select,
* as specified by the CustomResourceDefinition that defines it on the API server.
*/
apiVersion: pulumi.Input<string>;
/**
* kind is the kind of the apiextensions.CustomResource we wish to select, as specified by
* the CustomResourceDefinition that defines it on the API server.
*/
kind: pulumi.Input<string>
/**
* An ID for the Kubernetes resource to retrive. Takes the form <namespace>/<name> or
* <name>.
*/
id: pulumi.Input<pulumi.ID>;
}

/**
* CustomResource represents an instance of a CustomResourceDefinition (CRD). For example, the
* CoreOS Prometheus operator exposes a CRD `monitoring.coreos.com/ServiceMonitor`; to
* instantiate this as a Pulumi resource, one could call `new CustomResource`, passing the
* `ServiceMonitor` resource definition as an argument.
*/
export class CustomResource extends pulumi.CustomResource {
/**
* APIVersion defines the versioned schema of this representation of an object. Servers should
* convert recognized schemas to the latest internal value, and may reject unrecognized
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
public readonly apiVersion: pulumi.Output<string>;
/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
public readonly kind: pulumi.Output<string>;
/**
* Standard object metadata; More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.
*/
public readonly metadata: pulumi.Output<outputApi.meta.v1.ObjectMeta>;
/**
* Get the state of an existing `CustomResource`, 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 opts Uniquely specifies a CustomResource to select.
*/
public static get(name: string, opts: CustomResourceGetOptions): CustomResource {
// NOTE: `selectOpts` will be type `pulumi.CustomResource`. If we add a field that does
// not satisfy that interface, it will cause a compilation error in `...selectOpts` in
// the constructor call below.
const {apiVersion, kind, id, ...selectOpts} = opts;
return new CustomResource(name, {apiVersion: apiVersion, kind: kind}, { ...selectOpts, id: id });
}

public getInputs(): CustomResourceArgs { return this.__inputs; }
private readonly __inputs: CustomResourceArgs;

/**
* Create a CustomResource 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: CustomResourceArgs, opts?: pulumi.CustomResourceOptions) {
let inputs: pulumi.Inputs = {};
for (const key of Object.keys(args)) {
inputs[key] = (args as any)[key];
}
super(`kubernetes:${args.apiVersion}:${args.kind}`, name, inputs, opts);
this.__inputs = args;
}
}
}

/**
* The provider type for the kubernetes package.
*/
Expand Down Expand Up @@ -478,60 +350,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}} };

Loading

0 comments on commit a610ed8

Please sign in to comment.