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 disabled field in rollout spec #155

Merged
merged 1 commit into from
Jul 5, 2023
Merged

Conversation

Kuromesi
Copy link
Contributor

@Kuromesi Kuromesi commented Jun 26, 2023

Ⅰ. Describe what this PR does

Added Disabled field in rollout spec.
Added a rollout phase constant.

// RolloutPhaseDisabled indicates a rollout is disabled
RolloutPhaseDisabled RolloutPhase = "Disabled"

How the Disabled spec works?

  • If a rollout is disabled, the rollout is not working.
  • When an rolling rollout is disabled, release the resources of the rollout and set its phase as Disabled.

Ⅱ. Does this pull request fix one issue?

fixes #151

Ⅲ. Special notes for reviews

@kruise-bot kruise-bot requested review from FillZpp and zmberg June 26, 2023 02:53
@kruise-bot
Copy link

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)
Copy link

Choose a reason for hiding this comment

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

27% of developers fix this issue

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)
Copy link

Choose a reason for hiding this comment

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

27% of developers fix this issue

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 {
Copy link

Choose a reason for hiding this comment

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

28% of developers fix this issue

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
Copy link

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.

@zmberg
Copy link
Member

zmberg commented Jun 26, 2023

@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-commenter
Copy link

codecov-commenter commented Jun 27, 2023

Codecov Report

Merging #155 (10b8f2a) into master (8737f33) will decrease coverage by 0.02%.
The diff coverage is 21.05%.

❗ Current head 10b8f2a differs from pull request most recent head bf8b850. Consider uploading reports for the commit bf8b850 to get more accurate results

❗ 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     
Flag Coverage Δ
unittests 43.70% <21.05%> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
pkg/controller/rollout/rollout_canary.go 42.75% <ø> (ø)
pkg/controller/rollout/rollout_controller.go 11.26% <0.00%> (-0.33%) ⬇️
pkg/controller/rollout/rollout_event_handler.go 48.57% <ø> (ø)
...bhook/workload/mutating/workload_update_handler.go 33.21% <0.00%> (-0.38%) ⬇️
pkg/controller/rollout/rollout_status.go 24.52% <24.24%> (+5.29%) ⬆️

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

@kruise-bot kruise-bot added size/XL and removed size/L labels Jun 27, 2023
@Kuromesi Kuromesi changed the title Dev Disabled rollouts Jun 28, 2023
@kruise-bot kruise-bot added size/L and removed size/XL labels Jun 28, 2023
@@ -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"`
Copy link
Member

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 {
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 the code can be removed, because if rollout is disabled, the program will not execute here

@sumengzs
Copy link

sumengzs commented Jun 29, 2023

@Kuromesi 我看了一下,你的代码中,似乎没有考虑到 rollout 从 Progressing 转换到 Disabled 如何处理的问题,你需要仔细阅读源代码, rollout 这个 CR 实际上是一个控制角色,实际的执行角色是,BatchRelease 这个CR,当 rollout 处于 Progressing 状态时,BatchRelease 已经被创建,它会忠实的履行 rollout 给到的指令。或许你可以思考一下如何处理这个部分。

@@ -196,6 +197,10 @@ const (
ProgressingReasonCancelling = "Cancelling"
ProgressingReasonPaused = "Paused"

// Disabling condition
RolloutConditionDisabling RolloutConditionType = "Disabling"
Copy link

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.

@Kuromesi Kuromesi force-pushed the dev branch 3 times, most recently from 07da68f to e0c50cb Compare June 29, 2023 03:41
@Kuromesi
Copy link
Contributor Author

@Kuromesi 我看了一下,你的代码中,似乎没有考虑到 rollout 从 Progressing 转换到 Disabled 如何处理的问题,你需要仔细阅读源代码, rollout 这个 CR 实际上是一个控制角色,实际的执行角色是,BatchRelease 这个CR,当 rollout 处于 Progressing 状态时,BatchRelease 已经被创建,它会忠实的履行 rollout 给到的指令。或许你可以思考一下如何处理这个部分。

感谢建议,在新版的代码中已经对逻辑进行了重写

@@ -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 {
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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{
Copy link
Member

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")
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 that if there are multiple Rollout creations, the Webhook should reject the later rollout creations.

@@ -196,6 +198,11 @@ const (
ProgressingReasonCancelling = "Cancelling"
ProgressingReasonPaused = "Paused"

// Disabling condition
RolloutConditionDisabling RolloutConditionType = "Disabling"
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 we can remove the disabling condition currently.

@Kuromesi Kuromesi changed the title Disabled rollouts Add disabled field in rollout spec Jul 4, 2023
@@ -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 {
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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.

@zmberg
Copy link
Member

zmberg commented Jul 5, 2023

/lgtm

@veophi
Copy link
Member

veophi commented Jul 5, 2023

/lgtm

@@ -5485,6 +5485,82 @@ var _ = SIGDescribe("Rollout", func() {
})

})

KruiseDescribe("Disabled rollout tests", func() {
Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

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

@kruise-bot kruise-bot removed the lgtm label Jul 5, 2023
@Kuromesi Kuromesi force-pushed the dev branch 2 times, most recently from 10b8f2a to bf8b850 Compare July 5, 2023 08:01
Signed-off-by: Kuromesi <blackfacepan@163.com>
@furykerry
Copy link
Member

/lgtm

@zmberg
Copy link
Member

zmberg commented Jul 5, 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 88e4bb7 into openkruise:master Jul 5, 2023
Kuromesi added a commit to Kuromesi/rollouts that referenced this pull request Jul 17, 2023
Signed-off-by: Kuromesi <blackfacepan@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] support disable rollout
7 participants