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

new annotation: deletionPropagationPolicy #3011

Merged
merged 4 commits into from
May 17, 2024
Merged

new annotation: deletionPropagationPolicy #3011

merged 4 commits into from
May 17, 2024

Conversation

EronWright
Copy link
Contributor

@EronWright EronWright commented May 16, 2024

Proposed changes

Introduces a new Pulumi annotation to set the deletion propagation policy, e.g. to support non-cascading delete on StatefulSet to preserve pods during replacement (see walkthrough).

Note that the policy annotation must be set on the old resource before deleting or replacing it; setting it on the replacement or on the live object is ineffective.

Related issues (optional)

Closes #1831

Example

This example serves to show how the 'orphan' propagation policy allows for non-disruptive replacement of
a StatefulSet, e.g. by touching the volumeClaimTemplates.

name: issue-1831
runtime: yaml
description: A StatefulSet to demonstrate the `pulumi.com/deletionPropagationPolicy` annotation.
config:
  # disable SSA for this demonstration
  kubernetes:enableServerSideApply: false
resources:
  nginx:
    type: kubernetes:apps/v1:StatefulSet
    properties:
      metadata:
        name: nginx
        annotations:
          pulumi.com/deletionPropagationPolicy: "orphan"
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: nginx
        serviceName: nginx
        template:
          metadata:
            labels:
              app: nginx
          spec:
            containers:
            - image: nginx:1.19.9
              name: nginx
              ports:
              - containerPort: 80
                name: web
        volumeClaimTemplates:
        - metadata:
            name: nginx
          spec:
            accessModes:
            - ReadWriteOnce
            resources:
              requests:
                storage: 1Gi

Following the initial deployment, we have these objects:

❯ kubectl get statefulset,pod,pvc -ocustom-columns='KIND:.kind,NAME:.metadata.name,UID:.metadata.uid'
KIND                    NAME            UID
StatefulSet             nginx           b1aa144d-3f16-448e-8e15-02d2c2d4b61a
Pod                     nginx-0         c00d97cc-39d7-4a95-b839-0910f911dbca
PersistentVolumeClaim   nginx-nginx-0   2c624ff9-e856-4d2d-bfaf-527c6b770bc7

To provoke a replacement, we change the PVC template:

              requests:
-                storage: 1Gi
+                storage: 2Gi

Let's also increase the replicas:

      spec:
-        replicas: 1
+        replicas: 2

And deploy:

❯ pulumi up -f
Updating (dev)

     Type                               Name            Status            Info
     pulumi:pulumi:Stack                issue-1831-dev                    4 warnings; 2 messages
 +-  └─ kubernetes:apps/v1:StatefulSet  nginx           replaced (2s)     [diff: ~spec]

Resources:
    +-1 replaced
    1 unchanged

Looking again at the objects:

❯ kubectl get statefulset,pod,pvc -ocustom-columns='KIND:.kind,NAME:.metadata.name,UID:.metadata.uid'
KIND                    NAME            UID
StatefulSet             nginx           135d9142-460c-4f64-82a6-8ce23427f52b
Pod                     nginx-0         c00d97cc-39d7-4a95-b839-0910f911dbca
Pod                     nginx-1         8c80932f-7051-4fc7-baeb-00dae4b07b64
PersistentVolumeClaim   nginx-nginx-0   2c624ff9-e856-4d2d-bfaf-527c6b770bc7
PersistentVolumeClaim   nginx-nginx-1   e4b4fd18-28b2-454b-8c6b-9fa06435d3d6

We see the expected result: the StatefulSet was replaced, the existing pod was adopted, and a new pod was added w/ a PVC.

In more detail, the StatefulSet controller uses the selector to identify existing pods, then chooses to delete or adopt based on suitability. Note the updated owner reference on nginx-0:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-0
  uid: c00d97cc-39d7-4a95-b839-0910f911dbca
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: StatefulSet
    name: nginx
    uid: 135d9142-460c-4f64-82a6-8ce23427f52b

To demonstrate how the StatefulSet controller might choose to delete the existing pod rather than adopting it, let's change the image rather than the replicas:

            containers:
-            - image: nginx:1.19.9
+            - image: nginx:1.19.10
 
              requests:
-                storage: 2Gi
+                storage: 3Gi

We deploy again and see that all pods were replaced.

KIND                    NAME            UID
StatefulSet             nginx           ead53943-abc9-47c8-9393-326f845c7f42
Pod                     nginx-0         74752b8c-3979-478b-9be4-ff3ca1b0aa6f
Pod                     nginx-1         b6c2f0f6-f5ff-4e04-a1da-66966b8d697c
PersistentVolumeClaim   nginx-nginx-0   2c624ff9-e856-4d2d-bfaf-527c6b770bc7
PersistentVolumeClaim   nginx-nginx-1   e4b4fd18-28b2-454b-8c6b-9fa06435d3d6

Note that PVC nginx-nginx-0 was not replaced and still has storage: 1Gi.

Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

Copy link

codecov bot commented May 16, 2024

Codecov Report

Attention: Patch coverage is 53.84615% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 32.34%. Comparing base (098bd43) to head (4138b4d).

Files Patch % Lines
provider/pkg/await/await.go 0.00% 4 Missing ⚠️
provider/pkg/metadata/overrides.go 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3011      +/-   ##
==========================================
+ Coverage   32.29%   32.34%   +0.05%     
==========================================
  Files          69       69              
  Lines        8947     8954       +7     
==========================================
+ Hits         2889     2896       +7     
  Misses       5791     5791              
  Partials      267      267              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EronWright EronWright requested a review from a team May 16, 2024 20:21
@EronWright EronWright marked this pull request as draft May 17, 2024 15:16
@EronWright EronWright changed the title new annotation: deletionPropagation new annotation: pulumi.com/deletionPropagationPolicy May 17, 2024
@EronWright EronWright changed the title new annotation: pulumi.com/deletionPropagationPolicy new annotation: deletionPropagationPolicy May 17, 2024
@EronWright EronWright marked this pull request as ready for review May 17, 2024 15:42
@EronWright EronWright enabled auto-merge (squash) May 17, 2024 15:52
Copy link
Contributor

@blampe blampe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

@EronWright EronWright merged commit 9d759ca into master May 17, 2024
18 checks passed
@EronWright EronWright deleted the issue-1831 branch May 17, 2024 17:19
lumiere-bot bot referenced this pull request in coolguy1771/home-ops May 24, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@pulumi/kubernetes](https://pulumi.com)
([source](https://togithub.com/pulumi/pulumi-kubernetes)) | dependencies
| minor | [`4.11.0` ->
`4.12.0`](https://renovatebot.com/diffs/npm/@pulumi%2fkubernetes/4.11.0/4.12.0)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>pulumi/pulumi-kubernetes (@&#8203;pulumi/kubernetes)</summary>

###
[`v4.12.0`](https://togithub.com/pulumi/pulumi-kubernetes/blob/HEAD/CHANGELOG.md#4120-May-21-2024)

[Compare
Source](https://togithub.com/pulumi/pulumi-kubernetes/compare/v4.11.0...v4.12.0)

##### Added

- Added a new Helm Chart v4 resource.
([https://github.com/pulumi/pulumi-kubernetes/pull/2947](https://togithub.com/pulumi/pulumi-kubernetes/pull/2947))
- Added support for deletion propagation policies (e.g. Orphan).
([https://github.com/pulumi/pulumi-kubernetes/pull/3011](https://togithub.com/pulumi/pulumi-kubernetes/pull/3011))
- Server-side apply conflict errors now include the original field
manager's name.
([https://github.com/pulumi/pulumi-kubernetes/pull/2983](https://togithub.com/pulumi/pulumi-kubernetes/pull/2983))

##### Changed

- Pulumi will now wait for DaemonSets to become ready.
([https://github.com/pulumi/pulumi-kubernetes/pull/2953](https://togithub.com/pulumi/pulumi-kubernetes/pull/2953))
- The Release resource's merge behavior for `valueYamlFiles` now more
closely matches Helm's behavior.
([https://github.com/pulumi/pulumi-kubernetes/pull/2963](https://togithub.com/pulumi/pulumi-kubernetes/pull/2963))

##### Fixed

- Helm Chart V3 previews no longer fail when the cluster is unreachable.
([https://github.com/pulumi/pulumi-kubernetes/pull/2992](https://togithub.com/pulumi/pulumi-kubernetes/pull/2992))
- Fixed a panic that could occur when a missing field became `null`.
([https://github.com/pulumi/pulumi-kubernetes/issues/1970](https://togithub.com/pulumi/pulumi-kubernetes/issues/1970))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNzEuMSIsInVwZGF0ZWRJblZlciI6IjM3LjM3MS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL21pbm9yIl19-->

Co-authored-by: lumiere-bot[bot] <98047013+lumiere-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to delete a statefulset with the cascade orphan option
3 participants