pulumi: delete-before-replace triggers delete-before-replace in all dependencies

Following up from this community Slack thread, there is a bug where:

  • The user changes data in a manually-named Kubernetes ConfigMap, which triggers a delete-before-replace.
  • The user references that ConfigMap in a Deployment.
  • Because step generator believes that any resource that is marked delete-before-replace must also have all its dependencies transitively marked delete-before-replace (specifically this line), we delete the entire Deployment.

This is very bad for Kubernetes. It means that changing data in a ConfigMap can trigger a complete delete-first tear-down and rebuild of your application, including a stateful application.

The comment explaining this asserts that this is true, but I’m not really sure why it would be – why, in particular, would we need to mark resources that actually don’t need to be deleted at all, as delete-before-create?

cc @pgavlin @swgillespie @lukehoban

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 37 (33 by maintainers)

Most upvoted comments

@naveensrinivasan We apologize for the delay here. This is a subtle and tricky issue, so it’s taken a bit of time to discuss and design. That said, it’s in our current sprint, and we will be acting on this soon. Expect a more detailed update tomorrow on the plans and timeframe on a fix.

The PR for this is in progress at https://github.com/pulumi/pulumi/pull/2369. Currently expecting this to be available next week (hopefully early next week).

Great! We are being blocked by the EKS issue referred here.

Moreover, CloudFormation, Terraform, and all other such infrastructure as code solutions seem to have chosen our current behavior, as far as I know. I also prefer that we learn from others rather than invent. In fact, isn’t this Terraform’s precisely behavior for all resource replacements by default?

This may not in fact be TF’s behavior. Consider the following config:

resource "aws_s3_bucket" "b" {
  bucket = "my-tf-test-bucket-abcde"
  acl    = "private"

  tags {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

resource "aws_s3_bucket" "c" {
  bucket = "my-tf-test-bucket-efghi"
  acl    = "private"

  tags {
    Name        = "My bucket"
    Environment = "${aws_s3_bucket.b.id}"
  }
}

If I deploy this, then change the name of the first bucket, then run an apply, the second bucket is not replaced:

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place
-/+ destroy and then create replacement

Terraform will perform the following actions:

-/+ aws_s3_bucket.b (new resource required)
      id:                          "my-tf-test-bucket-abcde" => <computed> (forces new resource)
      acceleration_status:         "" => <computed>
      acl:                         "private" => "private"
      arn:                         "arn:aws:s3:::my-tf-test-bucket-abcde" => <computed>
      bucket:                      "my-tf-test-bucket-abcde" => "my-tf-test-bucket-abcdef" (forces new resource)
      bucket_domain_name:          "my-tf-test-bucket-abcde.s3.amazonaws.com" => <computed>
      bucket_regional_domain_name: "my-tf-test-bucket-abcde.s3.amazonaws.com" => <computed>
      force_destroy:               "false" => "false"
      hosted_zone_id:              "Z3AQBSTGFYJSTF" => <computed>
      region:                      "us-east-1" => <computed>
      request_payer:               "BucketOwner" => <computed>
      tags.%:                      "2" => "2"
      tags.Environment:            "Dev" => "Dev"
      tags.Name:                   "My bucket" => "My bucket"
      versioning.#:                "1" => <computed>
      website_domain:              "" => <computed>
      website_endpoint:            "" => <computed>

  ~ aws_s3_bucket.c
      tags.%:                      "" => <computed>
      tags.Environment:            "my-tf-test-bucket-abcde" => ""
      tags.Name:                   "My bucket" => ""


Plan: 1 to add, 1 to change, 1 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_s3_bucket.b: Destroying... (ID: my-tf-test-bucket-abcde)
aws_s3_bucket.b: Destruction complete after 1s
aws_s3_bucket.b: Creating...
  acceleration_status:         "" => "<computed>"
  acl:                         "" => "private"
  arn:                         "" => "<computed>"
  bucket:                      "" => "my-tf-test-bucket-abcdef"
  bucket_domain_name:          "" => "<computed>"
  bucket_regional_domain_name: "" => "<computed>"
  force_destroy:               "" => "false"
  hosted_zone_id:              "" => "<computed>"
  region:                      "" => "<computed>"
  request_payer:               "" => "<computed>"
  tags.%:                      "" => "2"
  tags.Environment:            "" => "Dev"
  tags.Name:                   "" => "My bucket"
  versioning.#:                "" => "<computed>"
  website_domain:              "" => "<computed>"
  website_endpoint:            "" => "<computed>"
aws_s3_bucket.b: Creation complete after 7s (ID: my-tf-test-bucket-abcdef)
aws_s3_bucket.c: Modifying... (ID: my-tf-test-bucket-efghi)
  tags.Environment: "my-tf-test-bucket-abcde" => "my-tf-test-bucket-abcdef"
aws_s3_bucket.c: Modifications complete after 6s (ID: my-tf-test-bucket-efghi)

Apply complete! Resources: 1 added, 1 changed, 1 destroyed.

I also don’t know whether you’d want to let a resource make a decision about its dependents. In general, this would seem to be something that only those dependents would be qualified to decide.

I am open to re-considering, but I am pretty confident that this a better for nearly all real-world applications:

  • It’s one of the most requested features of Kubernetes. See this issue.
  • It allows users to take advantage of the built-in lifecycle semantics of Pod. Triggering a rollout ties the changes in ConfigMap (which usually configures, e.g., nginx) to the well-understood liveness and readniness semantics of the Pod. Using the live-update feature means Pods will simply update whenever the kubelet syncs, and you may never be alerted that something went wrong.
  • It’s safer when you decide you need to roll back. There are no roll-back semantics with the live-update feature, so if you change something, and if you notice something is going wrong, and you have no way to keep directing traffic to old instances, or to go “backwards” without rolling out again – and that will take even more time, because you have to wait for the kubelet to sync.
  • It’s safer when the roll-forward fails, and you want to re-direct traffic back to the still-alive replicas from the previous version. We keep the old ConfigMap around, so if roll-forward fails, you not only have access to the old version of the application, but that old version doesn’t accidentally get live-updated, because it still references the old ConfigMap.
  • It’s provides fine-grained controls over how changes roll-out. Users have access to all the knobs on Deployment, or they can roll their own fairly easily with naked ReplicaSets. In contrast, the live-update feature will simply update any Pod whenever TTL cache expires and the kubelet syncs.
  • IME it is what the vast majority of users expect. I have never met someone who encountered this and was not surprised. See also the hundreds of responses in the issue above.
  • IME people use the live-update feature because it’s easier, rather than because it’s right. people using live-update are doing it because it’s simply easier than the alternative, which is to hand-roll a pipeline for triggering rollouts from ConfigMap changes. In all of the cases I have seen, except one, I believe the “correct” way is to go route Pulumi goes instead.
  • The times when you do want to use live-update are almost always better-suited to different technology. For example, if you want Envoy to update continuously, it’s probably better (more scalable, more operationally predictable, safer) for it to continuously watch a config service rather than have the kubelet use a ConfigMap.

As I said, I’m always super open to cases where I’ve missed something, but as it stands now, these to me are very compelling reasons to keep things as they are.

The behavior that this issue describes is due to three intersecting features:

  1. Pulumi’s delete semantics
  2. The Kubernetes provider’s delete-before-replace semantics for resources with fixed names
  3. The Kubernetes provider’s replacement semantics for ConfigMaps

In reverse order:

  • The Kubernetes provider treats ConfigMaps as immutable in order to trigger rollouts when they are updated. We believe that this is consistent with the general expectation around ConfigMaps. As such, any change to a ConfigMap causes it to be replaced (i.e. the current ConfigMap is deleted and a new one created).
  • The Kubernetes provider requires that any resources that have a user-specified name be deleted before their replacement is created. Normally, Pulumi would schedule the creation of the new resource before the deletion of the original resource in order to avoid downtime. That is not possible for resources with user-specified names, as the new resource would conflict with the original resource.
  • The Pulumi engine’s delete semantics require that all resources that transitively depend on a resource A are deleted before resource A is deleted. This behavior is required in order to accommodate resources that cannot be deleted until their dependent resources are deleted (there are a number of such resources in AWS), and because the engine does not have granular knowledge about which specific resources might fail in such a fashion. Normally this not an issue: the vast majority of resource deletions do not need to be scheduled promptly, and can be handled at the end of a pulumi update. If, however a resource A is being deleted as part of a delete-before-replace, the deletions of A’s transitive dependents are scheduled at the same time as the deletion of A. This causes downtime and deletions that a user is unlikely to expect.

We believe that it may be reasonable to avoid the cascading delete by default and instead allow resources to opt in to cascading deletes if necessary, and are investigating whether or not we can make this change without negatively affecting existing scenarios.