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

fix sidecarset hot upgrade reset empty container bug #1054

Merged
merged 1 commit into from
Aug 12, 2022

Conversation

zmberg
Copy link
Member

@zmberg zmberg commented Aug 9, 2022

Signed-off-by: liheng.zms liheng.zms@alibaba-inc.com

Ⅰ. Describe what this PR does

  1. flip old container to empty image logic: only the image should be updated at this point, but not the Pod sidecarSet hash, which will cause this hash error if published consecutively
  2. when only update main container, need patch sidecarSet pod metadata

@kruise-bot kruise-bot requested review from Fei-Guo and furykerry August 9, 2022 13:00
@kruise-bot kruise-bot added the size/L size/L: 100-499 label Aug 9, 2022
@codecov-commenter
Copy link

codecov-commenter commented Aug 9, 2022

Codecov Report

Merging #1054 (e1dbf76) into master (2319654) will increase coverage by 0.02%.
The diff coverage is 54.54%.

@@            Coverage Diff             @@
##           master    #1054      +/-   ##
==========================================
+ Coverage   49.34%   49.36%   +0.02%     
==========================================
  Files         125      125              
  Lines       12355    12363       +8     
==========================================
+ Hits         6096     6103       +7     
+ Misses       5320     5319       -1     
- Partials      939      941       +2     
Flag Coverage Δ
unittests 49.36% <54.54%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
pkg/control/sidecarcontrol/sidecarset_control.go 36.00% <ø> (-0.64%) ⬇️
pkg/webhook/pod/mutating/sidecarset.go 63.71% <46.15%> (+0.20%) ⬆️
pkg/controller/sidecarset/sidecarset_processor.go 65.66% <50.00%> (+0.26%) ⬆️
pkg/control/sidecarcontrol/util.go 54.92% <80.00%> (+1.59%) ⬆️
pkg/controller/uniteddeployment/revision.go 66.41% <0.00%> (-1.53%) ⬇️

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

pkg/control/sidecarcontrol/util.go Show resolved Hide resolved
sidecarSet := control.GetSidecarset()
if sk, err := sidecarcontrol.PatchPodMetadata(&pod.ObjectMeta, sidecarSet.Spec.PatchPodMetadata); err != nil {
klog.Errorf("sidecarSet(%s) update pod(%s/%s) metadata failed: %s", sidecarSet.Name, pod.Namespace, pod.Name, err.Error())
return false, err
Copy link
Member

Choose a reason for hiding this comment

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

i suggest that we all use return statement with explicit return variables, it's more clear . and when patch pod meta data fails, it seems that we should return true, err

admission.Request{AdmissionRequest: admissionv1.AdmissionRequest{Object: req.AdmissionRequest.OldObject}},
oldPod); err != nil {
return false, err
return
Copy link
Member

Choose a reason for hiding this comment

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

it changes the return logic, it return false previously and now return true, plz confirm it is expected

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, if error, skip will not take effect. I'll revert to the previous code

if err := h.Client.List(ctx, sidecarsetList, utilclient.DisableDeepCopy); err != nil {
return false, err
if err = h.Client.List(ctx, sidecarsetList, utilclient.DisableDeepCopy); err != nil {
return
Copy link
Member

Choose a reason for hiding this comment

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

it changes the return logic, it return false previously and now return true, plz confirm it is expected

}
}

klog.V(3).Infof("[sidecar inject] begin to operation(%s) pod(%s/%s) resources(%s) subResources(%s)",
req.Operation, req.Namespace, req.Name, req.Resource, req.SubResource)
// patch pod metadata, annotations & labels
for _, control := range matchedSidecarSets {
Copy link
Member

Choose a reason for hiding this comment

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

plz comment in the code why the code block should be move to this position

@zmberg zmberg force-pushed the fix-sidecarset-upgrade-bug branch from 8fb4255 to dacc23f Compare August 10, 2022 05:59
Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>
@zmberg zmberg force-pushed the fix-sidecarset-upgrade-bug branch from dacc23f to e1dbf76 Compare August 12, 2022 04:55
Copy link
Member

@furykerry furykerry left a comment

Choose a reason for hiding this comment

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

/lgtm

@zmberg
Copy link
Member Author

zmberg commented Aug 12, 2022

/approve

1 similar comment
@furykerry
Copy link
Member

/approve

@kruise-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: furykerry, 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 fc174ab into openkruise:master Aug 12, 2022
@zmberg zmberg deleted the fix-sidecarset-upgrade-bug branch August 12, 2022 07:34
diannaowa pushed a commit to diannaowa/kruise that referenced this pull request Sep 14, 2022
Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>

Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>
Signed-off-by: Liu Zhenwei <zwliu@thoughtworks.com>
ppbits pushed a commit to ppbits/kruise that referenced this pull request Apr 4, 2024
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.

4 participants