Skip to content

Commit

Permalink
Add examples in all languages to API docs (#477)
Browse files Browse the repository at this point in the history
Part of #196
  • Loading branch information
thomas11 authored Jun 27, 2024
1 parent 978e2f7 commit 11d4056
Show file tree
Hide file tree
Showing 22 changed files with 1,992 additions and 32 deletions.
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,46 @@ curl \

There are cases where it's important to run some cleanup operation before destroying a resource such as when destroying the resource does not properly handle orderly cleanup. For example, destroying an EKS Cluster will not ensure that all Kubernetes object finalizers are run, which may lead to leaking external resources managed by those Kubernetes resources. This example shows how we can use a `delete`-only `Command` to ensure some cleanup is run within a cluster before destroying it.

```yaml
resources:
cluster:
type: eks:Cluster

cleanupKubernetesNamespaces:
# We could also use `RemoteCommand` to run this from
# within a node in the cluster.
type: command:local:Command
properties:
# This will run before the cluster is destroyed.
# Everything else will need to depend on this resource
# to ensure this cleanup doesn't happen too early.
delete: |
kubectl --kubeconfig <(echo "$KUBECONFIG_DATA") delete namespace nginx
# Process substitution "<()" doesn't work in the default interpreter sh.
interpreter: ["/bin/bash", "-c"]
environment:
KUBECONFIG_DATA: "${cluster.kubeconfigJson}"
```
```ts
import { local } from "@pulumi/command";
import * as pulumi from "@pulumi/pulumi";
import * as command from "@pulumi/command";
import * as eks from "@pulumi/eks";
import * as random from "@pulumi/random";
import { interpolate } from "@pulumi/pulumi";

const cluster = new eks.Cluster("cluster", {});

// We could also use `RemoteCommand` to run this from within a node in the cluster
const cleanupKubernetesNamespaces = new local.Command("cleanupKubernetesNamespaces", {
const cleanupKubernetesNamespaces = new command.local.Command("cleanupKubernetesNamespaces", {
// This will run before the cluster is destroyed. Everything else will need to
// depend on this resource to ensure this cleanup doesn't happen too early.
delete: "kubectl delete --all namespaces",
"delete": "kubectl --kubeconfig <(echo \"$KUBECONFIG_DATA\") delete namespace nginx\n",
// Process substitution "<()" doesn't work in the default interpreter sh.
interpreter: [
"/bin/bash",
"-c",
],
environment: {
KUBECONFIG: cluster.kubeconfig,
KUBECONFIG_DATA: cluster.kubeconfigJson,
},
});
```
Expand Down
6 changes: 3 additions & 3 deletions provider/cmd/pulumi-resource-command/schema.json

Large diffs are not rendered by default.

Loading

0 comments on commit 11d4056

Please sign in to comment.