Skip to content

Commit

Permalink
Another fix for managed-by label in SSA mode. (#2140)
Browse files Browse the repository at this point in the history
#2138 attempted to fix the case where a resource was created using CSA, and then updated to use SSA. For this case, the resource should retain the "managed-by" label. However, there was a bug in the conditional logic, so that fix was not effective. This change fixes this logic so that the label is only created for CSA resources, but is retained once present on a resource in both cases.
  • Loading branch information
lblackstone authored Aug 16, 2022
1 parent 3c0d2cd commit 3838794
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

- Update autonaming to use NewUniqueName for deterministic update plans. (https://github.com/pulumi/pulumi-kubernetes/pull/2137)
- Another fix for managed-by label in SSA mode. (https://github.com/pulumi/pulumi-kubernetes/pull/2140)

## 3.20.4 (August 15, 2022)

Expand Down
22 changes: 10 additions & 12 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,24 +1293,22 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (
contract.Assert(oldInputs.GetName() != "")
metadata.AdoptOldAutonameIfUnnamed(newInputs, oldInputs)

// If this resource does not have a "managed-by: pulumi" label in its inputs, it is likely we are importing
// a resource that was created out-of-band. In this case, we do not add the `managed-by` label here, as doing
// so would result in a persistent failure to import due to a diff that the user cannot correct.
// If the resource has existing state, we only set the "managed-by: pulumi" label if it is already present. This
// avoids causing diffs for cases where the resource is being imported, or was created using SSA. The goal in
// both cases is to leave the resource unchanged. The label is added if already present, or omitted if not.
if metadata.HasManagedByLabel(oldInputs) {
if !k.serverSideApplyMode {
_, err = metadata.TrySetManagedByLabel(newInputs)
if err != nil {
return nil, pkgerrors.Wrapf(err,
"Failed to create object because of a problem setting managed-by labels")
}
_, err = metadata.TrySetManagedByLabel(newInputs)
if err != nil {
return nil, pkgerrors.Wrapf(err,
"Failed to create object because of a problem setting managed-by labels")
}
}
} else {
metadata.AssignNameIfAutonamable(req.RandomSeed, newInputs, news, urn)

// Set a "managed-by: pulumi" label on resources created with Client-Side Apply. To avoid churn on previously
// created resources, keep the label in SSA mode if it's already present on the resource.
if !k.serverSideApplyMode || metadata.HasManagedByLabel(oldInputs) {
// Set a "managed-by: pulumi" label on resources created with Client-Side Apply. Do not set this label for SSA
// resources since the fieldManagers field contains granular information about the managers.
if !k.serverSideApplyMode {
_, err = metadata.TrySetManagedByLabel(newInputs)
if err != nil {
return nil, pkgerrors.Wrapf(err,
Expand Down

0 comments on commit 3838794

Please sign in to comment.