Skip to content

Commit

Permalink
Add getResourceProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
pgavlin committed Nov 10, 2018
1 parent 47999d1 commit eb33a11
Show file tree
Hide file tree
Showing 5 changed files with 1,557 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/helm-local/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ const nginx = new k8s.helm.v2.Chart("simple-nginx-local", {
});

// Export the (cluster-private) IP address of the Guestbook frontend.
const frontend = nginx.getResource("v1/Service", "simple-nginx-local-nginx");
export const frontendClusterIp = frontend.apply(f => f.spec).apply(spec => spec.clusterIP);
export const frontendClusterIp = nginx.getResourceProperty("v1/Service", "simple-nginx-local-nginx", "spec")
.apply(spec => spec.clusterIP);
4 changes: 2 additions & 2 deletions examples/helm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ const nginx = new k8s.helm.v2.Chart("simple-nginx", {
});

// Export the (cluster-private) IP address of the Guestbook frontend.
const frontend = nginx.getResource("v1/Service", "simple-nginx-nginx-lego");
export const frontendClusterIp = frontend.apply(f => f.spec).apply(spec => spec.clusterIP);
export const frontendClusterIp = nginx.getResourceProperty("v1/Service", "simple-nginx-nginx-lego", "spec")
.apply(spec => spec.clusterIP);
3 changes: 1 addition & 2 deletions examples/yaml-guestbook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ import * as k8s from "@pulumi/kubernetes";
const guestbook = new k8s.yaml.ConfigGroup("guestbook", { files: "yaml/*.yaml" });

// Export the (cluster-private) IP address of the Guestbook frontend.
const frontend = guestbook.getResource("v1/Service", "frontend");
export const frontendIp = frontend.apply(f => f.spec).apply(spec => spec.clusterIP);
export const frontendIp = guestbook.getResource("v1/Service", "frontend", "spec").apply(spec => spec.clusterIP);
22 changes: 22 additions & 0 deletions pkg/gen/nodejs-templates/provider.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ export namespace yaml {
return this.getResourceImpl(groupVersionKind, namespaceOrName, name);
}

/**
* getResourceProperty returns a single property of a resource defined by a built-in Kubernetes group/version/kind and name.
*
* For example:
* getResourceProperty("v1/Service", "nginx", "spec")
*/
{{#Groups}}
{{#Versions}}
{{#Kinds}}
{{#Properties}}
public getResourceProperty(groupVersionKind: "{{RawAPIVersion}}/{{Kind}}", name: string, property: "{{LanguageName}}"): pulumi.Output<{{{PropType}}}>;
public getResourceProperty(groupVersionKind: "{{RawAPIVersion}}/{{Kind}}", namespace: string, name: string, property: "{{LanguageName}}"): pulumi.Output<{{{PropType}}}>;
{{/Properties}}
{{/Kinds}}
{{/Versions}}
{{/Groups}}
public getResourceProperty(groupVersionKind: string, namespaceOrName: string, nameOrProperty: string, property?: string): pulumi.Output<any> {
const name = property !== undefined ? nameOrProperty : undefined;
return this.getResourceImpl(groupVersionKind, namespaceOrName, name)
.apply(r => (<any>r)[property || nameOrProperty]);
}

/**
* getCustomResource returns a resource defined by a CRD with the given group/version/kind and name.
*
Expand Down
Loading

0 comments on commit eb33a11

Please sign in to comment.