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

Add NodeJS usage examples for Helm, YAML, and Kustomize #1205

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## HEAD (Unreleased)

### Improvements

- Add NodeJS usage examples for Helm, Kustomize, and YAML resources. (https://github.com/pulumi/pulumi-kubernetes/pull/1205)

## 2.4.0 (July 7, 2020)

### Bug Fixes
Expand Down
118 changes: 96 additions & 22 deletions provider/pkg/gen/nodejs-templates/helm/v2/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,100 @@ import * as yaml from "../../yaml/index";
* are equivalent to running `helm template` and then using Pulumi to manage the resulting YAML
* manifests. Any values that would be retrieved in-cluster are assigned fake values, and
* none of Tiller's server-side validity testing is executed.
*
* ## Example Usage
* ### Local Chart Directory
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const nginxIngress = new k8s.helm.v3.Chart("nginx-ingress", {
* path: "./nginx-ingress",
* });
* ```
* ### Remote Chart
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const nginxIngress = new k8s.helm.v3.Chart("nginx-ingress", {
* chart: "nginx-ingress",
* version: "1.24.4",
* fetchOpts:{
* repo: "https://kubernetes-charts.storage.googleapis.com/",
* },
* });
* ```
* ### Set Chart values
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const nginxIngress = new k8s.helm.v3.Chart("nginx-ingress", {
* chart: "nginx-ingress",
* version: "1.24.4",
* fetchOpts:{
* repo: "https://kubernetes-charts.storage.googleapis.com/",
* },
* values: {
* controller: {
* metrics: {
* enabled: true,
* }
* }
* },
* });
* ```
* ### Deploy Chart into Namespace
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const nginxIngress = new k8s.helm.v3.Chart("nginx-ingress", {
* chart: "nginx-ingress",
* version: "1.24.4",
* namespace: "test-namespace",
* fetchOpts:{
* repo: "https://kubernetes-charts.storage.googleapis.com/",
* },
* });
* ```
* ### Chart with Transformations
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const nginxIngress = new k8s.helm.v3.Chart("nginx-ingress", {
* chart: "nginx-ingress",
* version: "1.24.4",
* fetchOpts:{
* repo: "https://kubernetes-charts.storage.googleapis.com/",
* },
* transformations: [
* // Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Service" && obj.apiVersion === "v1") {
* if (obj.spec && obj.spec.type && obj.spec.type === "LoadBalancer") {
* obj.spec.type = "ClusterIP";
* }
* }
* },
*
* // Set a resource alias for a previous name.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Deployment") {
* opts.aliases = [{ name: "oldName" }]
* },
*
* // Omit a resource from the Chart by transforming the specified resource definition to an empty List.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Pod" && obj.metadata.name === "test") {
* obj.apiVersion = "v1"
* obj.kind = "List"
* },
* ],
* });
* ```
*/
export class Chart extends yaml.CollectionComponentResource {
/**
Expand Down Expand Up @@ -201,30 +295,10 @@ interface BaseChartOpts {
*/
values?: pulumi.Inputs;
/**
* Optional array of transformations to apply to resources that will be created by this chart prior to
* creation. Allows customization of the chart behaviour without directly modifying the chart itself.
*
* @example
* ```typescript
* transformations: [
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Deployment" && obj.metadata.name == "cert-manager") {
* opts.aliases = [
* "urn:pulumi:dev::example::kubernetes:helm.sh/v2:Chart$kubernetes:apps/v1beta1:Deployment::default/cert-manager",
* ];
* }
*
* if (obj.metadata) {
* obj.metadata.namespace = namespaceName;
* } else {
* obj.metadata = {namespace: namespaceName};
* }
* },
* ]
* ```
* A set of transformations to apply to Kubernetes resource definitions before registering
* with engine.
*/
transformations?: ((o: any, opts: pulumi.CustomResourceOptions) => void)[];

/**
* An optional prefix for the auto-generated resource names.
* Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
Expand Down
52 changes: 52 additions & 0 deletions provider/pkg/gen/nodejs-templates/kustomize/kustomize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,58 @@ import * as yaml from "../yaml";

/**
* Directory is a component representing a collection of resources described by a kustomize directory (kustomization).
*
* ## Example Usage
* ### Local Kustomize Directory
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const helloWorld = new k8s.kustomize.Directory("helloWorldLocal", {
* directory: "./helloWorld",
* });
* ```
* ### Kustomize Directory from a Git Repo
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const helloWorld = new k8s.kustomize.Directory("helloWorldRemote", {
* directory: "https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
* });
* ```
* ### Kustomize Directory with Transformations
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const helloWorld = new k8s.kustomize.Directory("helloWorldRemote", {
* directory: "https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
* transformations: [
* // Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Service" && obj.apiVersion === "v1") {
* if (obj.spec && obj.spec.type && obj.spec.type === "LoadBalancer") {
* obj.spec.type = "ClusterIP";
* }
* }
* },
*
* // Set a resource alias for a previous name.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Deployment") {
* opts.aliases = [{ name: "oldName" }]
* },
*
* // Omit a resource from the Chart by transforming the specified resource definition to an empty List.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Pod" && obj.metadata.name === "test") {
* obj.apiVersion = "v1"
* obj.kind = "List"
* },
* ],
* });
* ```
*/
export class Directory extends yaml.CollectionComponentResource {
/**
Expand Down
127 changes: 127 additions & 0 deletions provider/pkg/gen/nodejs-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,90 @@ export abstract class CollectionComponentResource extends pulumi.ComponentResour
* b. `{yaml: ["(LITERAL YAML HERE)", "(MORE YAML)"]}`
* 4. Any combination of files, patterns, or YAML strings:
* a. `{files: "foo.yaml", yaml: "(LITERAL YAML HERE)"}`
*
* ## Example Usage
* ### Local File
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const example = new k8s.yaml.ConfigGroup("example", {
* files: "foo.yaml",
* });
* ```
* ### Multiple Local Files
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const example = new k8s.yaml.ConfigGroup("example", {
* files: ["foo.yaml", "bar.yaml"],
* });
* ```
* ### Local File Pattern
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const example = new k8s.yaml.ConfigGroup("example", {
* files: "yaml/*.yaml",
* });
* ```
* ### Multiple Local File Patterns
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const example = new k8s.yaml.ConfigGroup("example", {
* files: ["foo/*.yaml", "bar/*.yaml"],
* });
* ```
* ### Literal YAML String
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const example = new k8s.yaml.ConfigGroup("example", {
* yaml: `
* apiVersion: v1
* kind: Namespace
* metadata:
* name: foo
* `,
* })
* ```
* ### YAML with Transformations
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const example = new k8s.yaml.ConfigGroup("example", {
* files: "foo.yaml",
* transformations: [
* // Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Service" && obj.apiVersion === "v1") {
* if (obj.spec && obj.spec.type && obj.spec.type === "LoadBalancer") {
* obj.spec.type = "ClusterIP";
* }
* }
* },
*
* // Set a resource alias for a previous name.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Deployment") {
* opts.aliases = [{ name: "oldName" }]
* },
*
* // Omit a resource from the Chart by transforming the specified resource definition to an empty List.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Pod" && obj.metadata.name === "test") {
* obj.apiVersion = "v1"
* obj.kind = "List"
* },
* ],
* });
* ```
*/
export class ConfigGroup extends CollectionComponentResource {
/**
Expand All @@ -121,6 +205,49 @@ export class ConfigGroup extends CollectionComponentResource {
/**
* ConfigFile creates a set of Kubernetes resources from Kubernetes YAML file. If `config.name`
* is not specified, `ConfigFile` assumes the argument `name` is the filename.
*
* ## Example Usage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block below looks like a dupe of the block above it. are they supposed to be similar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ConfigGroup and ConfigFile have similar usages

* ### Local File
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const example = new k8s.yaml.ConfigGroup("example", {
* file: "foo.yaml",
* });
* ```
* ### YAML with Transformations
*
* ```typescript
* import * as k8s from "@pulumi/kubernetes";
*
* const example = new k8s.yaml.ConfigGroup("example", {
* file: "foo.yaml",
* transformations: [
* // Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Service" && obj.apiVersion === "v1") {
* if (obj.spec && obj.spec.type && obj.spec.type === "LoadBalancer") {
* obj.spec.type = "ClusterIP";
* }
* }
* },
*
* // Set a resource alias for a previous name.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Deployment") {
* opts.aliases = [{ name: "oldName" }]
* },
*
* // Omit a resource from the Chart by transforming the specified resource definition to an empty List.
* (obj: any, opts: pulumi.CustomResourceOptions) => {
* if (obj.kind === "Pod" && obj.metadata.name === "test") {
* obj.apiVersion = "v1"
* obj.kind = "List"
* },
* ],
* });
* ```
*/
export class ConfigFile extends CollectionComponentResource {
/**
Expand Down
Loading