From 4aed22533a060b880c6aabf57f5302b4f17be5d0 Mon Sep 17 00:00:00 2001 From: Levi Blackstone Date: Tue, 6 Jun 2023 14:15:36 -0600 Subject: [PATCH] Drop support for legacy pulumi.com/initialApiVersion annotation (#2443) The pulumi.com/initialApiVersion annotation was briefly used to store information about the apiVersion used to create each resource in early versions of the provider (v1.x). The logic was updated to store this information in the Pulumi state rather than directly on the resource. Subsequent versions of the provider continued to support this annotation as a fallback option in case the state did not contain this information. Drop support for the annotation to simplify the provider logic. --- CHANGELOG.md | 1 + provider/pkg/metadata/annotations.go | 9 ++--- provider/pkg/provider/provider.go | 59 ++++------------------------ 3 files changed, 12 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15dd611dca..a71da9ed6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Breaking changes: - Remove deprecated enableReplaceCRD provider flag (https://github.com/pulumi/pulumi-kubernetes/pull/2402) - Drop support for Kubernetes clusters older than v1.13 (https://github.com/pulumi/pulumi-kubernetes/pull/2414) - Make all resource output properties required (https://github.com/pulumi/pulumi-kubernetes/pull/2422) +- Drop support for legacy pulumi.com/initialApiVersion annotation (https://github.com/pulumi/pulumi-kubernetes/pull/2443) Other changes: diff --git a/provider/pkg/metadata/annotations.go b/provider/pkg/metadata/annotations.go index ef042d54e0..a735316451 100644 --- a/provider/pkg/metadata/annotations.go +++ b/provider/pkg/metadata/annotations.go @@ -27,11 +27,10 @@ const ( AnnotationPrefix = "pulumi.com/" - AnnotationAutonamed = AnnotationPrefix + "autonamed" - AnnotationSkipAwait = AnnotationPrefix + "skipAwait" - AnnotationTimeoutSeconds = AnnotationPrefix + "timeoutSeconds" - AnnotationInitialAPIVersion = AnnotationPrefix + "initialApiVersion" - AnnotationReplaceUnready = AnnotationPrefix + "replaceUnready" + AnnotationAutonamed = AnnotationPrefix + "autonamed" + AnnotationSkipAwait = AnnotationPrefix + "skipAwait" + AnnotationTimeoutSeconds = AnnotationPrefix + "timeoutSeconds" + AnnotationReplaceUnready = AnnotationPrefix + "replaceUnready" AnnotationPatchForce = AnnotationPrefix + "patchForce" AnnotationPatchFieldManager = AnnotationPrefix + "patchFieldManager" diff --git a/provider/pkg/provider/provider.go b/provider/pkg/provider/provider.go index 92a3bc2025..87010d8767 100644 --- a/provider/pkg/provider/provider.go +++ b/provider/pkg/provider/provider.go @@ -1301,15 +1301,6 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) ( k.helmHookWarning(ctx, newInputs, urn) - annotatedInputs, err := legacyInitialAPIVersion(oldInputs, newInputs) - if err != nil { - return nil, pkgerrors.Wrapf( - err, "Failed to create resource %s/%s because of an error generating the %s value in "+ - "`.metadata.annotations`", - newInputs.GetNamespace(), newInputs.GetName(), metadata.AnnotationInitialAPIVersion) - } - newInputs = annotatedInputs - // Adopt name from old object if appropriate. // // If the user HAS NOT assigned a name in the new inputs, we autoname it and mark the object as @@ -1997,10 +1988,7 @@ func (k *kubeProvider) Read(ctx context.Context, req *pulumirpc.ReadRequest) (*p } } - initialAPIVersion, err := initialAPIVersion(oldState, oldInputs) - if err != nil { - return nil, err - } + initialAPIVersion := initialAPIVersion(oldState, oldInputs) fieldManager := k.fieldManagerName(nil, oldState, oldInputs) if k.yamlRenderMode { @@ -2262,11 +2250,7 @@ func (k *kubeProvider) Update( newInputs.GetNamespace(), newInputs.GetName(), lastAppliedConfigKey) } - initialAPIVersion, err := initialAPIVersion(oldState, oldInputs) - if err != nil { - return nil, err - } - + initialAPIVersion := initialAPIVersion(oldState, oldInputs) fieldManagerOld := k.fieldManagerName(nil, oldState, oldInputs) fieldManager := k.fieldManagerName(nil, oldState, newInputs) @@ -2441,10 +2425,7 @@ func (k *kubeProvider) Delete(ctx context.Context, req *pulumirpc.DeleteRequest) k.clusterUnreachableReason) } - initialAPIVersion, err := initialAPIVersion(oldState, &unstructured.Unstructured{}) - if err != nil { - return nil, err - } + initialAPIVersion := initialAPIVersion(oldState, &unstructured.Unstructured{}) fieldManager := k.fieldManagerName(nil, oldState, oldInputs) resources, err := k.getResources() if err != nil { @@ -2953,40 +2934,14 @@ func getAnnotations(config *unstructured.Unstructured) map[string]string { return annotations } -// legacyInitialAPIVersion maintains backward compatibility with behavior introduced in the 1.2.0 release. This -// information is now stored in the checkpoint file and the annotation is no longer used by the provider. -func legacyInitialAPIVersion(oldConfig, newConfig *unstructured.Unstructured) (*unstructured.Unstructured, error) { - oldAnnotations := getAnnotations(oldConfig) - newAnnotations := getAnnotations(newConfig) - - apiVersion, exists := oldAnnotations[metadata.AnnotationInitialAPIVersion] - if exists { - // Keep the annotation if it was already created previously to minimize further disruption - // to existing resources. - newAnnotations[metadata.AnnotationInitialAPIVersion] = apiVersion - } - - if len(newConfig.GetAnnotations()) > 0 { - newConfig.SetAnnotations(newAnnotations) - } - - return newConfig, nil -} - // initialAPIVersion retrieves the initialAPIVersion property from the checkpoint file and falls back to using -// the `pulumi.com/initialAPIVersion` annotation if that property is not present. -func initialAPIVersion(state resource.PropertyMap, oldConfig *unstructured.Unstructured) (string, error) { +// the version from the resource metadata if that property is not present. +func initialAPIVersion(state resource.PropertyMap, oldInputs *unstructured.Unstructured) string { if v, ok := state[initialAPIVersionKey]; ok { - return v.StringValue(), nil - } - - oldAnnotations := getAnnotations(oldConfig) - apiVersion, exists := oldAnnotations[metadata.AnnotationInitialAPIVersion] - if exists { - return apiVersion, nil + return v.StringValue() } - return oldConfig.GetAPIVersion(), nil + return oldInputs.GetAPIVersion() } func checkpointObject(inputs, live *unstructured.Unstructured, fromInputs resource.PropertyMap,