Skip to content

Commit

Permalink
Enable Server-Side Apply mode by default (#2206)
Browse files Browse the repository at this point in the history
* Fix failing test

This test was accessing an Output property without using an apply, and the value had not resolved already. Apparently this was working with the legacy Client-Side Apply implementation, but the test code was unsafe.

* Fix replacement behavior for immutable fields

With Server-side Apply previews, updating an immutable field in a resource will result in a 422 error code from the API server. In these cases, Pulumi will replace the resource, so we need to ignore the error rather than failing the preview.
  • Loading branch information
lblackstone committed Oct 19, 2022
1 parent d322a3b commit 5960e58
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 37 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## Unreleased

Important Note -- This release changes the Provider default to enable Server-Side Apply mode. This change is
backward compatible, and should not require further action from users. The `enableServerSideApply` flag is
still present, so you may explicitly opt out if you run into any problems. This flag will be removed in the
next major release (`v4`) of the provider. See https://www.pulumi.com/registry/packages/kubernetes/how-to-guides/managing-resources-with-server-side-apply/
for additional information about using Server-Side Apply with Pulumi's Kubernetes provider.

- Fix values precedence in helm release (https://github.com/pulumi/pulumi-kubernetes/pull/2191)
- Enable Server-Side Apply mode by default (https://github.com/pulumi/pulumi-kubernetes/pull/2206)

## 3.21.4 (September 22, 2022)

Expand Down
4 changes: 2 additions & 2 deletions provider/cmd/pulumi-resource-kubernetes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
},
"enableServerSideApply": {
"type": "boolean",
"description": "BETA FEATURE - If present and set to true, enable Server-Side Apply mode.\nSee https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.\nThis feature is in developer preview, and is disabled by default."
"description": "If present and set to false, disable Server-Side Apply mode.\nSee https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details."
},
"kubeconfig": {
"type": "string",
Expand Down Expand Up @@ -57864,7 +57864,7 @@
},
"enableServerSideApply": {
"type": "boolean",
"description": "BETA FEATURE - If present and set to true, enable Server-Side Apply mode.\nSee https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.\nThis feature is in developer preview, and is disabled by default.",
"description": "If present and set to false, disable Server-Side Apply mode.\nSee https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.",
"defaultInfo": {
"environment": [
"PULUMI_K8S_ENABLE_SERVER_SIDE_APPLY"
Expand Down
4 changes: 2 additions & 2 deletions provider/pkg/gen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func PulumiSchema(swagger map[string]interface{}) pschema.PackageSpec {
DeprecationMessage: "This option has been replaced by `enableServerSideApply`.",
},
"enableServerSideApply": {
Description: "BETA FEATURE - If present and set to true, enable Server-Side Apply mode.\nSee https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.\nThis feature is in developer preview, and is disabled by default.",
Description: "If present and set to false, disable Server-Side Apply mode.\nSee https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
},
"enableReplaceCRD": {
Expand Down Expand Up @@ -157,7 +157,7 @@ func PulumiSchema(swagger map[string]interface{}) pschema.PackageSpec {
"PULUMI_K8S_ENABLE_SERVER_SIDE_APPLY",
},
},
Description: "BETA FEATURE - If present and set to true, enable Server-Side Apply mode.\nSee https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.\nThis feature is in developer preview, and is disabled by default.",
Description: "If present and set to false, disable Server-Side Apply mode.\nSee https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
},
"enableReplaceCRD": {
Expand Down
10 changes: 6 additions & 4 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequ
CurrentContext: vars["kubernetes:config:context"],
}

// TODO: Simplify / factor out the provider flag parsing. Currently lots of error-prone copy-paste code here.

deleteUnreachable := func() bool {
// If the provider flag is set, use that value to determine behavior. This will override the ENV var.
if enabled, exists := vars["kubernetes:config:deleteUnreachable"]; exists {
Expand Down Expand Up @@ -442,8 +444,7 @@ func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequ
if enabled, exists := os.LookupEnv("PULUMI_K8S_ENABLE_SERVER_SIDE_APPLY"); exists {
return enabled == trueStr
}
// Default to false.
return false
return true
}
if enableServerSideApply() {
k.enableDryRun = true
Expand Down Expand Up @@ -2755,10 +2756,11 @@ func (k *kubeProvider) tryServerSidePatch(
return nil, nil, false, err
}
if se, isStatusError := err.(*errors.StatusError); isStatusError {
// If the resource field is immutable.
if se.Status().Code == http.StatusUnprocessableEntity ||
strings.Contains(se.ErrStatus.Message, "field is immutable") {
return nil, nil, false, err
// This error occurs if the resource field is immutable.
// Ignore this error since this case is handled by the replacement logic.
return nil, nil, false, nil
}
}
if err.Error() == "name is required" {
Expand Down
3 changes: 1 addition & 2 deletions sdk/dotnet/Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ public void Set(T value)

private static readonly __Value<bool?> _enableServerSideApply = new __Value<bool?>(() => __config.GetBoolean("enableServerSideApply"));
/// <summary>
/// BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
/// If present and set to false, disable Server-Side Apply mode.
/// See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
/// This feature is in developer preview, and is disabled by default.
/// </summary>
public static bool? EnableServerSideApply
{
Expand Down
3 changes: 1 addition & 2 deletions sdk/dotnet/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ public sealed class ProviderArgs : global::Pulumi.ResourceArgs
public Input<bool>? EnableReplaceCRD { get; set; }

/// <summary>
/// BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
/// If present and set to false, disable Server-Side Apply mode.
/// See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
/// This feature is in developer preview, and is disabled by default.
/// </summary>
[Input("enableServerSideApply", json: true)]
public Input<bool>? EnableServerSideApply { get; set; }
Expand Down
3 changes: 1 addition & 2 deletions sdk/go/kubernetes/config/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions sdk/go/kubernetes/provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions sdk/java/src/main/java/com/pulumi/kubernetes/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ public Optional<Boolean> enableReplaceCRD() {
return Codegen.booleanProp("enableReplaceCRD").config(config).get();
}
/**
* BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
* If present and set to false, disable Server-Side Apply mode.
* See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
* This feature is in developer preview, and is disabled by default.
*
*/
public Optional<Boolean> enableServerSideApply() {
Expand Down
12 changes: 4 additions & 8 deletions sdk/java/src/main/java/com/pulumi/kubernetes/ProviderArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,16 @@ public Optional<Output<Boolean>> enableReplaceCRD() {
}

/**
* BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
* If present and set to false, disable Server-Side Apply mode.
* See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
* This feature is in developer preview, and is disabled by default.
*
*/
@Import(name="enableServerSideApply", json=true)
private @Nullable Output<Boolean> enableServerSideApply;

/**
* @return BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
* @return If present and set to false, disable Server-Side Apply mode.
* See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
* This feature is in developer preview, and is disabled by default.
*
*/
public Optional<Output<Boolean>> enableServerSideApply() {
Expand Down Expand Up @@ -473,9 +471,8 @@ public Builder enableReplaceCRD(Boolean enableReplaceCRD) {
}

/**
* @param enableServerSideApply BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
* @param enableServerSideApply If present and set to false, disable Server-Side Apply mode.
* See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
* This feature is in developer preview, and is disabled by default.
*
* @return builder
*
Expand All @@ -486,9 +483,8 @@ public Builder enableServerSideApply(@Nullable Output<Boolean> enableServerSideA
}

/**
* @param enableServerSideApply BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
* @param enableServerSideApply If present and set to false, disable Server-Side Apply mode.
* See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
* This feature is in developer preview, and is disabled by default.
*
* @return builder
*
Expand Down
3 changes: 1 addition & 2 deletions sdk/nodejs/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ export interface ProviderArgs {
*/
enableReplaceCRD?: pulumi.Input<boolean>;
/**
* BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
* If present and set to false, disable Server-Side Apply mode.
* See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
* This feature is in developer preview, and is disabled by default.
*/
enableServerSideApply?: pulumi.Input<boolean>;
/**
Expand Down
9 changes: 3 additions & 6 deletions sdk/python/pulumi_kubernetes/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ def __init__(__self__, *,
2. The `PULUMI_K8S_ENABLE_CONFIGMAP_MUTABLE` environment variable.
:param pulumi.Input[bool] enable_dry_run: Deprecated. If present and set to true, enable server-side diff calculations.
:param pulumi.Input[bool] enable_replace_crd: Obsolete. This option has no effect.
:param pulumi.Input[bool] enable_server_side_apply: BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
:param pulumi.Input[bool] enable_server_side_apply: If present and set to false, disable Server-Side Apply mode.
See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
This feature is in developer preview, and is disabled by default.
:param pulumi.Input['HelmReleaseSettingsArgs'] helm_release_settings: Options to configure the Helm Release resource.
:param pulumi.Input['KubeClientSettingsArgs'] kube_client_settings: Options for tuning the Kubernetes client used by a Provider.
:param pulumi.Input[str] kubeconfig: The contents of a kubeconfig file or the path to a kubeconfig file.
Expand Down Expand Up @@ -195,9 +194,8 @@ def enable_replace_crd(self, value: Optional[pulumi.Input[bool]]):
@pulumi.getter(name="enableServerSideApply")
def enable_server_side_apply(self) -> Optional[pulumi.Input[bool]]:
"""
BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
If present and set to false, disable Server-Side Apply mode.
See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
This feature is in developer preview, and is disabled by default.
"""
return pulumi.get(self, "enable_server_side_apply")

Expand Down Expand Up @@ -338,9 +336,8 @@ def __init__(__self__,
2. The `PULUMI_K8S_ENABLE_CONFIGMAP_MUTABLE` environment variable.
:param pulumi.Input[bool] enable_dry_run: Deprecated. If present and set to true, enable server-side diff calculations.
:param pulumi.Input[bool] enable_replace_crd: Obsolete. This option has no effect.
:param pulumi.Input[bool] enable_server_side_apply: BETA FEATURE - If present and set to true, enable Server-Side Apply mode.
:param pulumi.Input[bool] enable_server_side_apply: If present and set to false, disable Server-Side Apply mode.
See https://github.com/pulumi/pulumi-kubernetes/issues/2011 for additional details.
This feature is in developer preview, and is disabled by default.
:param pulumi.Input[pulumi.InputType['HelmReleaseSettingsArgs']] helm_release_settings: Options to configure the Helm Release resource.
:param pulumi.Input[pulumi.InputType['KubeClientSettingsArgs']] kube_client_settings: Options for tuning the Kubernetes client used by a Provider.
:param pulumi.Input[str] kubeconfig: The contents of a kubeconfig file or the path to a kubeconfig file.
Expand Down
2 changes: 1 addition & 1 deletion tests/sdk/python/smoke-test-old/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
]
})

pulumi.export("ip", pod.status["pod_ip"])
pulumi.export("ip", pod.status.apply(lambda s: s.pod_ip))

0 comments on commit 5960e58

Please sign in to comment.