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

store history revisions for sidecarset #715

Merged
merged 1 commit into from
Dec 29, 2021

Conversation

veophi
Copy link
Member

@veophi veophi commented Aug 18, 2021

Signed-off-by: veophi [email protected]

Ⅰ. Describe what this PR does

  1. Store history revisions for sidecarset.
  • Store sidecarset.spec using controllerRevision;
  • All controllerRevisions of sidecarset will be stored in the namespace of kruise-manager;
  • We set a limited number of stored revisions (default is 10).
  1. Add revision annotation for matched pods.
  • This annotation can remind users which sidecar is not the latest;
  • This annotation may be used in the future(e.g., for the future plan of replacing update operation with patch).

Ⅱ. Does this pull request fix one issue?

fixes #710

Ⅲ. What does it look like?

image

@kruise-bot kruise-bot requested review from Fei-Guo and zmberg August 18, 2021 09:40
@kruise-bot kruise-bot added the size/L size/L: 100-499 label Aug 18, 2021
func (p *Processor) updatePodAnnotationsAboutSidecarNameAndRevision(control sidecarcontrol.SidecarControl, pod *corev1.Pod, latestRevision *apps.ControllerRevision) {
sidecarSet := control.GetSidecarset()
sidecarSetRevisions := make(map[string]string)
if revisions, _ := pod.Annotations[sidecarcontrol.SidecarSetRevisionAnnotation]; len(revisions) > 0 {
Copy link

Choose a reason for hiding this comment

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

S1005: unnecessary assignment to the blank identifier
(at-me in a reply with help or ignore)


showme := map[string]string{"s1": "latest"}
by, _ := json.Marshal(showme)
fmt.Printf(string(by))
Copy link

Choose a reason for hiding this comment

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

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead
(at-me in a reply with help or ignore)

// case 4
for i := 0; i < 100; i++ {
sidecarSet.Spec.Containers[0].Image = fmt.Sprintf("%d", i)
latestRevision, _, err = processor.registerLatestRevision(sidecarSet, selector)
Copy link

Choose a reason for hiding this comment

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

SA4006: this value of err is never used
(at-me in a reply with help or ignore)

// case 4
for i := 0; i < 100; i++ {
sidecarSet.Spec.Containers[0].Image = fmt.Sprintf("%d", i)
latestRevision, _, err = processor.registerLatestRevision(sidecarSet, selector)
Copy link

Choose a reason for hiding this comment

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

SA4006: this value of latestRevision is never used
(at-me in a reply with help or ignore)

@veophi veophi force-pushed the sidecar-revision-control branch 2 times, most recently from f1753ac to 467a183 Compare August 19, 2021 03:54
@codecov-commenter
Copy link

codecov-commenter commented Aug 19, 2021

Codecov Report

Merging #715 (1e30627) into master (8d73235) will decrease coverage by 0.27%.
The diff coverage is 41.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #715      +/-   ##
==========================================
- Coverage   48.02%   47.74%   -0.28%     
==========================================
  Files         118      119       +1     
  Lines       10854    10999     +145     
==========================================
+ Hits         5213     5252      +39     
- Misses       4839     4939     +100     
- Partials      802      808       +6     
Flag Coverage Δ
unittests 47.74% <41.61%> (-0.28%) ⬇️

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

Impacted Files Coverage Δ
pkg/control/sidecarcontrol/history_control.go 0.00% <0.00%> (ø)
pkg/controller/sidecarset/sidecarset_controller.go 13.88% <ø> (ø)
pkg/control/sidecarcontrol/util.go 43.68% <71.42%> (-0.32%) ⬇️
pkg/controller/sidecarset/sidecarset_processor.go 72.80% <73.07%> (-1.34%) ⬇️
pkg/controller/daemonset/update.go 24.24% <0.00%> (-2.53%) ⬇️
pkg/controller/daemonset/daemonset_util.go 60.00% <0.00%> (-2.31%) ⬇️
pkg/controller/uniteddeployment/revision.go 66.15% <0.00%> (-1.54%) ⬇️
...tating/container_launch_priority_initialization.go 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d73235...1e30627. Read the comment docs.

@veophi veophi force-pushed the sidecar-revision-control branch 3 times, most recently from 63116fc to ec1e026 Compare August 19, 2021 07:21
@kruise-bot kruise-bot added size/XL size/XL: 500-999 and removed size/L size/L: 100-499 labels Aug 19, 2021
@veophi veophi force-pushed the sidecar-revision-control branch from ec1e026 to 7a9617c Compare August 19, 2021 07:27
apis/apps/v1alpha1/sidecarset_types.go Show resolved Hide resolved
var raw map[string]interface{}
_ = json.Unmarshal(str, &raw)
objCopy := make(map[string]interface{})
objCopy["spec"] = raw["spec"].(map[string]interface{})
Copy link
Member

Choose a reason for hiding this comment

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

Should not use the whole spec as patch, fields like selector, updateStrategy should be excluded.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

if cr.Labels == nil {
cr.Labels = make(map[string]string)
}
cr.SetLabels(r.GetRevisionLabelSelector(s).MatchLabels)
Copy link
Member

Choose a reason for hiding this comment

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

  1. Do not use SetLabels, it will replace the original labels in it.
  2. Why we need GetRevisionLabelSelector? How about directly cr.Labels["SidecarSet"] = s.Name here?
  3. Rename "SidecarSet" to kruise.io/sidecarset-name and make it a variable in util.go.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

sidecarSetClone := s.DeepCopy()
// set controllerRevision namespace, this namespace must have very
// strict permissions for average users. Here use namespace of kruise-manager
sidecarSetClone.SetNamespace(webhookutil.GetNamespace())
Copy link
Member

Choose a reason for hiding this comment

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

Do not set the namespace in SidecarSet. Just use webhookutil.GetNamespace() in the places need it.

Copy link
Member Author

@veophi veophi Aug 19, 2021

Choose a reason for hiding this comment

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

in kubernetes/pkg/controller/history/controller_history.go, func CreateControllerRevision uses parent's namespace to create ControllerRevision, so we have to set sidecarset namespace here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or we might copy these codes and modify them.

if len(revisions) == 0 || len(revisions) <= limited {
return nil
}
if err := p.historyController.DeleteControllerRevision(revisions[0]); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Should not delete the ControllerRevisions that have existing pods in these revisions.

Copy link
Member Author

Choose a reason for hiding this comment

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

So should we count references for each revisions?

return nil
}

func getCurrentStatus(control sidecarcontrol.SidecarControl, pods []*corev1.Pod,
Copy link
Member

Choose a reason for hiding this comment

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

Just add latestRevision and collisionCount into calculateStatus. No need to define getCurrentStatus and setStatusRevisionInfo

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

// in the future, we will support revision control for sidecar injection,
// some pods may be injected old sidecarSet
if _, ok := sidecarSetRevisions[sidecar]; !ok {
sidecarSetRevisions[sidecar] = sidecarcontrol.SidecarLatestRevision
Copy link
Member

Choose a reason for hiding this comment

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

Don't really understand what does the SidecarLatestRevision for?

Copy link
Member Author

Choose a reason for hiding this comment

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

I realize I'm wrong and I'll fix it as soon as possible.

sidecarCount := len(strings.Split(sidecarSetNames, ","))
if !nameOk || sidecarCount == 0 || len(sidecarSetRevisions) != sidecarCount {
sidecarSets := p.listMatchedSidecarSets(pod)
for _, sidecar := range sidecarSets {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe here should only manage the sidecar revision of this sidecarset in the pod annotation.

Copy link
Member Author

@veophi veophi Aug 19, 2021

Choose a reason for hiding this comment

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

I continue to use the name list annotation just for forward compatibility.

@@ -38,6 +38,10 @@ const (
// SidecarSetHashWithoutImageAnnotation represents the key of a sidecarset hash without images of sidecar
SidecarSetHashWithoutImageAnnotation = "kruise.io/sidecarset-hash-without-image"

// SidecarSetHashAnnotation represents the revision of a sidecarSet
SidecarSetRevisionAnnotation = "kruise.io/sidecarset-injected-revision"
Copy link
Member

Choose a reason for hiding this comment

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

Why not put the revision in SidecarSetUpgradeSpec?

@@ -204,7 +250,7 @@ func (p *Processor) listMatchedSidecarSets(pod *corev1.Pod) string {
}
}

return strings.Join(sidecarSetNames, ",")
return sidecarSetNames
}

func (p *Processor) updateSidecarSetStatus(sidecarSet *appsv1alpha1.SidecarSet, status *appsv1alpha1.SidecarSetStatus) error {
Copy link
Member

Choose a reason for hiding this comment

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

Is function inconsistentStatus necessary to determine revision filed?

@@ -127,13 +142,13 @@ func (p *Processor) UpdateSidecarSet(sidecarSet *appsv1alpha1.SidecarSet) (recon
}

// 7. upgrade pod sidecar
if err := p.updatePods(control, pods); err != nil {
if err := p.updatePods(control, pods, latestRevision); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

sidecarSet.status already contains the latestRevison, so don't need to add additional parameters latestRevision

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean we should execute "get status" in this function?

// update SidecarSetRevisionAnnotation and SidecarSetRevisionAnnotation of pod
// These annotations improve the performance of the sidecarSet controller
// In the future, SidecarSetRevisionAnnotation may help sidecarSet controller replace update operation with patch
p.updatePodAnnotationsAboutSidecarNameAndRevision(control, podClone, latestRevision)
Copy link
Member

Choose a reason for hiding this comment

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

I think you can update revision in function control.updatePodSidecarSetHash

@veophi veophi force-pushed the sidecar-revision-control branch 4 times, most recently from 2686690 to 6801438 Compare August 20, 2021 07:33
@zmberg
Copy link
Member

zmberg commented Aug 20, 2021

/lgtm

kubeSysNs := &corev1.Namespace{}
kubeSysNs.SetName(webhookutil.GetNamespace()) //Note that util.GetKruiseManagerNamespace() return "" here
kubeSysNs.SetNamespace(webhookutil.GetNamespace())
fakeClient := fake.NewFakeClientWithScheme(scheme, sidecarSet, kubeSysNs)
Copy link

Choose a reason for hiding this comment

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

SA1019: fake.NewFakeClientWithScheme is deprecated: Please use NewClientBuilder instead.
(at-me in a reply with help or ignore)

@veophi veophi force-pushed the sidecar-revision-control branch 2 times, most recently from 56432c3 to 50e99f0 Compare September 18, 2021 06:27
@zmberg
Copy link
Member

zmberg commented Oct 22, 2021

/lgtm

// RevisionHistoryLimit indicates the maximum quantity of stored revisions about SidecarSet.
// This value is set by SidecarSet controller.
// default value is 10
RevisionHistoryLimit int32 `json:"revisionHistoryLimit,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

It should be in SidecarSet spec instead of status...

@@ -47,6 +47,7 @@ func init() {
}

var (
maxStoredRevisions = 10
Copy link
Member

Choose a reason for hiding this comment

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

We should use spec.revisionHistoryLimit instead of a fixed number.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@veophi veophi force-pushed the sidecar-revision-control branch from 50e99f0 to 3be668f Compare October 27, 2021 06:50
@kruise-bot kruise-bot removed the lgtm label Oct 27, 2021
@veophi veophi force-pushed the sidecar-revision-control branch 3 times, most recently from ceef177 to bbd46e0 Compare October 28, 2021 04:13
@kruise-bot kruise-bot added size/XXL and removed size/XL size/XL: 500-999 labels Oct 28, 2021
@veophi veophi force-pushed the sidecar-revision-control branch from 1e30627 to 209141e Compare October 28, 2021 05:58
@kruise-bot kruise-bot added size/XL size/XL: 500-999 and removed size/XXL labels Oct 28, 2021
@veophi veophi force-pushed the sidecar-revision-control branch from 209141e to b273cfc Compare December 14, 2021 09:37
@veophi veophi force-pushed the sidecar-revision-control branch from b273cfc to b95ead0 Compare December 20, 2021 08:08
@FillZpp
Copy link
Member

FillZpp commented Dec 20, 2021

/lgtm

@FillZpp
Copy link
Member

FillZpp commented Dec 29, 2021

/approve

@kruise-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FillZpp

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 766a7d1 into openkruise:master Dec 29, 2021
FillZpp pushed a commit that referenced this pull request Jan 21, 2022
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.

[feature request]Support version control for SidecarSet
5 participants