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

add condition and event info for not upgradable pods when update sidecarset (#1272) #1309

Merged
merged 3 commits into from
Jul 10, 2023

Conversation

MarkLux
Copy link
Contributor

@MarkLux MarkLux commented Jun 8, 2023

Ⅰ. Describe what this PR does

Currently the sidecar container in-place upgrade can only support changing of image field, if user changed other fields, the injected pods will not execute sidecar container upgrade.

However, this rule is not explicit for users, they can not get any hint or info in this situation. This PR add an event for pods, when the injected sidecar changed but cannot be upgrade. If user changed SidecarSet but the pods are not upgraded, they can use kubectl describe sidecarset <sidecarset-name> or kubectl describe pod <pod-name> to see the event and figure out the reason.

Ⅱ. Does this pull request fix one issue?

fixes #1272

Ⅲ. Describe how to verify it

  1. create a sidecar set
apiVersion: apps.kruise.io/v1alpha1
kind: SidecarSet
metadata:
  name: demo-sidecarset
spec:
  selector:
    matchLabels:
      app: demo-server
  updateStrategy:
    type: RollingUpdate
  containers:
  - name: sidecar
    image: nginx
  1. create some pods with label (here I using a CloneSet), the pods will be injected with sidecar container immediately
apiVersion: apps.kruise.io/v1alpha1
kind: CloneSet
metadata:
  labels:
    app: demo-server
  name: demo-server
spec:
  updateStrategy:
    type: InPlaceIfPossible
  replicas: 3
  selector:
    matchLabels:
      app: demo-server
  template:
    metadata:
      labels:
        app: demo-server
    spec:
      containers:
      - name: demo-server
        image: tomcat
        ports:
        - containerPort: 8080
  1. update the SidecarSet , change some fields more than image (here I change the image and add a command field)
apiVersion: apps.kruise.io/v1alpha1
kind: SidecarSet
metadata:
  name: demo-sidecarset
spec:
  selector:
    matchLabels:
      app: demo-server
  updateStrategy:
    type: RollingUpdate
  containers:
  - name: sidecar
    image: busybox
    command: [ "/bin/sh", "-c", "touch a.txt && tail -f a.txt"]
  1. apply the changed sidecarset, the pods will not be upgraded, using kubectl get pod , we can see the condition info:
- lastProbeTime: null
    lastTransitionTime: "2023-06-19T05:41:13Z"
    message: Pod's sidecar set is not upgradable due to changes out of image field
    reason: UpdateImmutableField
    status: "False"
    type: SidecarSetUpgradable
  1. and the SidecarSet got an event for not upgradable pods
Events:
  Type    Reason             Age                From                   Message
  ----    ------             ----               ----                   -------
  Normal  NotUpgradablePods  5s (x5 over 161m)  sidecarset-controller  SidecarSet in-place update detected 2 not upgradable pod(s) in this round, will skip them.

Ⅳ. Special notes for reviews

@kruise-bot kruise-bot requested review from FillZpp and zmberg June 8, 2023 12:41
@kruise-bot
Copy link

Welcome @MarkLux! It looks like this is your first PR to openkruise/kruise 🎉

@kruise-bot kruise-bot added the size/S size/S 10-29 label Jun 8, 2023
@veophi
Copy link
Member

veophi commented Jun 8, 2023

@MarkLux How about considering a condition for such Pod instead of an event? (too many events will oppress ETCD)

@MarkLux
Copy link
Contributor Author

MarkLux commented Jun 8, 2023

@MarkLux How about a condition for such Pod instead of an event? (too many events will oppress ETCD)

@veophi

do you mean this?

Conditions:
  Type                 Status
  KruisePodReady       True
  InPlaceUpdateReady   True
  Initialized          True
  Ready                True
  ContainersReady      True
  PodScheduled         True
  SidecarUpgradble       False

But the Condition Field may be too short to show the reason, and it's not obvious. I think after user updated SidecarSet, they need a feedback.

If too many events can make an extra stress to etcd, how about add event for SidecarSet instead of Pods? (thus we only got an single event for each update)

btw, currently when the sidecar upgrade succeeded, an event will be added to all the pods(by kubectl), will this also generate too many events?

@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch 2 times, most recently from d3c6995 to 27e6ba6 Compare June 9, 2023 02:01
@kruise-bot kruise-bot added size/M size/M: 30-99 and removed size/S size/S 10-29 labels Jun 9, 2023
@veophi
Copy link
Member

veophi commented Jun 9, 2023

If too many events can make an extra stress to etcd, how about add event for SidecarSet instead of Pods? (thus we only got an single event for each update)

btw, if the sidecar upgrade succeeded, an event will be added to all the pods(by kubectl), I wonder if these events can will oppress etcd too?

@MarkLux Successful Update event will be sent only when Pod update successfully. But Failed Update events may be added at Each Reconciling.

How about this condition?

conditions:
- type: SidecarSetUpgradable
   status: False
   reason: UpdateImmutableField
   message: Pod env and volume fields cannot be modified

@MarkLux MarkLux changed the title add event info for not upgradble pods when update sidecarset (#1272) [WIP] add event info for not upgradble pods when update sidecarset (#1272) Jun 9, 2023
@MarkLux
Copy link
Contributor Author

MarkLux commented Jun 9, 2023

If too many events can make an extra stress to etcd, how about add event for SidecarSet instead of Pods? (thus we only got an single event for each update)
btw, if the sidecar upgrade succeeded, an event will be added to all the pods(by kubectl), I wonder if these events can will oppress etcd too?

@MarkLux Successful Update event will be sent only when Pod update successfully. But Failed Update events may be added at Each Reconciling.

How about this condition?

conditions:
- type: SidecarSetUpgradable
   status: False
   reason: UpdateImmutableField
   message: Pod env and volume fields cannot be modified

got it, I'll change the codes, thanks for your advice

@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch from 27e6ba6 to 7a6c1d7 Compare June 12, 2023 02:31
@codecov-commenter
Copy link

codecov-commenter commented Jun 12, 2023

Codecov Report

Merging #1309 (ffa34ca) into master (6d25366) will increase coverage by 0.24%.
The diff coverage is 63.88%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master    #1309      +/-   ##
==========================================
+ Coverage   48.37%   48.62%   +0.24%     
==========================================
  Files         151      152       +1     
  Lines       21178    21341     +163     
==========================================
+ Hits        10245    10377     +132     
- Misses       9808     9824      +16     
- Partials     1125     1140      +15     
Flag Coverage Δ
unittests 48.62% <63.88%> (+0.24%) ⬆️

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

Impacted Files Coverage Δ
pkg/control/sidecarcontrol/util.go 53.48% <ø> (ø)
pkg/controller/sidecarset/sidecarset_processor.go 66.66% <58.51%> (-2.01%) ⬇️
pkg/controller/sidecarset/sidecarset_strategy.go 92.70% <100.00%> (+2.85%) ⬆️

... and 12 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch 3 times, most recently from 2aa0940 to 4f0f5b2 Compare June 12, 2023 08:22
@MarkLux
Copy link
Contributor Author

MarkLux commented Jun 12, 2023

@veophi made a draft based on adding condition, could you have a brief view on it? some problems are commented

@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch 2 times, most recently from a340aea to cec7aa8 Compare June 13, 2023 01:57
@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch from cec7aa8 to 3ada88a Compare June 14, 2023 02:05
@kruise-bot kruise-bot added size/L size/L: 100-499 and removed size/M size/M: 30-99 labels Jun 14, 2023
@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch 2 times, most recently from b3ff93e to a1e7299 Compare June 15, 2023 09:34
@veophi
Copy link
Member

veophi commented Jun 28, 2023

/lgtm

@veophi
Copy link
Member

veophi commented Jun 28, 2023

/remove lgtm

@veophi
Copy link
Member

veophi commented Jun 28, 2023

@MarkLux If there are more than one SidecarSets that all select one Pod, you must refresh this condition of the Pod to true only if all the SidecarSets can upgrade the Pod.

You can refer to [the following codes] to fix your logic (

func addMessage(base string, msg Message) (bool, messageList) {

@kruise-bot kruise-bot removed the lgtm label Jun 28, 2023
@MarkLux
Copy link
Contributor Author

MarkLux commented Jun 28, 2023

@MarkLux If there are more than one SidecarSets that all select one Pod, you must refresh this condition of the Pod to true only if all the SidecarSets can upgrade the Pod.

You can refer to [the following codes] to fix your logic (

func addMessage(base string, msg Message) (bool, messageList) {

got it

@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch from 0a399a1 to dd4faad Compare June 28, 2023 02:59
@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch 3 times, most recently from d911f9a to ffa34ca Compare July 1, 2023 10:33
@MarkLux
Copy link
Contributor Author

MarkLux commented Jul 4, 2023

@zmberg PTAL

@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch 2 times, most recently from 37085ff to 6a01d5a Compare July 5, 2023 12:02
@MarkLux MarkLux force-pushed the sidecarset_upgrade_event_info branch from 6a01d5a to 4db30ba Compare July 6, 2023 02:17
@zmberg
Copy link
Member

zmberg commented Jul 6, 2023

/lgtm

@kruise-bot kruise-bot added the lgtm label Jul 6, 2023
@zmberg
Copy link
Member

zmberg commented Jul 10, 2023

/approve

@kruise-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zmberg

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

@kruise-bot kruise-bot merged commit 3d39726 into openkruise:master Jul 10, 2023
21 checks passed
diannaowa pushed a commit to diannaowa/kruise that referenced this pull request Aug 29, 2023
…carset (openkruise#1272) (openkruise#1309)

* add condition for pods and event for sidecarset when detecting not upgradable pod (openkruise#1272)

Signed-off-by: MarkLux <marlx6590@163.com>

* add e2e test for sidecarset upgrade out of image fields(openkruise#1272)

Signed-off-by: MarkLux <marlx6590@163.com>

* only update condition to true when all sidecarset upgradable (openkruise#1272)

Signed-off-by: MarkLux <marlx6590@163.com>

---------

Signed-off-by: MarkLux <marlx6590@163.com>
lilongfeng0902 pushed a commit to lilongfeng0902/kruise that referenced this pull request Sep 12, 2023
…carset (openkruise#1272) (openkruise#1309)

* add condition for pods and event for sidecarset when detecting not upgradable pod (openkruise#1272)

Signed-off-by: MarkLux <marlx6590@163.com>

* add e2e test for sidecarset upgrade out of image fields(openkruise#1272)

Signed-off-by: MarkLux <marlx6590@163.com>

* only update condition to true when all sidecarset upgradable (openkruise#1272)

Signed-off-by: MarkLux <marlx6590@163.com>

---------

Signed-off-by: MarkLux <marlx6590@163.com>
ppbits pushed a commit to ppbits/kruise that referenced this pull request Apr 4, 2024
…carset (openkruise#1272) (openkruise#1309)

* add condition for pods and event for sidecarset when detecting not upgradable pod (openkruise#1272)


* add e2e test for sidecarset upgrade out of image fields(openkruise#1272)


* only update condition to true when all sidecarset upgradable (openkruise#1272)


---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Update SidecarSet(Not just the image field) will not trigger sidecar version update.
5 participants