Skip to content

Commit

Permalink
Ensure schema is available in Provider for use in GetSchema calls (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
stack72 authored Feb 10, 2022
1 parent a51a451 commit 4cfa852
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WORKING_DIR := $(shell pwd)
build:: schema provider build_nodejs build_python build_go build_dotnet

schema::
cd provider/cmd/$(CODEGEN) && go run main.go schema ../$(PROVIDER)
(cd provider/cmd/$(CODEGEN) && go run main.go schema ../$(PROVIDER))

provider::
rm -rf provider/cmd/$(PROVIDER)/bin
Expand All @@ -28,7 +28,8 @@ build_nodejs::
sed -e 's/\$${VERSION}/$(VERSION)/g' < package.json > bin/package.json && \
cp ../../README.md ../../LICENSE bin/ && \
cp -R dashboard bin/ && \
cp -R cni bin/
cp -R cni bin/ && \
cp ../../provider/cmd/pulumi-resource-eks/schema.json bin/cmd/provider/

build_python:: PYPI_VERSION := $(shell pulumictl get version --language python)
build_python:: schema
Expand Down
24 changes: 12 additions & 12 deletions nodejs/eks/cmd/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import * as pulumi from "@pulumi/pulumi";
import { readFileSync } from "fs";
import { Cluster } from "../../cluster";
import { VpcCni } from "../../cni";
import { clusterCreationRoleProviderProviderFactory, clusterProviderFactory } from "./cluster";
Expand All @@ -22,8 +23,6 @@ import { randomSuffixProviderFactory } from "./randomSuffix";
import { nodeGroupSecurityGroupProviderFactory } from "./securitygroup";

class Provider implements pulumi.provider.Provider {
readonly version = getVersion();

// A map of types to provider factories. Calling a factory may return a new instance each
// time or return the same provider instance.
private readonly typeToProviderFactoryMap: Record<string, () => pulumi.provider.Provider> = {
Expand All @@ -36,10 +35,10 @@ class Provider implements pulumi.provider.Provider {
"eks:index:VpcCni": vpcCniProviderFactory,
};

constructor() {
constructor(readonly version: string, readonly schema: string) {
// Register any resources that can come back as resource references that need to be rehydrated.
pulumi.runtime.registerResourceModule("eks", "index", {
version: getVersion(),
version: version,
construct: (name, type, urn) => {
switch (type) {
case "eks:index:Cluster":
Expand Down Expand Up @@ -153,16 +152,17 @@ function getType(urn: pulumi.URN): string {
return lastType;
}

function getVersion(): string {
const version: string = require("../../package.json").version;
// Node allows for the version to be prefixed by a "v", while semver doesn't.
// If there is a v, strip it off.
return version.startsWith("v") ? version.slice(1) : version;
}

/** @internal */
export function main(args: string[]) {
return pulumi.provider.main(new Provider(), args);
const schema: string = readFileSync(require.resolve("./schema.json"), {encoding: "utf-8"});
let version: string = require("../../package.json").version;
// Node allows for the version to be prefixed by a "v",
// while semver doesn't. If there is a v, strip it off.
if (version.startsWith("v")) {
version = version.slice(1);
}

return pulumi.provider.main(new Provider(version, schema), args);
}

main(process.argv.slice(2));

0 comments on commit 4cfa852

Please sign in to comment.