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

Use pulumi convert to automate conversion of examples #1999

Merged
merged 21 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 18 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
29 changes: 29 additions & 0 deletions .github/workflows/run-acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,32 @@ jobs:
name: lint
if: github.event_name == 'repository_dispatch' ||
github.event.pull_request.head.repo.full_name == github.repository
ensure-examples-gen:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want to add this to the acceptance tests at this time. The convert process is a bit slow, and the examples are currently static. Let's add a Makefile target instead, and then we can update the examples as needed.

name: Ensure Examples Generated
runs-on: ubuntu-latest
strategy:
matrix:
goversion: [1.17.x]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Unshallow clone for tags
run: git fetch --prune --unshallow --tags
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.goversion }}
- name: Install pulumictl
uses: jaxxstorm/action-install-gh-release@v1.1.0
with:
repo: pulumi/pulumictl
- name: Install Pulumi CLI
uses: pulumi/action-install-pulumi-cli@v1.0.1
- name: Install Kubernetes Plugin
run: pulumi plugin install resource kubernetes
- name: Generate examples
run: |
cd provider/pkg/gen/examples/upstream
go run generate.go ./yaml ./
- name: Check worktree clean
run: ./ci-scripts/ci/check-worktree-is-clean
12 changes: 6 additions & 6 deletions provider/cmd/pulumi-resource-kubernetes/schema.json

Large diffs are not rendered by default.

101 changes: 78 additions & 23 deletions provider/pkg/gen/examples/upstream/deployment.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as pulumi from "@pulumi/pulumi";
import * as kubernetes from "@pulumi/kubernetes";

const nginx = new kubernetes.apps.v1.Deployment("nginx", {
const deployment = new kubernetes.apps.v1.Deployment("deployment", {
metadata: {
labels: {
app: "nginx",
Expand All @@ -28,8 +28,8 @@ const nginx = new kubernetes.apps.v1.Deployment("nginx", {
},
spec: {
containers: [{
name: "nginx",
image: "nginx:1.14.2",
name: "nginx",
ports: [{
containerPort: 80,
}],
Expand All @@ -43,8 +43,7 @@ const nginx = new kubernetes.apps.v1.Deployment("nginx", {
import pulumi
import pulumi_kubernetes as kubernetes

nginx = kubernetes.apps.v1.Deployment(
"nginx",
deployment = kubernetes.apps.v1.Deployment("deployment",
metadata=kubernetes.meta.v1.ObjectMetaArgs(
labels={
"app": "nginx",
Expand All @@ -65,8 +64,8 @@ nginx = kubernetes.apps.v1.Deployment(
),
spec=kubernetes.core.v1.PodSpecArgs(
containers=[kubernetes.core.v1.ContainerArgs(
name="nginx",
image="nginx:1.14.2",
name="nginx",
ports=[kubernetes.core.v1.ContainerPortArgs(
container_port=80,
)],
Expand All @@ -83,7 +82,7 @@ class MyStack : Stack
{
public MyStack()
{
var nginx = new Kubernetes.Apps.V1.Deployment("nginx", new Kubernetes.Types.Inputs.Apps.V1.DeploymentArgs
var deployment = new Kubernetes.Apps.V1.Deployment("deployment", new Kubernetes.Types.Inputs.Apps.V1.DeploymentArgs
{
Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs
{
Expand Down Expand Up @@ -117,8 +116,8 @@ class MyStack : Stack
{
new Kubernetes.Types.Inputs.Core.V1.ContainerArgs
{
Name = "nginx",
Image = "nginx:1.14.2",
Name = "nginx",
Ports =
{
new Kubernetes.Types.Inputs.Core.V1.ContainerPortArgs
Expand All @@ -133,6 +132,7 @@ class MyStack : Stack
},
});
}

}
```
```go
Expand All @@ -147,7 +147,7 @@ import (

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := appsv1.NewDeployment(ctx, "nginx", &appsv1.DeploymentArgs{
_, err := appsv1.NewDeployment(ctx, "deployment", &appsv1.DeploymentArgs{
Metadata: &metav1.ObjectMetaArgs{
Labels: pulumi.StringMap{
"app": pulumi.String("nginx"),
Expand All @@ -169,8 +169,8 @@ func main() {
Spec: &corev1.PodSpecArgs{
Containers: corev1.ContainerArray{
&corev1.ContainerArgs{
Name: pulumi.String("nginx"),
Image: pulumi.String("nginx:1.14.2"),
Name: pulumi.String("nginx"),
Ports: corev1.ContainerPortArray{
&corev1.ContainerPortArgs{
ContainerPort: pulumi.Int(80),
Expand All @@ -189,6 +189,33 @@ func main() {
})
}
```
```yaml
description: Create a Deployment with auto-naming
name: yaml-example
resources:
deployment:
properties:
metadata:
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80
type: kubernetes:apps/v1:Deployment
runtime: yaml
```
{{% /example %}}
{{% example %}}
### Create a Deployment with a user-specified name
Expand All @@ -197,12 +224,12 @@ func main() {
import * as pulumi from "@pulumi/pulumi";
import * as kubernetes from "@pulumi/kubernetes";

const nginx = new kubernetes.apps.v1.Deployment("nginx", {
const deployment = new kubernetes.apps.v1.Deployment("deployment", {
metadata: {
name: "nginx-deployment",
labels: {
app: "nginx",
},
name: "nginx-deployment",
},
spec: {
replicas: 3,
Expand All @@ -219,8 +246,8 @@ const nginx = new kubernetes.apps.v1.Deployment("nginx", {
},
spec: {
containers: [{
name: "nginx",
image: "nginx:1.14.2",
name: "nginx",
ports: [{
containerPort: 80,
}],
Expand All @@ -234,13 +261,12 @@ const nginx = new kubernetes.apps.v1.Deployment("nginx", {
import pulumi
import pulumi_kubernetes as kubernetes

nginx = kubernetes.apps.v1.Deployment(
"nginx",
deployment = kubernetes.apps.v1.Deployment("deployment",
metadata=kubernetes.meta.v1.ObjectMetaArgs(
name="nginx-deployment",
labels={
"app": "nginx",
},
name="nginx-deployment",
),
spec=kubernetes.apps.v1.DeploymentSpecArgs(
replicas=3,
Expand All @@ -257,8 +283,8 @@ nginx = kubernetes.apps.v1.Deployment(
),
spec=kubernetes.core.v1.PodSpecArgs(
containers=[kubernetes.core.v1.ContainerArgs(
name="nginx",
image="nginx:1.14.2",
name="nginx",
ports=[kubernetes.core.v1.ContainerPortArgs(
container_port=80,
)],
Expand All @@ -275,15 +301,15 @@ class MyStack : Stack
{
public MyStack()
{
var nginx = new Kubernetes.Apps.V1.Deployment("nginx", new Kubernetes.Types.Inputs.Apps.V1.DeploymentArgs
var deployment = new Kubernetes.Apps.V1.Deployment("deployment", new Kubernetes.Types.Inputs.Apps.V1.DeploymentArgs
{
Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs
{
Name = "nginx-deployment",
Labels =
{
{ "app", "nginx" },
},
Name = "nginx-deployment",
},
Spec = new Kubernetes.Types.Inputs.Apps.V1.DeploymentSpecArgs
{
Expand All @@ -310,8 +336,8 @@ class MyStack : Stack
{
new Kubernetes.Types.Inputs.Core.V1.ContainerArgs
{
Name = "nginx",
Image = "nginx:1.14.2",
Name = "nginx",
Ports =
{
new Kubernetes.Types.Inputs.Core.V1.ContainerPortArgs
Expand All @@ -326,6 +352,7 @@ class MyStack : Stack
},
});
}

}
```
```go
Expand All @@ -340,12 +367,12 @@ import (

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := appsv1.NewDeployment(ctx, "nginx", &appsv1.DeploymentArgs{
_, err := appsv1.NewDeployment(ctx, "deployment", &appsv1.DeploymentArgs{
Metadata: &metav1.ObjectMetaArgs{
Name: pulumi.String("nginx-deployment"),
Labels: pulumi.StringMap{
"app": pulumi.String("nginx"),
},
Name: pulumi.String("nginx-deployment"),
},
Spec: &appsv1.DeploymentSpecArgs{
Replicas: pulumi.Int(3),
Expand All @@ -363,8 +390,8 @@ func main() {
Spec: &corev1.PodSpecArgs{
Containers: corev1.ContainerArray{
&corev1.ContainerArgs{
Name: pulumi.String("nginx"),
Image: pulumi.String("nginx:1.14.2"),
Name: pulumi.String("nginx"),
Ports: corev1.ContainerPortArray{
&corev1.ContainerPortArgs{
ContainerPort: pulumi.Int(80),
Expand All @@ -383,5 +410,33 @@ func main() {
})
}
```
```yaml
description: Create a Deployment with a user-specified name
name: yaml-example
resources:
deployment:
properties:
metadata:
labels:
app: nginx
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80
type: kubernetes:apps/v1:Deployment
runtime: yaml
```
{{% /example %}}
{% /examples %}}
{{% /examples %}}
Loading