pulumi/tests/testdata/codegen/kubernetes-pod-pp/go/kubernetes-pod.go

65 lines
1.8 KiB
Go
Raw Permalink Normal View History

package main
import (
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/core/v1"
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/meta/v1"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
bar, err := corev1.NewPod(ctx, "bar", &corev1.PodArgs{
ApiVersion: pulumi.String("v1"),
Metadata: &metav1.ObjectMetaArgs{
Namespace: pulumi.String("foo"),
Name: pulumi.String("bar"),
[program-gen/csharp,python] Allow object keys to be template expressions (#15000) # Description I've noticed while working with PCL generated from Kubernetes manifests that when an object property key is quoted for example `{ "key" = value }` instead of `{ key = value }` then program-gen for csharp and python _panic_ because they assume the object keys to be strictly a literal value expression and this type assertion fails: ```go lit := item.Key.(*model.LiteralValueExpression) ``` This PR fixes this panic and allows program-gen to handle cases where the object keys are `TemplateExpression` assuming that it has one part which is a literal value expression (handling cases like `{ "key" = value }`) ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [ ] I have run `make lint` to verify my code passes the lint check - [ ] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2023-12-23 11:26:01 +00:00
Labels: pulumi.StringMap{
"app.kubernetes.io/name": pulumi.String("cilium-agent"),
"app.kubernetes.io/part-of": pulumi.String("cilium"),
"k8s-app": pulumi.String("cilium"),
},
},
Spec: &corev1.PodSpecArgs{
[docs/go-program-gen] Fix generating constructor syntax examples for kubernetes (#16574) In this PR we fix generating constructor syntax examples for Kubernetes. The problem initially was due to generating a PCL program with syntax errors for the kubernetes schema. The syntax error was happening because we emitted properties `$ref` and `$schema` which are not valid identifiers in PCL. Fixing this was simple enough, we only needed to quote these properties that start with dollar signs and we get a valid PCL program. Full PCL program for kubernetes: https://gist.github.com/Zaid-Ajaj/abe899430a0b5f99a428934dcac75d52 However, the valid PCL program wouldn't convert to Go with program-gen and it would hang without showing any errors or stack traces. I wrote a script to split the programs for each resource and convert each separately. This way I narrowed down the problem to this program: ``` resource "def" "kubernetes:apiextensions.k8s.io/v1:CustomResourceDefinition" { apiVersion = "string" kind = "string" spec = { versions = [{}] } } ``` Debugging this in Go program-gen didn't show an obvious error and it kept on hanging. However I noticed that we lowering expressions twice: once for the entirety of resource inputs when generating resources and again when generating the expressions separately. Lowering expressions has been the source of many bugs and it seems to trip up program-gen a lot and suspected something wrong was going on here, so I simplified it to lower the expressions once when we generate resource inputs. This fixed the hang issue as well as a few of our test programs (see diffs for test programs and tests schemas) Tested this against the full kubernetes schema and we can now generate the full Go program: https://gist.github.com/Zaid-Ajaj/3ac734536969a989edae92219968d51f > The second time we lower expressions not only is redundant but also can generate invalid code if the lowered expressions have temporary variables because program-gen would just emit these variables inside inline expressions like objects and lists which gives invalid Go code. Resolves part of #16463
2024-07-05 12:42:41 +00:00
Containers: corev1.ContainerArray{
&corev1.ContainerArgs{
Name: pulumi.String("nginx"),
Image: pulumi.String("nginx:1.14-alpine"),
Ports: corev1.ContainerPortArray{
[docs/go-program-gen] Fix generating constructor syntax examples for kubernetes (#16574) In this PR we fix generating constructor syntax examples for Kubernetes. The problem initially was due to generating a PCL program with syntax errors for the kubernetes schema. The syntax error was happening because we emitted properties `$ref` and `$schema` which are not valid identifiers in PCL. Fixing this was simple enough, we only needed to quote these properties that start with dollar signs and we get a valid PCL program. Full PCL program for kubernetes: https://gist.github.com/Zaid-Ajaj/abe899430a0b5f99a428934dcac75d52 However, the valid PCL program wouldn't convert to Go with program-gen and it would hang without showing any errors or stack traces. I wrote a script to split the programs for each resource and convert each separately. This way I narrowed down the problem to this program: ``` resource "def" "kubernetes:apiextensions.k8s.io/v1:CustomResourceDefinition" { apiVersion = "string" kind = "string" spec = { versions = [{}] } } ``` Debugging this in Go program-gen didn't show an obvious error and it kept on hanging. However I noticed that we lowering expressions twice: once for the entirety of resource inputs when generating resources and again when generating the expressions separately. Lowering expressions has been the source of many bugs and it seems to trip up program-gen a lot and suspected something wrong was going on here, so I simplified it to lower the expressions once when we generate resource inputs. This fixed the hang issue as well as a few of our test programs (see diffs for test programs and tests schemas) Tested this against the full kubernetes schema and we can now generate the full Go program: https://gist.github.com/Zaid-Ajaj/3ac734536969a989edae92219968d51f > The second time we lower expressions not only is redundant but also can generate invalid code if the lowered expressions have temporary variables because program-gen would just emit these variables inside inline expressions like objects and lists which gives invalid Go code. Resolves part of #16463
2024-07-05 12:42:41 +00:00
&corev1.ContainerPortArgs{
ContainerPort: pulumi.Int(80),
},
},
[docs/go-program-gen] Fix generating constructor syntax examples for kubernetes (#16574) In this PR we fix generating constructor syntax examples for Kubernetes. The problem initially was due to generating a PCL program with syntax errors for the kubernetes schema. The syntax error was happening because we emitted properties `$ref` and `$schema` which are not valid identifiers in PCL. Fixing this was simple enough, we only needed to quote these properties that start with dollar signs and we get a valid PCL program. Full PCL program for kubernetes: https://gist.github.com/Zaid-Ajaj/abe899430a0b5f99a428934dcac75d52 However, the valid PCL program wouldn't convert to Go with program-gen and it would hang without showing any errors or stack traces. I wrote a script to split the programs for each resource and convert each separately. This way I narrowed down the problem to this program: ``` resource "def" "kubernetes:apiextensions.k8s.io/v1:CustomResourceDefinition" { apiVersion = "string" kind = "string" spec = { versions = [{}] } } ``` Debugging this in Go program-gen didn't show an obvious error and it kept on hanging. However I noticed that we lowering expressions twice: once for the entirety of resource inputs when generating resources and again when generating the expressions separately. Lowering expressions has been the source of many bugs and it seems to trip up program-gen a lot and suspected something wrong was going on here, so I simplified it to lower the expressions once when we generate resource inputs. This fixed the hang issue as well as a few of our test programs (see diffs for test programs and tests schemas) Tested this against the full kubernetes schema and we can now generate the full Go program: https://gist.github.com/Zaid-Ajaj/3ac734536969a989edae92219968d51f > The second time we lower expressions not only is redundant but also can generate invalid code if the lowered expressions have temporary variables because program-gen would just emit these variables inside inline expressions like objects and lists which gives invalid Go code. Resolves part of #16463
2024-07-05 12:42:41 +00:00
Resources: &corev1.ResourceRequirementsArgs{
Limits: pulumi.StringMap{
"memory": pulumi.String("20Mi"),
"cpu": pulumi.String("0.2"),
},
},
},
[docs/go-program-gen] Fix generating constructor syntax examples for kubernetes (#16574) In this PR we fix generating constructor syntax examples for Kubernetes. The problem initially was due to generating a PCL program with syntax errors for the kubernetes schema. The syntax error was happening because we emitted properties `$ref` and `$schema` which are not valid identifiers in PCL. Fixing this was simple enough, we only needed to quote these properties that start with dollar signs and we get a valid PCL program. Full PCL program for kubernetes: https://gist.github.com/Zaid-Ajaj/abe899430a0b5f99a428934dcac75d52 However, the valid PCL program wouldn't convert to Go with program-gen and it would hang without showing any errors or stack traces. I wrote a script to split the programs for each resource and convert each separately. This way I narrowed down the problem to this program: ``` resource "def" "kubernetes:apiextensions.k8s.io/v1:CustomResourceDefinition" { apiVersion = "string" kind = "string" spec = { versions = [{}] } } ``` Debugging this in Go program-gen didn't show an obvious error and it kept on hanging. However I noticed that we lowering expressions twice: once for the entirety of resource inputs when generating resources and again when generating the expressions separately. Lowering expressions has been the source of many bugs and it seems to trip up program-gen a lot and suspected something wrong was going on here, so I simplified it to lower the expressions once when we generate resource inputs. This fixed the hang issue as well as a few of our test programs (see diffs for test programs and tests schemas) Tested this against the full kubernetes schema and we can now generate the full Go program: https://gist.github.com/Zaid-Ajaj/3ac734536969a989edae92219968d51f > The second time we lower expressions not only is redundant but also can generate invalid code if the lowered expressions have temporary variables because program-gen would just emit these variables inside inline expressions like objects and lists which gives invalid Go code. Resolves part of #16463
2024-07-05 12:42:41 +00:00
&corev1.ContainerArgs{
Name: pulumi.String("nginx2"),
Image: pulumi.String("nginx:1.14-alpine"),
Ports: corev1.ContainerPortArray{
[docs/go-program-gen] Fix generating constructor syntax examples for kubernetes (#16574) In this PR we fix generating constructor syntax examples for Kubernetes. The problem initially was due to generating a PCL program with syntax errors for the kubernetes schema. The syntax error was happening because we emitted properties `$ref` and `$schema` which are not valid identifiers in PCL. Fixing this was simple enough, we only needed to quote these properties that start with dollar signs and we get a valid PCL program. Full PCL program for kubernetes: https://gist.github.com/Zaid-Ajaj/abe899430a0b5f99a428934dcac75d52 However, the valid PCL program wouldn't convert to Go with program-gen and it would hang without showing any errors or stack traces. I wrote a script to split the programs for each resource and convert each separately. This way I narrowed down the problem to this program: ``` resource "def" "kubernetes:apiextensions.k8s.io/v1:CustomResourceDefinition" { apiVersion = "string" kind = "string" spec = { versions = [{}] } } ``` Debugging this in Go program-gen didn't show an obvious error and it kept on hanging. However I noticed that we lowering expressions twice: once for the entirety of resource inputs when generating resources and again when generating the expressions separately. Lowering expressions has been the source of many bugs and it seems to trip up program-gen a lot and suspected something wrong was going on here, so I simplified it to lower the expressions once when we generate resource inputs. This fixed the hang issue as well as a few of our test programs (see diffs for test programs and tests schemas) Tested this against the full kubernetes schema and we can now generate the full Go program: https://gist.github.com/Zaid-Ajaj/3ac734536969a989edae92219968d51f > The second time we lower expressions not only is redundant but also can generate invalid code if the lowered expressions have temporary variables because program-gen would just emit these variables inside inline expressions like objects and lists which gives invalid Go code. Resolves part of #16463
2024-07-05 12:42:41 +00:00
&corev1.ContainerPortArgs{
ContainerPort: pulumi.Int(80),
},
},
[docs/go-program-gen] Fix generating constructor syntax examples for kubernetes (#16574) In this PR we fix generating constructor syntax examples for Kubernetes. The problem initially was due to generating a PCL program with syntax errors for the kubernetes schema. The syntax error was happening because we emitted properties `$ref` and `$schema` which are not valid identifiers in PCL. Fixing this was simple enough, we only needed to quote these properties that start with dollar signs and we get a valid PCL program. Full PCL program for kubernetes: https://gist.github.com/Zaid-Ajaj/abe899430a0b5f99a428934dcac75d52 However, the valid PCL program wouldn't convert to Go with program-gen and it would hang without showing any errors or stack traces. I wrote a script to split the programs for each resource and convert each separately. This way I narrowed down the problem to this program: ``` resource "def" "kubernetes:apiextensions.k8s.io/v1:CustomResourceDefinition" { apiVersion = "string" kind = "string" spec = { versions = [{}] } } ``` Debugging this in Go program-gen didn't show an obvious error and it kept on hanging. However I noticed that we lowering expressions twice: once for the entirety of resource inputs when generating resources and again when generating the expressions separately. Lowering expressions has been the source of many bugs and it seems to trip up program-gen a lot and suspected something wrong was going on here, so I simplified it to lower the expressions once when we generate resource inputs. This fixed the hang issue as well as a few of our test programs (see diffs for test programs and tests schemas) Tested this against the full kubernetes schema and we can now generate the full Go program: https://gist.github.com/Zaid-Ajaj/3ac734536969a989edae92219968d51f > The second time we lower expressions not only is redundant but also can generate invalid code if the lowered expressions have temporary variables because program-gen would just emit these variables inside inline expressions like objects and lists which gives invalid Go code. Resolves part of #16463
2024-07-05 12:42:41 +00:00
Resources: &corev1.ResourceRequirementsArgs{
Limits: pulumi.StringMap{
"memory": pulumi.String("20Mi"),
"cpu": pulumi.String("0.2"),
},
},
},
},
},
})
if err != nil {
return err
}
// Test that we can assign from a constant without type errors
_ := bar.Kind
return nil
})
}