From 9208a2f3999565090893847683ab3ce3d4889c09 Mon Sep 17 00:00:00 2001 From: Levi Blackstone Date: Fri, 9 Dec 2022 13:42:47 -0700 Subject: [PATCH] Add `PULUMI_K8S_ENABLE_PATCH_FORCE` env var support --- CHANGELOG.md | 2 ++ provider/pkg/await/await.go | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba1d27362b..fb6fa072a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased +- Add `PULUMI_K8S_ENABLE_PATCH_FORCE` env var support (https://github.com/pulumi/pulumi-kubernetes/pulls/2260) + ## 3.23.0 (December 8, 2022) - Expose the allowNullValues boolean as an InputProperty so that it can be set in SDKs (https://github.com/pulumi/pulumi-kubernetes/pulls/2255) diff --git a/provider/pkg/await/await.go b/provider/pkg/await/await.go index 4e188585a1..761a1f9a84 100644 --- a/provider/pkg/await/await.go +++ b/provider/pkg/await/await.go @@ -17,6 +17,7 @@ package await import ( "context" "fmt" + "os" "strings" "github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/clients" @@ -180,7 +181,7 @@ func Creation(c CreateConfig) (*unstructured.Unstructured, error) { if c.ServerSideApply { // Always force on preview to avoid erroneous conflict errors for resource replacements - force := c.Preview || metadata.IsAnnotationTrue(c.Inputs, metadata.AnnotationPatchForce) + force := c.Preview || patchForce(c.Inputs) options := metav1.PatchOptions{ FieldManager: c.FieldManager, Force: &force, @@ -420,7 +421,7 @@ func Update(c UpdateConfig) (*unstructured.Unstructured, error) { if err != nil { return nil, err } - force := metadata.IsAnnotationTrue(c.Inputs, metadata.AnnotationPatchForce) + force := patchForce(c.Inputs) options := metav1.PatchOptions{ FieldManager: c.FieldManager, Force: &force, @@ -691,3 +692,14 @@ func checkIfResourceDeleted( func clearStatus(context context.Context, host *pulumiprovider.HostClient, urn resource.URN) error { return host.LogStatus(context, diag.Info, urn, "") } + +// patchForce decides whether to overwrite patch conflicts. +func patchForce(obj *unstructured.Unstructured) bool { + if metadata.IsAnnotationTrue(obj, metadata.AnnotationPatchForce) { + return true + } + if enabled, exists := os.LookupEnv("PULUMI_K8S_ENABLE_PATCH_FORCE"); exists { + return enabled == "true" + } + return false +}