Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another fix for managed-by label in SSA mode. #2140

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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