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

Add PULUMI_K8S_ENABLE_PATCH_FORCE env var support #2260

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
16 changes: 14 additions & 2 deletions provider/pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package await
import (
"context"
"fmt"
"os"
"strings"

"github.com/pulumi/pulumi-kubernetes/provider/v3/pkg/clients"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Might be nice if the value could be any case or 1 (i.e. "truthy"), but I wouldn't block on it, this is fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I followed precedence for other env vars on this provider, but it would be a nice thing to change. I'll open an issue to follow up on that.

Copy link
Member Author

Choose a reason for hiding this comment

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

}
return false
}