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

Disabled #11

Merged
merged 8 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions api/v1alpha1/rollout_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type RolloutSpec struct {
// It is to distinguish consecutive multiple workload publications and rollout progress.
DeprecatedRolloutID string `json:"rolloutID,omitempty"`
// if a rollout disabled, then the rollout would not watch changes of workload
//+kubebuilder:validation:Optional
//+kubebuilder:default=false
Disabled bool `json:"disabled"`
}

Expand Down Expand Up @@ -198,11 +200,6 @@ const (
ProgressingReasonCancelling = "Cancelling"
ProgressingReasonPaused = "Paused"

// Disabling condition
RolloutConditionDisabling RolloutConditionType = "Disabling"
// Disabling reason
DisablingReasonFinalising = "InDisabling"

// RolloutConditionSucceeded indicates whether rollout is succeeded or failed.
RolloutConditionSucceeded RolloutConditionType = "Succeeded"

Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/rollouts.kruise.io_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ spec:
description: RolloutSpec defines the desired state of Rollout
properties:
disabled:
default: false
description: if a rollout disabled, then the rollout would not watch
changes of workload
type: boolean
Expand Down Expand Up @@ -275,7 +276,6 @@ spec:
type: boolean
type: object
required:
- disabled
- objectRef
- strategy
type: object
Expand Down
5 changes: 0 additions & 5 deletions pkg/controller/rollout/rollout_canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,6 @@ 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 {
return true, nil
}
return false, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/rollout/rollout_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 && rollout.Status.Phase != rolloutv1alpha1.RolloutPhaseDisabled {
if targetRef.Kind == gvk.Kind && targetGV.Group == gvk.Group && targetRef.Name == key.Name {
return &rollout, nil
}
}
Expand Down
42 changes: 19 additions & 23 deletions pkg/controller/rollout/rollout_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,18 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r
return false, newStatus, nil
}

if rollout.Spec.Disabled && newStatus.Phase != v1alpha1.RolloutPhaseDisabling {
if rollout.Spec.Disabled && newStatus.Phase != v1alpha1.RolloutPhaseDisabled && newStatus.Phase != v1alpha1.RolloutPhaseDisabling {
// if rollout in progressing, indicates a working rollout is disabled, then the rollout should be finalized
if newStatus.Phase == v1alpha1.RolloutPhaseProgressing {
newStatus.Phase = v1alpha1.RolloutPhaseDisabling
newStatus.Message = "Disabling rollout, release resources"
} else {
*newStatus = v1alpha1.RolloutStatus{
ObservedGeneration: rollout.Generation,
Phase: v1alpha1.RolloutPhaseDisabled,
Message: "Rollout is disabled",
}
return false, newStatus, nil
newStatus.Phase = v1alpha1.RolloutPhaseDisabled
newStatus.Message = "Rollout is disabled"
}
}

if newStatus.Phase == "" || newStatus.Phase == v1alpha1.RolloutPhaseDisabled {
if newStatus.Phase == "" {
newStatus.Phase = v1alpha1.RolloutPhaseInitial
}
// get ref workload
Expand All @@ -74,12 +70,14 @@ 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 {
newStatus = &v1alpha1.RolloutStatus{
ObservedGeneration: rollout.Generation,
Phase: v1alpha1.RolloutPhaseInitial,
Message: "Workload Not Found",
if !rollout.Spec.Disabled {
newStatus = &v1alpha1.RolloutStatus{
ObservedGeneration: rollout.Generation,
Phase: v1alpha1.RolloutPhaseInitial,
Message: "Workload Not Found",
}
klog.Infof("rollout(%s/%s) workload not found, and reset status be Initial", rollout.Namespace, rollout.Name)
}
klog.Infof("rollout(%s/%s) workload not found, and reset status be Initial", rollout.Namespace, rollout.Name)
return false, newStatus, nil
}
klog.V(5).Infof("rollout(%s/%s) workload(%s)", rollout.Namespace, rollout.Name, util.DumpJSON(workload))
Expand Down Expand Up @@ -138,9 +136,11 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r
}
newStatus.Message = "workload deployment is completed"
}
case v1alpha1.RolloutPhaseDisabling:
cond := util.NewRolloutCondition(v1alpha1.RolloutConditionDisabling, corev1.ConditionTrue, v1alpha1.DisablingReasonFinalising, "Rollout is disabled and releasing resources")
util.SetRolloutCondition(newStatus, *cond)
case v1alpha1.RolloutPhaseDisabled:
if !rollout.Spec.Disabled {
newStatus.Phase = v1alpha1.RolloutPhaseHealthy
newStatus.Message = "rollout is healthy"
}
}
return false, newStatus, nil
}
Expand Down Expand Up @@ -227,7 +227,6 @@ func (r *RolloutReconciler) reconcileRolloutTerminating(rollout *v1alpha1.Rollou
}

func (r *RolloutReconciler) reconcileRolloutDisabling(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutStatus) (*time.Time, error) {
cond := util.GetRolloutCondition(rollout.Status, v1alpha1.RolloutConditionDisabling)
workload, err := r.finder.GetWorkloadForRef(rollout)
if err != nil {
klog.Errorf("rollout(%s/%s) get workload failed: %s", rollout.Namespace, rollout.Name, err.Error())
Expand All @@ -238,12 +237,9 @@ func (r *RolloutReconciler) reconcileRolloutDisabling(rollout *v1alpha1.Rollout,
if err != nil {
return nil, err
} else if done {
klog.Infof("rollout(%s/%s) is disabling, and state from(%s) -> to(%s)", rollout.Namespace, rollout.Name, cond.Reason, v1alpha1.RolloutPhaseDisabled)
*newStatus = v1alpha1.RolloutStatus{
ObservedGeneration: rollout.Generation,
Phase: v1alpha1.RolloutPhaseDisabled,
Message: "Rollout is disabled",
}
klog.Infof("rollout(%s/%s) is disabled", rollout.Namespace, rollout.Name)
newStatus.Phase = v1alpha1.RolloutPhaseDisabled
newStatus.Message = "Rollout is disabled"
} else {
// Incomplete, recheck
expectedTime := time.Now().Add(time.Duration(defaultGracePeriodSeconds) * time.Second)
Expand Down
4 changes: 4 additions & 0 deletions pkg/webhook/workload/mutating/workload_update_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ func (h *WorkloadHandler) fetchMatchedRollout(obj client.Object) (*appsv1alpha1.
if !rollout.DeletionTimestamp.IsZero() || rollout.Spec.ObjectRef.WorkloadRef == nil {
continue
}
if rollout.Status.Phase == appsv1alpha1.RolloutPhaseDisabled {
klog.Infof("Disabled rollout(%s/%s) fetched when fetching matched rollout", rollout.Namespace, rollout.Name)
continue
}
ref := rollout.Spec.ObjectRef.WorkloadRef
gv, err := schema.ParseGroupVersion(ref.APIVersion)
if err != nil {
Expand Down
42 changes: 29 additions & 13 deletions test/e2e/rollout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5489,7 +5489,7 @@ var _ = SIGDescribe("Rollout", func() {
KruiseDescribe("Disabled rollout tests", func() {
rollout := &v1alpha1.Rollout{}
Expect(ReadYamlToObject("./test_data/rollout/rollout_disabled.yaml", rollout)).ToNot(HaveOccurred())
It("Conflict checks", func() {
It("Rollout status tests", func() {
By("Create an enabled rollout")
rollout1 := rollout.DeepCopy()
rollout1.Name = "rollout-demo1"
Expand All @@ -5510,21 +5510,14 @@ var _ = SIGDescribe("Rollout", func() {
rollout3.Spec.Disabled = true
rollout2.SetNamespace(namespace)
Expect(k8sClient.Create(context.TODO(), rollout2)).Should(HaveOccurred())

// wait for reconciling
time.Sleep(3 * time.Second)
Expect(GetObject(rollout1.Name, rollout1)).NotTo(HaveOccurred())
Expect(rollout1.Status.Phase).Should(Equal(v1alpha1.RolloutPhaseInitial))
})

It("Disable a rolling rollout", func() {
By("Create an enabled rollout")
rollout1 := rollout.DeepCopy()
rollout1.Spec.Disabled = false
By("Create workload")
deploy := &apps.Deployment{}
Expect(ReadYamlToObject("./test_data/rollout/deployment_disabled.yaml", deploy)).ToNot(HaveOccurred())

CreateObject(rollout1)
CreateObject(deploy)
WaitDeploymentAllPodsReady(deploy)
Expect(GetObject(rollout1.Name, rollout1)).NotTo(HaveOccurred())
Expand All @@ -5534,22 +5527,45 @@ var _ = SIGDescribe("Rollout", func() {
Expect(GetObject(deploy.Name, deploy)).NotTo(HaveOccurred())
newEnvs := mergeEnvVar(deploy.Spec.Template.Spec.Containers[0].Env, v1.EnvVar{Name: "VERSION", Value: "version-2"})
deploy.Spec.Template.Spec.Containers[0].Env = newEnvs

UpdateDeployment(deploy)
WaitRolloutCanaryStepPaused(rollout1.Name, 1)
Expect(GetObject(rollout1.Name, rollout1)).NotTo(HaveOccurred())
Expect(rollout1.Status.CanaryStatus.CanaryReplicas).Should(BeNumerically("==", 2))
Expect(rollout1.Status.CanaryStatus.CanaryReadyReplicas).Should(BeNumerically("==", 2))
Expect(GetObject(deploy.Name, deploy)).NotTo(HaveOccurred())
Expect(deploy.Spec.Paused).Should(BeTrue())

By("Disable a rolling rollout")
rollout1.Spec.Disabled = true
UpdateRollout(rollout1)
// wait for reconciling
time.Sleep(5 * time.Second)
key := types.NamespacedName{Namespace: namespace, Name: rollout1.Name}

By("Rolling should be resumed")
Expect(GetObject(deploy.Name, deploy)).NotTo(HaveOccurred())
Expect(deploy.Spec.Paused).Should(BeFalse())

By("Batchrelease should be deleted")
key := types.NamespacedName{Namespace: namespace, Name: rollout1.Name}
Expect(k8sClient.Get(context.TODO(), key, &v1alpha1.BatchRelease{})).Should(HaveOccurred())
Expect(GetObject(rollout1.Name, rollout1)).NotTo(HaveOccurred())
Expect(rollout1.Status.Phase).Should(Equal(v1alpha1.RolloutPhaseDisabled))
})

By("Updating deployment version-2 to version-3")
Expect(GetObject(deploy.Name, deploy)).NotTo(HaveOccurred())
newEnvs = mergeEnvVar(deploy.Spec.Template.Spec.Containers[0].Env, v1.EnvVar{Name: "VERSION", Value: "version-3"})
deploy.Spec.Template.Spec.Containers[0].Env = newEnvs
UpdateDeployment(deploy)
time.Sleep(3 * time.Second)
Expect(GetObject(deploy.Name, deploy)).NotTo(HaveOccurred())
Expect(deploy.Spec.Paused).Should(BeFalse())

By("Enable a disabled rollout")
rollout1.Spec.Disabled = false
UpdateRollout(rollout1)
time.Sleep(3 * time.Second)
Expect(GetObject(rollout1.Name, rollout1)).NotTo(HaveOccurred())
Expect(rollout1.Status.Phase).Should(Equal(v1alpha1.RolloutPhaseHealthy))
})
})
})

Expand Down
Loading