-
Notifications
You must be signed in to change notification settings - Fork 74
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 disabled field in rollout spec #155
Conversation
Welcome @Kuromesi! It looks like this is your first PR to openkruise/rollouts 🎉 |
rollout.Status.Phase = v1alpha1.RolloutPhaseTerminating | ||
cond := util.NewRolloutCondition(v1alpha1.RolloutConditionTerminating, corev1.ConditionTrue, v1alpha1.TerminatingReasonInTerminating, "Rollout is in terminating") | ||
util.SetRolloutCondition(&rollout.Status, *cond) | ||
r.reconcileRolloutTerminating(rollout, &rollout.Status) |
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.
G104: Errors unhandled.
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Command | Usage |
---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
rollout.Status.Phase = v1alpha1.RolloutPhaseTerminating | ||
cond := util.NewRolloutCondition(v1alpha1.RolloutConditionTerminating, corev1.ConditionTrue, v1alpha1.TerminatingReasonInTerminating, "Rollout is in terminating") | ||
util.SetRolloutCondition(&rollout.Status, *cond) | ||
r.reconcileRolloutTerminating(rollout, &rollout.Status) |
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.
G104: Errors unhandled.
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Command | Usage |
---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
@@ -120,11 +120,14 @@ func (h *RolloutCreateUpdateHandler) validateRolloutUpdate(oldObj, newObj *appsv | |||
|
|||
func (h *RolloutCreateUpdateHandler) validateRollout(rollout *appsv1alpha1.Rollout) field.ErrorList { | |||
errList := validateRolloutSpec(rollout, field.NewPath("Spec")) | |||
errList = append(errList, h.validateRolloutConflict(rollout, field.NewPath("Conflict Checker"))...) | |||
// errList = append(errList, h.validateRolloutConflict(rollout, field.NewPath("Conflict Checker"))...) | |||
return errList | |||
} | |||
|
|||
func (h *RolloutCreateUpdateHandler) validateRolloutConflict(rollout *appsv1alpha1.Rollout, path *field.Path) field.ErrorList { |
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.
U1000: func (*RolloutCreateUpdateHandler).validateRolloutConflict is unused
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Command | Usage |
---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
|
||
// check if an enabled rollout conflicts with other enabled rollout | ||
func (r *RolloutReconciler) checkConflict(rollout *v1alpha1.Rollout) (bool, error) { | ||
// if rollout is enabling or terminating then the conflict check is not neccessary |
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.
misspell: neccessary
is a misspelling of necessary
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Command | Usage |
---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
@Kuromesi I think that for the moment we can dispense with the "rollout conflicts with another rollout" scenario and assume that there is a rollout. |
Codecov Report
❗ 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 #155 +/- ##
==========================================
- Coverage 43.72% 43.70% -0.02%
==========================================
Files 50 50
Lines 5263 5297 +34
==========================================
+ Hits 2301 2315 +14
- Misses 2575 2588 +13
- Partials 387 394 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
api/v1alpha1/rollout_types.go
Outdated
@@ -72,6 +72,7 @@ type RolloutSpec struct { | |||
// RolloutID should be changed before each workload revision publication. | |||
// It is to distinguish consecutive multiple workload publications and rollout progress. | |||
DeprecatedRolloutID string `json:"rolloutID,omitempty"` | |||
Disabled bool `json:"disabled"` |
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.
add comments to describe the meaning and behaviour of disabled
@@ -454,6 +454,11 @@ func (m *canaryReleaseManager) finalizingBatchRelease(c *RolloutContext) (bool, | |||
return false, err | |||
} | |||
klog.Infof("rollout(%s/%s) patch batchRelease(%s) success", c.Rollout.Namespace, c.Rollout.Name, body) | |||
|
|||
// if rollout is disabled, then the batchrelease should be deleted | |||
if c.Rollout.Spec.Disabled { |
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 the code can be removed, because if rollout is disabled, the program will not execute here
@Kuromesi 我看了一下,你的代码中,似乎没有考虑到 rollout 从 Progressing 转换到 Disabled 如何处理的问题,你需要仔细阅读源代码, rollout 这个 CR 实际上是一个控制角色,实际的执行角色是,BatchRelease 这个CR,当 rollout 处于 Progressing 状态时,BatchRelease 已经被创建,它会忠实的履行 rollout 给到的指令。或许你可以思考一下如何处理这个部分。 |
api/v1alpha1/rollout_types.go
Outdated
@@ -196,6 +197,10 @@ const ( | |||
ProgressingReasonCancelling = "Cancelling" | |||
ProgressingReasonPaused = "Paused" | |||
|
|||
// Disabling condition | |||
RolloutConditionDisabling RolloutConditionType = "Disabling" |
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.
SA9004: only the first constant in this group has an explicit type
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Command | Usage |
---|---|
@sonatype-lift ignore |
Leave out the above finding from this PR |
@sonatype-lift ignoreall |
Leave out all the existing findings from this PR |
@sonatype-lift exclude <file|issue|path|tool> |
Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file |
Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.
07da68f
to
e0c50cb
Compare
感谢建议,在新版的代码中已经对逻辑进行了重写 |
@@ -92,7 +92,7 @@ func (w *enqueueRequestForWorkload) getRolloutForWorkload(key types.NamespacedNa | |||
continue | |||
} | |||
|
|||
if targetRef.Kind == gvk.Kind && targetGV.Group == gvk.Group && targetRef.Name == key.Name { | |||
if targetRef.Kind == gvk.Kind && targetGV.Group == gvk.Group && targetRef.Name == key.Name && rollout.Status.Phase != rolloutv1alpha1.RolloutPhaseDisabled { |
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.
Remove the judgement for now.
} | ||
} | ||
|
||
if newStatus.Phase == "" || newStatus.Phase == v1alpha1.RolloutPhaseDisabled { |
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 newStatus.phase == newStatus.Phase == v1alpha1.RolloutPhaseDisabled, then set newStatus.Phase = v1alpha1.RolloutPhaseInitial ?
@@ -49,7 +49,23 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r | |||
} | |||
return false, newStatus, nil | |||
} | |||
if newStatus.Phase == "" { | |||
|
|||
if rollout.Spec.Disabled && newStatus.Phase != v1alpha1.RolloutPhaseDisabling { |
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.
if rollout.Spec.Disabled && (newStatus.Phase != v1alpha1.RolloutPhaseDisabling || newStatus.Phase != v1alpha1.RolloutPhaseDisabled {
newStatus.Phase = v1alpha1.RolloutPhaseDisabling | ||
newStatus.Message = "Disabling rollout, release resources" | ||
} else { | ||
*newStatus = v1alpha1.RolloutStatus{ |
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 you new struct RolloutStatus? Can you set the newStatus filed immediately?
CreateObject(rollout1) | ||
time.Sleep(1 * time.Second) | ||
|
||
By("Create another enabled rollout") |
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 that if there are multiple Rollout creations, the Webhook should reject the later rollout creations.
api/v1alpha1/rollout_types.go
Outdated
@@ -196,6 +198,11 @@ const ( | |||
ProgressingReasonCancelling = "Cancelling" | |||
ProgressingReasonPaused = "Paused" | |||
|
|||
// Disabling condition | |||
RolloutConditionDisabling RolloutConditionType = "Disabling" |
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 we can remove the disabling condition currently.
@@ -454,6 +454,11 @@ func (m *canaryReleaseManager) finalizingBatchRelease(c *RolloutContext) (bool, | |||
return false, err | |||
} | |||
klog.Infof("rollout(%s/%s) patch batchRelease(%s) success", c.Rollout.Namespace, c.Rollout.Name, body) | |||
|
|||
// if rollout is disabling, then the batchrelease should be deleted | |||
if c.NewStatus.Phase == v1alpha1.RolloutPhaseDisabling { |
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.
Remove the code, because the progressing will never run this, when rollout.spec.disabled is true.
newStatus.Message = "Disabling rollout, release resources" | ||
} else { | ||
newStatus.Phase = v1alpha1.RolloutPhaseDisabled | ||
newStatus.ObservedGeneration = rollout.Generation |
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.
remove the generation code, because the above code already set this field.
@@ -58,10 +71,12 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r | |||
klog.Errorf("rollout(%s/%s) get workload failed: %s", rollout.Namespace, rollout.Name, err.Error()) | |||
return false, nil, err | |||
} else if workload == 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.
} else if workload == nil && !rollout.Spec.Disabled {
@@ -122,6 +137,11 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r | |||
} | |||
newStatus.Message = "workload deployment is completed" | |||
} | |||
case v1alpha1.RolloutPhaseDisabled: | |||
if !rollout.Spec.Disabled { | |||
newStatus.Phase = v1alpha1.RolloutPhaseHealthy |
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.
newStatus.Phase = v1alpha1.RolloutPhaseInitial, Because workload may be not found.
} else if done { | ||
klog.Infof("rollout(%s/%s) is disabled", rollout.Namespace, rollout.Name) | ||
newStatus.Phase = v1alpha1.RolloutPhaseDisabled | ||
newStatus.ObservedGeneration = rollout.Generation |
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.
Remove the generation code.
@@ -406,7 +406,7 @@ func (h *WorkloadHandler) fetchMatchedRollout(obj client.Object) (*appsv1alpha1. | |||
} | |||
for i := range rolloutList.Items { | |||
rollout := &rolloutList.Items[i] | |||
if !rollout.DeletionTimestamp.IsZero() || rollout.Spec.ObjectRef.WorkloadRef == nil { | |||
if !rollout.DeletionTimestamp.IsZero() || rollout.Spec.ObjectRef.WorkloadRef == nil || rollout.Status.Phase == appsv1alpha1.RolloutPhaseDisabled { |
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.
when rollout is disabled, add log.
/lgtm |
/lgtm |
@@ -5485,6 +5485,82 @@ var _ = SIGDescribe("Rollout", func() { | |||
}) | |||
|
|||
}) | |||
|
|||
KruiseDescribe("Disabled rollout tests", func() { |
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.
add an ut about enable a disabled rollout
@@ -271,6 +275,7 @@ spec: | |||
type: boolean | |||
type: object | |||
required: | |||
- disabled |
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.
can disabled be optional ? defaults to false?
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.
Have already fixed the issues mentioned above
10b8f2a
to
bf8b850
Compare
Signed-off-by: Kuromesi <blackfacepan@163.com>
/lgtm |
/approve |
[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 |
Signed-off-by: Kuromesi <blackfacepan@163.com>
Ⅰ. Describe what this PR does
Added
Disabled
field in rollout spec.Added a rollout phase constant.
How the Disabled spec works?
Disabled
.Ⅱ. Does this pull request fix one issue?
fixes #151
Ⅲ. Special notes for reviews