Skip to content

Commit

Permalink
Don't use the last-applied-configuration annotation for CRDs (#1882)
Browse files Browse the repository at this point in the history
* Remove handling code for enableReplaceCRD

* Add deprecation notice for enableReplaceCRD
  • Loading branch information
lblackstone committed May 25, 2022
1 parent 6fa7689 commit 308be3d
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 60 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
## Unreleased

Note: The `kubernetes:helm/v2:Chart` API was deprecated in this update and will be removed in a future release. The
`kubernetes:helm/v3:Chart` resource is backward compatible, so changing the import path should not cause any resource
updates.
### Deprecations

- The `kubernetes:helm/v2:Chart` API is deprecated in this update and will be removed in a future release. The
`kubernetes:helm/v3:Chart` resource is backward compatible, so changing the import path should not cause any resource
updates.
- The `enableReplaceCRD` option on the Provider is deprecated in the update and will be removed in a future release.
The behavior formerly enabled by this option is now default, and this option is ignored by the provider.

### Improvements

- Deprecate helm/v2:Chart resources (https://github.com/pulumi/pulumi-kubernetes/pull/1990)
- Don't use the last-applied-configuration annotation for CRDs (https://github.com/pulumi/pulumi-kubernetes/pull/1882)

## 3.19.0 (May 3, 2022)

Expand Down
8 changes: 5 additions & 3 deletions provider/cmd/pulumi-resource-kubernetes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
},
"enableReplaceCRD": {
"type": "boolean",
"description": "BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.\nThis feature is in developer preview, and is disabled by default.\n\nThis config can be specified in the following ways, using this precedence:\n1. This `enableReplaceCRD` parameter.\n2. The `PULUMI_K8S_ENABLE_REPLACE_CRD` environment variable."
"description": "Obsolete. This option has no effect.",
"deprecationMessage": "This option is deprecated, and will be removed in a future release."
},
"kubeconfig": {
"type": "string",
Expand Down Expand Up @@ -31592,12 +31593,13 @@
},
"enableReplaceCRD": {
"type": "boolean",
"description": "BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.\nThis feature is in developer preview, and is disabled by default.",
"description": "Obsolete. This option has no effect.",
"defaultInfo": {
"environment": [
"PULUMI_K8S_ENABLE_REPLACE_CRD"
]
}
},
"deprecationMessage": "This option is deprecated, and will be removed in a future release."
},
"helmReleaseSettings": {
"$ref": "#/types/kubernetes:index:HelmReleaseSettings",
Expand Down
3 changes: 1 addition & 2 deletions provider/pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type ProviderConfig struct {
URN resource.URN
InitialAPIVersion string
ClusterVersion *cluster.ServerVersion
EnableReplaceCRD bool

ClientSet *clients.DynamicClientSet
DedupLogger *logging.DedupLogger
Expand Down Expand Up @@ -368,7 +367,7 @@ func Update(c UpdateConfig) (*unstructured.Unstructured, error) {
}

var currentOutputs *unstructured.Unstructured
if c.EnableReplaceCRD && clients.IsCRD(c.Inputs) {
if clients.IsCRD(c.Inputs) {
// Note: This feature is currently enabled with a provider feature flag, but is expected to eventually become
// the default behavior.

Expand Down
10 changes: 6 additions & 4 deletions provider/pkg/gen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ func PulumiSchema(swagger map[string]interface{}) pschema.PackageSpec {
TypeSpec: pschema.TypeSpec{Type: "boolean"},
},
"enableReplaceCRD": {
Description: "BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.\nThis feature is in developer preview, and is disabled by default.\n\nThis config can be specified in the following ways, using this precedence:\n1. This `enableReplaceCRD` parameter.\n2. The `PULUMI_K8S_ENABLE_REPLACE_CRD` environment variable.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
Description: "Obsolete. This option has no effect.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
DeprecationMessage: "This option is deprecated, and will be removed in a future release.",
},
"enableConfigMapMutable": {
Description: "BETA FEATURE - If present and set to true, allow ConfigMaps to be mutated.\nThis feature is in developer preview, and is disabled by default.\n\nThis config can be specified in the following ways using this precedence:\n1. This `enableConfigMapMutable` parameter.\n2. The `PULUMI_K8S_ENABLE_CONFIGMAP_MUTABLE` environment variable.",
Expand Down Expand Up @@ -142,8 +143,9 @@ func PulumiSchema(swagger map[string]interface{}) pschema.PackageSpec {
"PULUMI_K8S_ENABLE_REPLACE_CRD",
},
},
Description: "BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.\nThis feature is in developer preview, and is disabled by default.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
Description: "Obsolete. This option has no effect.",
TypeSpec: pschema.TypeSpec{Type: "boolean"},
DeprecationMessage: "This option is deprecated, and will be removed in a future release.",
},
"enableConfigMapMutable": {
DefaultInfo: &pschema.DefaultSpec{
Expand Down
35 changes: 12 additions & 23 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ type kubeProvider struct {
defaultNamespace string

enableDryRun bool
enableReplaceCRD bool
enableConfigMapMutable bool
enableSecrets bool
suppressDeprecationWarnings bool
Expand Down Expand Up @@ -419,22 +418,6 @@ func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequ
k.enableDryRun = true
}

enableReplaceCRD := 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:enableReplaceCRD"]; exists {
return enabled == trueStr
}
// If the provider flag is not set, fall back to the ENV var.
if enabled, exists := os.LookupEnv("PULUMI_K8S_ENABLE_REPLACE_CRD"); exists {
return enabled == trueStr
}
// Default to false.
return false
}
if enableReplaceCRD() {
k.enableReplaceCRD = true
}

enableConfigMapMutable := 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:enableConfigMapMutable"]; exists {
Expand Down Expand Up @@ -2188,7 +2171,6 @@ func (k *kubeProvider) Update(
Host: k.host,
URN: urn,
InitialAPIVersion: initialAPIVersion,
EnableReplaceCRD: k.enableReplaceCRD,
ClientSet: k.clientSet,
DedupLogger: logging.NewLogger(k.canceler.context, k.host, urn),
Resources: resources,
Expand Down Expand Up @@ -2575,15 +2557,23 @@ func (k *kubeProvider) tryServerSidePatch(oldInputs, newInputs *unstructured.Uns
}

func (k *kubeProvider) withLastAppliedConfig(config *unstructured.Unstructured) (*unstructured.Unstructured, error) {
if k.enableReplaceCRD && clients.IsCRD(config) {
// Skip last-applied-config annotation when CRD replacement is enabled.
return config, nil
}
if k.supportsDryRun(config.GroupVersionKind()) {
// Skip last-applied-config annotation if the resource supports server-side apply.
return config, nil
}

// CRDs are updated using a separate mechanism, so skip the last-applied-configuration annotation, and delete it
// if it was present from a previous update.
if clients.IsCRD(config) {
// Deep copy the config before returning.
config = config.DeepCopy()

annotations := getAnnotations(config)
delete(annotations, lastAppliedConfigKey)
config.SetAnnotations(annotations)
return config, nil
}

// Serialize the inputs and add the last-applied-configuration annotation.
marshaled, err := config.MarshalJSON()
if err != nil {
Expand All @@ -2594,7 +2584,6 @@ func (k *kubeProvider) withLastAppliedConfig(config *unstructured.Unstructured)
config = config.DeepCopy()

annotations := getAnnotations(config)

annotations[lastAppliedConfigKey] = string(marshaled)
config.SetAnnotations(annotations)
return config, nil
Expand Down
7 changes: 1 addition & 6 deletions sdk/dotnet/Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,7 @@ public void Set(T value)

private static readonly __Value<bool?> _enableReplaceCRD = new __Value<bool?>(() => __config.GetBoolean("enableReplaceCRD"));
/// <summary>
/// BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.
/// This feature is in developer preview, and is disabled by default.
///
/// This config can be specified in the following ways, using this precedence:
/// 1. This `enableReplaceCRD` parameter.
/// 2. The `PULUMI_K8S_ENABLE_REPLACE_CRD` environment variable.
/// Obsolete. This option has no effect.
/// </summary>
public static bool? EnableReplaceCRD
{
Expand Down
3 changes: 1 addition & 2 deletions sdk/dotnet/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public sealed class ProviderArgs : Pulumi.ResourceArgs
public Input<bool>? EnableDryRun { get; set; }

/// <summary>
/// BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.
/// This feature is in developer preview, and is disabled by default.
/// Obsolete. This option has no effect.
/// </summary>
[Input("enableReplaceCRD", json: true)]
public Input<bool>? EnableReplaceCRD { get; set; }
Expand Down
7 changes: 2 additions & 5 deletions sdk/go/kubernetes/config/config.go

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

10 changes: 6 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.

5 changes: 3 additions & 2 deletions sdk/nodejs/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ export interface ProviderArgs {
*/
enableDryRun?: pulumi.Input<boolean>;
/**
* BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.
* This feature is in developer preview, and is disabled by default.
* Obsolete. This option has no effect.
*
* @deprecated This option is deprecated, and will be removed in a future release.
*/
enableReplaceCRD?: pulumi.Input<boolean>;
/**
Expand Down
15 changes: 9 additions & 6 deletions sdk/python/pulumi_kubernetes/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def __init__(__self__, *,
2. The `PULUMI_K8S_ENABLE_CONFIGMAP_MUTABLE` environment variable.
:param pulumi.Input[bool] enable_dry_run: BETA FEATURE - If present and set to true, enable server-side diff calculations.
This feature is in developer preview, and is disabled by default.
:param pulumi.Input[bool] enable_replace_crd: BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.
This feature is in developer preview, and is disabled by default.
:param pulumi.Input[bool] enable_replace_crd: Obsolete. This option has no effect.
: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 @@ -74,6 +73,9 @@ def __init__(__self__, *,
pulumi.set(__self__, "enable_dry_run", enable_dry_run)
if enable_replace_crd is None:
enable_replace_crd = _utilities.get_env_bool('PULUMI_K8S_ENABLE_REPLACE_CRD')
if enable_replace_crd is not None:
warnings.warn("""This option is deprecated, and will be removed in a future release.""", DeprecationWarning)
pulumi.log.warn("""enable_replace_crd is deprecated: This option is deprecated, and will be removed in a future release.""")
if enable_replace_crd is not None:
pulumi.set(__self__, "enable_replace_crd", enable_replace_crd)
if helm_release_settings is not None:
Expand Down Expand Up @@ -155,8 +157,7 @@ def enable_dry_run(self, value: Optional[pulumi.Input[bool]]):
@pulumi.getter(name="enableReplaceCRD")
def enable_replace_crd(self) -> Optional[pulumi.Input[bool]]:
"""
BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.
This feature is in developer preview, and is disabled by default.
Obsolete. This option has no effect.
"""
return pulumi.get(self, "enable_replace_crd")

Expand Down Expand Up @@ -294,8 +295,7 @@ def __init__(__self__,
2. The `PULUMI_K8S_ENABLE_CONFIGMAP_MUTABLE` environment variable.
:param pulumi.Input[bool] enable_dry_run: BETA FEATURE - If present and set to true, enable server-side diff calculations.
This feature is in developer preview, and is disabled by default.
:param pulumi.Input[bool] enable_replace_crd: BETA FEATURE - If present and set to true, replace CRDs on update rather than patching.
This feature is in developer preview, and is disabled by default.
:param pulumi.Input[bool] enable_replace_crd: Obsolete. This option has no effect.
: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 Expand Up @@ -374,6 +374,9 @@ def _internal_init(__self__,
__props__.__dict__["enable_dry_run"] = pulumi.Output.from_input(enable_dry_run).apply(pulumi.runtime.to_json) if enable_dry_run is not None else None
if enable_replace_crd is None:
enable_replace_crd = _utilities.get_env_bool('PULUMI_K8S_ENABLE_REPLACE_CRD')
if enable_replace_crd is not None and not opts.urn:
warnings.warn("""This option is deprecated, and will be removed in a future release.""", DeprecationWarning)
pulumi.log.warn("""enable_replace_crd is deprecated: This option is deprecated, and will be removed in a future release.""")
__props__.__dict__["enable_replace_crd"] = pulumi.Output.from_input(enable_replace_crd).apply(pulumi.runtime.to_json) if enable_replace_crd is not None else None
__props__.__dict__["helm_release_settings"] = pulumi.Output.from_input(helm_release_settings).apply(pulumi.runtime.to_json) if helm_release_settings is not None else None
__props__.__dict__["kube_client_settings"] = pulumi.Output.from_input(kube_client_settings).apply(pulumi.runtime.to_json) if kube_client_settings is not None else None
Expand Down

0 comments on commit 308be3d

Please sign in to comment.