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

Avoid treating PVC managed by VolumeClaimTemplate as dependencies #5568

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

jklaw90
Copy link
Contributor

@jklaw90 jklaw90 commented Sep 18, 2024

What type of PR is this?
/kind bug

What this PR does / why we need it:
It was incorrectly handling PVCs when it belongs to the StatefulSet VolumeClaimTemplates.
If you set the claim name in the to match the StatefulSet VolumeClaimTemplate the StatefulSet controller would replace it for the pod, so the name isn't a backed by a real pvc.

create the following statefulset, and note the pod created has a claim with name www-web-0

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx # has to match .spec.template.metadata.labels
  serviceName: "nginx"
  replicas: 3 # by default is 1
  minReadySeconds: 10 # by default is 0
  template:
    metadata:
      labels:
        app: nginx # has to match .spec.selector.matchLabels
    spec:
      volumes:
      - name: www
        persistentVolumeClaim:
          claimName: www
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: registry.k8s.io/nginx-slim:0.24
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "my-storage-class"
      resources:
        requests:
          storage: 1Gi

Which issue(s) this PR fixes:
Fixes # n/a

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

`karmada-controller-manager`: Ignored StatefulSet Dependencies with PVCs created via the VolumeClaimTemplates.

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 18, 2024
@jklaw90 jklaw90 changed the title fix sts pvc logic fix: sts pvc logic Sep 18, 2024
@karmada-bot
Copy link
Collaborator

Welcome @jklaw90! It looks like this is your first PR to karmada-io/karmada 🎉

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 18, 2024
@jklaw90 jklaw90 force-pushed the fix-sts-pvc branch 2 times, most recently from 46eccf1 to 106eb02 Compare September 18, 2024 23:49
@codecov-commenter
Copy link

codecov-commenter commented Sep 19, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 82.35294% with 3 lines in your changes missing coverage. Please review.

Project coverage is 35.21%. Comparing base (8cc712f) to head (902bb1b).

Files with missing lines Patch % Lines
...resourceinterpreter/default/native/dependencies.go 82.35% 2 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5568      +/-   ##
==========================================
+ Coverage   35.19%   35.21%   +0.02%     
==========================================
  Files         645      645              
  Lines       44869    44885      +16     
==========================================
+ Hits        15791    15808      +17     
  Misses      27846    27846              
+ Partials     1232     1231       -1     
Flag Coverage Δ
unittests 35.21% <82.35%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@RainbowMango
Copy link
Member

cc @XiShanYongYe-Chang for help

@XiShanYongYe-Chang
Copy link
Member

Thanks @jklaw90
/assign

@XiShanYongYe-Chang
Copy link
Member

Hi @jklaw90 Do you know how to get the correct pvc name from podTemplate?

@jklaw90
Copy link
Contributor Author

jklaw90 commented Sep 20, 2024

Hi @jklaw90 Do you know how to get the correct pvc name from podTemplate?

Hi @XiShanYongYe-Chang
I don't think we can derive it from the podTemplate alone, we need the volumeClaimTemplates to determine the real name. The pvc name would be <template-claim-name>-<sts-name>-<index>.
That being said should the StatefulSet have dependencies or the pod in this case?

@XiShanYongYe-Chang
Copy link
Member

You're right, we cannot obtain the PVC name directly from the StatefulSet, as it also needs to be combined with the pod's index. Therefore, the current method of obtaining the dependent PVC name is incorrect.

Provide the Pod's YAML information here:

apiVersion: v1
kind: Pod
metadata:
  generateName: web-
  labels:
    app: nginx
    apps.kubernetes.io/pod-index: "0"
    controller-revision-hash: web-59cfccf6c
    statefulset.kubernetes.io/pod-name: web-0
  name: web-0
  namespace: default
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: StatefulSet
    name: web
    uid: 13e01c3d-4c7e-4d3a-8611-a0b41dd30be9
spec:
  containers:
  - image: registry.k8s.io/nginx-slim:0.24
    imagePullPolicy: IfNotPresent
    name: nginx
    ports:
    - containerPort: 80
      name: web
      protocol: TCP
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /usr/share/nginx/html
      name: www
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  hostname: web-0
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  subdomain: nginx
  terminationGracePeriodSeconds: 10
  volumes:
  - name: www
    persistentVolumeClaim:
      claimName: www-web-0

cc @RainbowMango

@XiShanYongYe-Chang
Copy link
Member

Hi @jklaw90 how are you currently obtaining the dependent PVC, or is it also not being obtained?

@jklaw90
Copy link
Contributor Author

jklaw90 commented Sep 20, 2024

@XiShanYongYe-Chang

It's not being obtained currently. I assumed getPodDependencies would handle this for pods?

@XiShanYongYe-Chang
Copy link
Member

The getPodDependencies function can serve to obtain the pod's dependent resources, but we will not be able to retrieve the associated PVC resources when distributing StatefulSets from the Karmada control plane.

@jklaw90
Copy link
Contributor Author

jklaw90 commented Sep 20, 2024

We could use replicas and StatefulSet name with the claim template to derive pvc names.
But we have the possibility of missing some of the replicas were scaled down at all.

I think we'd have to query all the pvcs in the namespace to know with 100% certainty. (which is how i'm using it, with this function)

@XiShanYongYe-Chang
Copy link
Member

XiShanYongYe-Chang commented Sep 20, 2024

For the sts resource, according to the template provided by you, when it is distributed to the member cluster, the pvc resource is automatically created. Therefore, there is no need to determine the pvc resource that the sts resource follows and distribute it.

Hi @jklaw90, this seems to depend on whether the .spec.volumeClaimTemplates field is defined in the template with sts. If I remove this filed in the sts, the generated pod will looks like this:

image

@jklaw90
Copy link
Contributor Author

jklaw90 commented Sep 20, 2024

if you remove the template then that PVC should be a dependency.
so i think the current pr handles the cases you want.

@XiShanYongYe-Chang
Copy link
Member

Should we execute different logic depending on whether .spec.volumeClaimTemplates exists or not?

@jklaw90
Copy link
Contributor Author

jklaw90 commented Sep 23, 2024

Should we execute different logic depending on whether .spec.volumeClaimTemplates exists or not?

I might not understand the question. but i think the current code handles this, the first and new test should cover both cases.

@XiShanYongYe-Chang
Copy link
Member

Oh @jklaw90 thanks, I get you, you are right.

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Thanks~
/lgtm
/cc @RainbowMango

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 26, 2024
@RainbowMango
Copy link
Member

/retitle Avoid treating PVC managed by VolumeClaimTemplate as dependencies

@karmada-bot karmada-bot changed the title fix: sts pvc logic Avoid treating PVC managed by VolumeClaimTemplate as dependencies Sep 26, 2024
@RainbowMango RainbowMango added this to the v1.12 milestone Sep 26, 2024
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 27, 2024
@RainbowMango
Copy link
Member

@jklaw90 Could you please squash your commits? Then things will be all set.

@jklaw90
Copy link
Contributor Author

jklaw90 commented Sep 30, 2024

@RainbowMango i've been having some issues with chart-lint-test
It's not reporting the status, but i've also had it fail on some of the installation steps. seems unrelated to this pr.

@jklaw90 jklaw90 force-pushed the fix-sts-pvc branch 2 times, most recently from 809874a to b4bfaa3 Compare October 2, 2024 05:45
Co-authored-by: yelshall <[email protected]>
Signed-off-by: Julian Lawrence <[email protected]>
@RainbowMango
Copy link
Member

@RainbowMango i've been having some issues with chart-lint-test It's not reporting the status, but i've also had it fail on some of the installation steps. seems unrelated to this pr.

No worries. The test chart-lint-test will only run when there are changes in the content of the chart directory. See the configuration here.

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 5, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 5, 2024
@karmada-bot karmada-bot merged commit 62ae95e into karmada-io:master Oct 5, 2024
12 checks passed
@XiShanYongYe-Chang
Copy link
Member

Hi @jklaw90 @RainbowMango do you think we need to rebase this commit to the previous branch?

@RainbowMango
Copy link
Member

I guess you mean if we need to backport this PR to release branches. I think we can do it although it's not a critical bug fix, as I don't see any risk with it.

@jklaw90
Copy link
Contributor Author

jklaw90 commented Oct 8, 2024

yeah, next release is fine for us.

karmada-bot added a commit that referenced this pull request Oct 14, 2024
…-upstream-release-1.11

Automated cherry pick of #5568: Avoid treating PVC managed by VolumeClaimTemplate as dependencies
karmada-bot added a commit that referenced this pull request Oct 14, 2024
…-upstream-release-1.10

Automated cherry pick of #5568: Avoid treating PVC managed by VolumeClaimTemplate as dependencies
karmada-bot added a commit that referenced this pull request Oct 14, 2024
…-upstream-release-1.9

Automated cherry pick of #5568: Avoid treating PVC managed by VolumeClaimTemplate as dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants