Skip to content

Commit

Permalink
Drop support for legacy pulumi.com/initialApiVersion annotation (#2443)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lblackstone authored Jun 6, 2023
1 parent 3096efa commit 4aed225
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 57 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
9 changes: 4 additions & 5 deletions provider/pkg/metadata/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
59 changes: 7 additions & 52 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4aed225

Please sign in to comment.