Skip to content

Commit

Permalink
[sdk/python] Handle CRDs with status field input (#2183)
Browse files Browse the repository at this point in the history
Although .status is an output-only field for CRDs, this is a frequent occurrence in real-world manifests. Manually delete the status field in the YAML handler to avoid an error on deserialization.
  • Loading branch information
lblackstone authored Sep 21, 2022
1 parent e0e2db6 commit bb1c93d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

- Fix Helm Chart preview with unconfigured provider (C#) (https://github.com/pulumi/pulumi-kubernetes/issues/2162)
- [sdk/python] Handle CRDs with status field input (https://github.com/pulumi/pulumi-kubernetes/issues/2183)

## 3.21.2 (September 1, 2022)

Expand Down
3 changes: 3 additions & 0 deletions provider/cmd/pulumi-gen-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ func writePythonClient(pkg *schema.Package, outdir string, templateDir string) {
if resourcesToFilterFromTemplate.Has(tok) {
continue
}
if resource.Name == "CustomResourceDefinition" { // Use manual overlay in yaml.tmpl
continue
}
if strings.HasSuffix(resource.Name, "Patch") {
continue
}
Expand Down
14 changes: 14 additions & 0 deletions provider/pkg/gen/python-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,20 @@ def _parse_yaml_object(
lambda x: (f"{{.GVK}}:{x}",
{{.Name}}(f"{x}", opts, **obj)))]
{{- end}}
if gvk == "apiextensions.k8s.io/v1/CustomResourceDefinition":
# Import locally to avoid name collisions.
from pulumi_kubernetes.apiextensions.v1 import CustomResourceDefinition
obj.pop("status", None) # Delete output-only status field to avoid errors.
return [identifier.apply(
lambda x: (f"apiextensions.k8s.io/v1/CustomResourceDefinition:{x}",
CustomResourceDefinition(f"{x}", opts, **obj)))]
if gvk == "apiextensions.k8s.io/v1beta1/CustomResourceDefinition":
# Import locally to avoid name collisions.
from pulumi_kubernetes.apiextensions.v1beta1 import CustomResourceDefinition
obj.pop("status", None) # Delete output-only status field to avoid errors.
return [identifier.apply(
lambda x: (f"apiextensions.k8s.io/v1beta1/CustomResourceDefinition:{x}",
CustomResourceDefinition(f"{x}", opts, **obj)))]
return [identifier.apply(
lambda x: (f"{gvk}:{x}",
CustomResource(f"{x}", api_version, kind, spec, metadata, opts)))]
26 changes: 14 additions & 12 deletions sdk/python/pulumi_kubernetes/yaml/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,24 +539,12 @@ def _parse_yaml_object(
return [identifier.apply(
lambda x: (f"admissionregistration.k8s.io/v1beta1/ValidatingWebhookConfigurationList:{x}",
ValidatingWebhookConfigurationList(f"{x}", opts, **obj)))]
if gvk == "apiextensions.k8s.io/v1/CustomResourceDefinition":
# Import locally to avoid name collisions.
from pulumi_kubernetes.apiextensions.v1 import CustomResourceDefinition
return [identifier.apply(
lambda x: (f"apiextensions.k8s.io/v1/CustomResourceDefinition:{x}",
CustomResourceDefinition(f"{x}", opts, **obj)))]
if gvk == "apiextensions.k8s.io/v1/CustomResourceDefinitionList":
# Import locally to avoid name collisions.
from pulumi_kubernetes.apiextensions.v1 import CustomResourceDefinitionList
return [identifier.apply(
lambda x: (f"apiextensions.k8s.io/v1/CustomResourceDefinitionList:{x}",
CustomResourceDefinitionList(f"{x}", opts, **obj)))]
if gvk == "apiextensions.k8s.io/v1beta1/CustomResourceDefinition":
# Import locally to avoid name collisions.
from pulumi_kubernetes.apiextensions.v1beta1 import CustomResourceDefinition
return [identifier.apply(
lambda x: (f"apiextensions.k8s.io/v1beta1/CustomResourceDefinition:{x}",
CustomResourceDefinition(f"{x}", opts, **obj)))]
if gvk == "apiextensions.k8s.io/v1beta1/CustomResourceDefinitionList":
# Import locally to avoid name collisions.
from pulumi_kubernetes.apiextensions.v1beta1 import CustomResourceDefinitionList
Expand Down Expand Up @@ -1817,6 +1805,20 @@ def _parse_yaml_object(
return [identifier.apply(
lambda x: (f"storage.k8s.io/v1beta1/VolumeAttachmentList:{x}",
VolumeAttachmentList(f"{x}", opts, **obj)))]
if gvk == "apiextensions.k8s.io/v1/CustomResourceDefinition":
# Import locally to avoid name collisions.
from pulumi_kubernetes.apiextensions.v1 import CustomResourceDefinition
obj.pop("status", None) # Delete output-only status field to avoid errors.
return [identifier.apply(
lambda x: (f"apiextensions.k8s.io/v1/CustomResourceDefinition:{x}",
CustomResourceDefinition(f"{x}", opts, **obj)))]
if gvk == "apiextensions.k8s.io/v1beta1/CustomResourceDefinition":
# Import locally to avoid name collisions.
from pulumi_kubernetes.apiextensions.v1beta1 import CustomResourceDefinition
obj.pop("status", None) # Delete output-only status field to avoid errors.
return [identifier.apply(
lambda x: (f"apiextensions.k8s.io/v1beta1/CustomResourceDefinition:{x}",
CustomResourceDefinition(f"{x}", opts, **obj)))]
return [identifier.apply(
lambda x: (f"{gvk}:{x}",
CustomResource(f"{x}", api_version, kind, spec, metadata, opts)))]

0 comments on commit bb1c93d

Please sign in to comment.