-
Notifications
You must be signed in to change notification settings - Fork 117
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
Named resources get deleted from cluster after pulumi resource name change, even though indicated otherwise by pulumi #2948
Comments
Also able to replicate the issue based on the repro steps. It appears to be planning/adding based on the id, but then deleting based on Spec.Metadata.Name, causing and add / delete instead of a replace. The add upserts, giving the deployment a new Id, same name, and the delete then removes the freshly upserted deployment. |
I also note, if I create two deployments with the same Metadata.Name, but different ID, Pulumi will register that it has created 2 deployment resources, but only 1 deployment exists in the cluster. It will create 1 and then immediately upsert on it (replacing the first ID), while tracking 2 in state. |
Thank you for bringing this issue to our attention, @sfc-gh-jlangefeld. Currently, the behavior you're experiencing is a deliberate aspect of how server-side-apply functions within the Pulumi Kubernetes provider which unfortunately results in this scenario. When utilizing server-side-apply (SSA) and creating a new Pulumi resource, the provider performs an upsert operation on the corresponding Kubernetes object. Consequently, during a We're actively tracking this behavior in another open issue (#2926), which addresses the desire to alter this upsert behavior to have the provider consistently fail during creation if the object already exists in the cluster. It's worth noting that even if this behavior is modified for SSA, renaming Pulumi resources could still present challenges. In such cases, rather than the object being lost in the cluster, an error would be triggered indicating that the object already exists. For renaming Pulumi resources, we recommend utilizing a resource alias. Further guidance on this can be found in our documentation: Link to Documentation I will be closing this issue in favor of #2926 which tracks the same underlying behaviour with SSA. |
Hi @rquitales unfortunately #2926 doesn't present a solution for this issue. We actually specifically rely on the SSA upsert behavior by setting Given that we specifically rely on the SSA upsert behavior I think we should re-open this issue. Acceptable solutions could include the following:
I think the main issue right now is that both, Do you think that's possible? |
@sfc-gh-jlangefeld I agree with your statement that the current different results of
This is a change that would need to be done in the Pulumi engine and I'm not sure if it's technically possible since the engine would see a create event and a delete event. I don't think it's capable of knowing that these two events are due to a renaming event.
There is ongoing discussions about delete before create in upstream pulumi/pulumi about this, ref: pulumi/pulumi#2877
This should occur once we land #2926, as renaming the pulumi resource itself will result in a
To address your concerns about this, we're investigating also allowing the current upsert behaviour once #2926 is landed via an opt-in resource option. This would allow users who are currently relying on this behaviour to adopt resources to not be blocked. |
I think in your case @sfc-gh-jlangefeld you would want three things:
The most important part of this is (2). This looks like: }, pulumi.Aliases([]pulumi.Alias{{Name: pulumi.String("app-dep")}})) This ensures that Pulumi knows that Then these are a create and delete of unrelated resources, Pulumi will do the create operation first, and the delete at the end of the update during it's cleanup phase. That means that the "new" resources will be created first, but there is no new resource because it is upserted, so both the new and old logical Pulumi resources are actually referring to the same physical resources. When Pulumi then deletes the "old" logical resource, it deletes the one and only physical resource. The way to avoid this ever happening - while still supporting upsert - is to do (2) and (3) above. I believe with those applied, you should get all of the expected results here - while still being able to get upsert behaviour on your resources. |
Thank you for your replies and thoughts here! We would like to either prevent this in code, or visualize it via the preview output, that after the run the resource is actually deleted. @rquitales summarized it nicely with this:
Regarding the 'failure on upsert' as described in #2926, that would actually be undesired behavior for us and we would be a candidate for the opt-in to still allow upserts. All we care about is that the state of the real world is as it should be. If that means that a resource already exists we don't want to fail, but we want to accept it as the new truth and the program should be a success because the desired state matched the real world state. This is also our reason for why we'd like to allow the upsert behavior beyond the initial migration and adoption of existing resources. Given all this, here's a whole new solution approach I was thinking about: |
What happened?
When changing the pulumi resource name of a kubernetes resource that was named via
and then running
pulumi up
, pulumi indicates that the resource gets deleted and created (as expected), but in reality the resource only gets deleted.This is a risk for us in the case of resource name changes. Especially that the preview and up indicate that the resource should be created again, but it never was in reality.
We rely on resource naming via
metadata.name
because that's the only way to adopt existing resource, a common use case for us.Example
Here are some good steps to reproduce and to exemplify the behavior:
kind create cluster
metadata.name
in theappsv1.DeploymentArgs
struct via:pulumi up
and make sure the deployment was created:pulumi preview
and it shows correctly that it wants to deletetest
and createtest1
:pulumi up
and it will show you that it actually deletedtest
and createdtest1
:test
because that wasn't changed):Output of
pulumi about
Contributing
Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
The text was updated successfully, but these errors were encountered: