Skip to content

Commit

Permalink
feat(ThirdPartyResource): Add resources option to constructor (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
silasbw committed Feb 9, 2017
1 parent 58614c5 commit f457b56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@ and then extend an `ThirdPartyResource` API client with your new resources:
```js
const thirdPartyResources = new K8Api.ThirdPartyResources({
url: 'http://my-k8-api-server.com',
group: 'kubernetes-client.io'
group: 'kubernetes-client.io',
resources: ['customresources'] // Notice pluralization!
});

// Access `customresources` as if they were a regular Kubernetes object
thirdPartyResources.ns.customresources.get(print);
thirdPartyResources.addResource('newresources'); // Notice pluralization!
// Now access `newresources` as if they were a regular Kubernetes object
// Now access `newresources`
thirdPartyResources.ns.newresources.get(print);
```

Expand Down
5 changes: 5 additions & 0 deletions lib/third-party-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class ThirdPartyResource extends ApiGroup {
genericTypes: []
});
super(options);

if (options.resources) {
options.resources.forEach(resource => this.addResource(resource));
}
}

addResource(resourceName) {
Expand All @@ -20,6 +24,7 @@ class ThirdPartyResource extends ApiGroup {
name: resourceName,
parentPath: this.path
});
return this;
}
}

Expand Down

0 comments on commit f457b56

Please sign in to comment.