Skip to content

Commit

Permalink
Add Patch resources to all SDKs (#2043)
Browse files Browse the repository at this point in the history
Add Patch resources for all Kubernetes resource types that can be used to patch existing cluster resources rather than creating a new resource under Pulumi management. See #2011 for additional details on the background and design of this feature.

* Update SDK dep

* Disable managed-by label for SSA

* Remove managedFields from patch calculation

* Require SSA mode for Patch resources

* DryRun -> Preview

* Improve error handling

* Update some comments
  • Loading branch information
lblackstone committed Jul 12, 2022
1 parent 83a14d1 commit 63ba49e
Show file tree
Hide file tree
Showing 2,149 changed files with 446,517 additions and 40,352 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## Unreleased

- Implement Server-Side Apply mode (https://github.com/pulumi/pulumi-kubernetes/pull/2029)
- Add Patch resources to all SDKs (https://github.com/pulumi/pulumi-kubernetes/pull/2043)
- Add awaiter for service-account-token secret (https://github.com/pulumi/pulumi-kubernetes/pull/2048)
- All Java packages changed to be more intuitive, unfortunately this is a breaking change for Java version (https://github.com/pulumi/pulumi-kubernetes/pull/2055)
- Add Java packages overrides to schema (https://github.com/pulumi/pulumi-kubernetes/pull/2055)

## 3.19.4 (June 21, 2022)

Expand Down
65 changes: 42 additions & 23 deletions provider/cmd/pulumi-gen-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ func writeNodeJSClient(pkg *schema.Package, outdir, templateDir string) {
if resource.Package == "" {
continue
}
if strings.HasSuffix(resource.Name, "Patch") {
continue
}
tr := gen.TemplateResource{
Name: resource.Name,
Package: resource.Package,
Expand Down Expand Up @@ -212,11 +215,12 @@ func writeNodeJSClient(pkg *schema.Package, outdir, templateDir string) {
templateResources.Packages = packages.SortedValues()

overlays := map[string][]byte{
"apiextensions/customResource.ts": mustLoadFile(filepath.Join(templateDir, "apiextensions", "customResource.ts")),
"helm/v2/helm.ts": mustLoadFile(filepath.Join(templateDir, "helm", "v2", "helm.ts")),
"helm/v3/helm.ts": mustLoadFile(filepath.Join(templateDir, "helm", "v3", "helm.ts")),
"kustomize/kustomize.ts": mustLoadFile(filepath.Join(templateDir, "kustomize", "kustomize.ts")),
"yaml/yaml.ts": mustRenderTemplate(filepath.Join(templateDir, "yaml", "yaml.tmpl"), templateResources),
"apiextensions/customResource.ts": mustLoadFile(filepath.Join(templateDir, "apiextensions", "customResource.ts")),
"apiextensions/customResourcePatch.ts": mustLoadFile(filepath.Join(templateDir, "apiextensions", "customResourcePatch.ts")),
"helm/v2/helm.ts": mustLoadFile(filepath.Join(templateDir, "helm", "v2", "helm.ts")),
"helm/v3/helm.ts": mustLoadFile(filepath.Join(templateDir, "helm", "v3", "helm.ts")),
"kustomize/kustomize.ts": mustLoadFile(filepath.Join(templateDir, "kustomize", "kustomize.ts")),
"yaml/yaml.ts": mustRenderTemplate(filepath.Join(templateDir, "yaml", "yaml.tmpl"), templateResources),
}
files, err := nodejsgen.GeneratePackage("pulumigen", pkg, overlays)
if err != nil {
Expand All @@ -241,6 +245,9 @@ func writePythonClient(pkg *schema.Package, outdir string, templateDir string) {
if resourcesToFilterFromTemplate.Has(tok) {
continue
}
if strings.HasSuffix(resource.Name, "Patch") {
continue
}
r := gen.TemplateResource{
Name: resource.Name,
Package: resource.Package,
Expand All @@ -253,11 +260,12 @@ func writePythonClient(pkg *schema.Package, outdir string, templateDir string) {
})

overlays := map[string][]byte{
"apiextensions/CustomResource.py": mustLoadFile(filepath.Join(templateDir, "apiextensions", "CustomResource.py")),
"helm/v2/helm.py": mustLoadFile(filepath.Join(templateDir, "helm", "v2", "helm.py")),
"helm/v3/helm.py": mustLoadFile(filepath.Join(templateDir, "helm", "v3", "helm.py")),
"kustomize/kustomize.py": mustLoadFile(filepath.Join(templateDir, "kustomize", "kustomize.py")),
"yaml/yaml.py": mustRenderTemplate(filepath.Join(templateDir, "yaml", "yaml.tmpl"), templateResources),
"apiextensions/CustomResource.py": mustLoadFile(filepath.Join(templateDir, "apiextensions", "CustomResource.py")),
"apiextensions/CustomResourcePatch.py": mustLoadFile(filepath.Join(templateDir, "apiextensions", "CustomResourcePatch.py")),
"helm/v2/helm.py": mustLoadFile(filepath.Join(templateDir, "helm", "v2", "helm.py")),
"helm/v3/helm.py": mustLoadFile(filepath.Join(templateDir, "helm", "v3", "helm.py")),
"kustomize/kustomize.py": mustLoadFile(filepath.Join(templateDir, "kustomize", "kustomize.py")),
"yaml/yaml.py": mustRenderTemplate(filepath.Join(templateDir, "yaml", "yaml.tmpl"), templateResources),
}

files, err := pythongen.GeneratePackage("pulumigen", pkg, overlays)
Expand All @@ -279,6 +287,9 @@ func writeDotnetClient(pkg *schema.Package, outdir, templateDir string) {
if resourcesToFilterFromTemplate.Has(tok) {
continue
}
if strings.HasSuffix(resource.Name, "Patch") {
continue
}
r := gen.TemplateResource{
Name: resource.Name,
Package: resource.Package,
Expand All @@ -290,19 +301,20 @@ func writeDotnetClient(pkg *schema.Package, outdir, templateDir string) {
return templateResources.Resources[i].Token < templateResources.Resources[j].Token
})
overlays := map[string][]byte{
"ApiExtensions/CustomResource.cs": mustLoadFile(filepath.Join(templateDir, "apiextensions", "CustomResource.cs")),
"Helm/ChartBase.cs": mustLoadFile(filepath.Join(templateDir, "helm", "ChartBase.cs")),
"Helm/Unwraps.cs": mustLoadFile(filepath.Join(templateDir, "helm", "Unwraps.cs")),
"Helm/V2/Chart.cs": mustLoadFile(filepath.Join(templateDir, "helm", "v2", "Chart.cs")),
"Helm/V3/Chart.cs": mustLoadFile(filepath.Join(templateDir, "helm", "v3", "Chart.cs")),
"Helm/V3/Invokes.cs": mustLoadFile(filepath.Join(templateDir, "helm", "v3", "Invokes.cs")),
"Kustomize/Directory.cs": mustLoadFile(filepath.Join(templateDir, "kustomize", "Directory.cs")),
"Kustomize/Invokes.cs": mustLoadFile(filepath.Join(templateDir, "kustomize", "Invokes.cs")),
"Yaml/ConfigFile.cs": mustLoadFile(filepath.Join(templateDir, "yaml", "ConfigFile.cs")),
"Yaml/ConfigGroup.cs": mustLoadFile(filepath.Join(templateDir, "yaml", "ConfigGroup.cs")),
"Yaml/Invokes.cs": mustLoadFile(filepath.Join(templateDir, "yaml", "Invokes.cs")),
"Yaml/TransformationAction.cs": mustLoadFile(filepath.Join(templateDir, "yaml", "TransformationAction.cs")),
"Yaml/Yaml.cs": mustRenderTemplate(filepath.Join(templateDir, "yaml", "yaml.tmpl"), templateResources),
"ApiExtensions/CustomResource.cs": mustLoadFile(filepath.Join(templateDir, "apiextensions", "CustomResource.cs")),
"ApiExtensions/CustomResourcePatch.cs": mustLoadFile(filepath.Join(templateDir, "apiextensions", "CustomResourcePatch.cs")),
"Helm/ChartBase.cs": mustLoadFile(filepath.Join(templateDir, "helm", "ChartBase.cs")),
"Helm/Unwraps.cs": mustLoadFile(filepath.Join(templateDir, "helm", "Unwraps.cs")),
"Helm/V2/Chart.cs": mustLoadFile(filepath.Join(templateDir, "helm", "v2", "Chart.cs")),
"Helm/V3/Chart.cs": mustLoadFile(filepath.Join(templateDir, "helm", "v3", "Chart.cs")),
"Helm/V3/Invokes.cs": mustLoadFile(filepath.Join(templateDir, "helm", "v3", "Invokes.cs")),
"Kustomize/Directory.cs": mustLoadFile(filepath.Join(templateDir, "kustomize", "Directory.cs")),
"Kustomize/Invokes.cs": mustLoadFile(filepath.Join(templateDir, "kustomize", "Invokes.cs")),
"Yaml/ConfigFile.cs": mustLoadFile(filepath.Join(templateDir, "yaml", "ConfigFile.cs")),
"Yaml/ConfigGroup.cs": mustLoadFile(filepath.Join(templateDir, "yaml", "ConfigGroup.cs")),
"Yaml/Invokes.cs": mustLoadFile(filepath.Join(templateDir, "yaml", "Invokes.cs")),
"Yaml/TransformationAction.cs": mustLoadFile(filepath.Join(templateDir, "yaml", "TransformationAction.cs")),
"Yaml/Yaml.cs": mustRenderTemplate(filepath.Join(templateDir, "yaml", "yaml.tmpl"), templateResources),
}

files, err := dotnetgen.GeneratePackage("pulumigen", pkg, overlays)
Expand Down Expand Up @@ -360,6 +372,9 @@ func writeGoClient(pkg *schema.Package, outdir string, templateDir string) {
if resourcesToFilterFromTemplate.Has(tok) {
continue
}
if strings.HasSuffix(resource.Name, "Patch") {
continue
}
r := gen.TemplateResource{
Alias: resource.Alias,
Name: resource.Name,
Expand All @@ -374,6 +389,7 @@ func writeGoClient(pkg *schema.Package, outdir string, templateDir string) {

files["kubernetes/customPulumiTypes.go"] = mustLoadGoFile(filepath.Join(templateDir, "customPulumiTypes.go"))
files["kubernetes/apiextensions/customResource.go"] = mustLoadGoFile(filepath.Join(templateDir, "apiextensions", "customResource.go"))
files["kubernetes/apiextensions/customResourcePatch.go"] = mustLoadGoFile(filepath.Join(templateDir, "apiextensions", "customResourcePatch.go"))
files["kubernetes/helm/v2/chart.go"] = mustLoadGoFile(filepath.Join(templateDir, "helm", "v2", "chart.go"))
files["kubernetes/helm/v2/pulumiTypes.go"] = mustLoadGoFile(filepath.Join(templateDir, "helm", "v2", "pulumiTypes.go"))
files["kubernetes/helm/v3/chart.go"] = mustLoadGoFile(filepath.Join(templateDir, "helm", "v3", "chart.go"))
Expand Down Expand Up @@ -441,6 +457,9 @@ func genK8sResourceTypes(pkg *schema.Package) {
if resource.IsOverlay {
continue
}
if strings.HasSuffix(kind, "Patch") {
continue
}

groupVersions.Add(groupVersion)
kinds.Add(kind)
Expand Down
Loading

0 comments on commit 63ba49e

Please sign in to comment.