-
Notifications
You must be signed in to change notification settings - Fork 773
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
Conversation
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 { |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
)
f1753ac
to
467a183
Compare
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
63116fc
to
ec1e026
Compare
ec1e026
to
7a9617c
Compare
var raw map[string]interface{} | ||
_ = json.Unmarshal(str, &raw) | ||
objCopy := make(map[string]interface{}) | ||
objCopy["spec"] = raw["spec"].(map[string]interface{}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Do not use
SetLabels
, it will replace the original labels in it. - Why we need
GetRevisionLabelSelector
? How about directlycr.Labels["SidecarSet"] = s.Name
here? - Rename "SidecarSet" to
kruise.io/sidecarset-name
and make it a variable in util.go.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/control/sidecarcontrol/util.go
Outdated
@@ -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" |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
2686690
to
6801438
Compare
/lgtm |
6801438
to
fe454ed
Compare
kubeSysNs := &corev1.Namespace{} | ||
kubeSysNs.SetName(webhookutil.GetNamespace()) //Note that util.GetKruiseManagerNamespace() return "" here | ||
kubeSysNs.SetNamespace(webhookutil.GetNamespace()) | ||
fakeClient := fake.NewFakeClientWithScheme(scheme, sidecarSet, kubeSysNs) |
There was a problem hiding this comment.
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
)
56432c3
to
50e99f0
Compare
/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"` |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
50e99f0
to
3be668f
Compare
ceef177
to
bbd46e0
Compare
1e30627
to
209141e
Compare
209141e
to
b273cfc
Compare
Signed-off-by: veophi <[email protected]>
b273cfc
to
b95ead0
Compare
/lgtm |
/approve |
[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 |
Signed-off-by: veophi <[email protected]>
Signed-off-by: veophi [email protected]
Ⅰ. Describe what this PR does
kruise-manager
;Ⅱ. Does this pull request fix one issue?
fixes #710
Ⅲ. What does it look like?