-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,18 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1alpha1.Rollout) (r | |
} | ||
return false, newStatus, nil | ||
} | ||
|
||
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.Phase = v1alpha1.RolloutPhaseDisabled | ||
newStatus.Message = "Rollout is disabled" | ||
} | ||
} | ||
|
||
if newStatus.Phase == "" { | ||
newStatus.Phase = v1alpha1.RolloutPhaseInitial | ||
} | ||
|
@@ -58,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)) | ||
|
@@ -122,6 +136,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 commentThe reason will be displayed to describe this comment to others. Learn more. newStatus.Phase = v1alpha1.RolloutPhaseInitial, Because workload may be not found. |
||
newStatus.Message = "rollout is healthy" | ||
} | ||
} | ||
return false, newStatus, nil | ||
} | ||
|
@@ -207,6 +226,29 @@ func (r *RolloutReconciler) reconcileRolloutTerminating(rollout *v1alpha1.Rollou | |
return c.RecheckTime, nil | ||
} | ||
|
||
func (r *RolloutReconciler) reconcileRolloutDisabling(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutStatus) (*time.Time, error) { | ||
workload, err := r.finder.GetWorkloadForRef(rollout) | ||
if err != nil { | ||
klog.Errorf("rollout(%s/%s) get workload failed: %s", rollout.Namespace, rollout.Name, err.Error()) | ||
return nil, err | ||
} | ||
c := &RolloutContext{Rollout: rollout, NewStatus: newStatus, Workload: workload} | ||
done, err := r.doFinalising(c) | ||
if err != nil { | ||
return nil, err | ||
} else if done { | ||
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) | ||
c.RecheckTime = &expectedTime | ||
klog.Infof("rollout(%s/%s) disabling is incomplete, and recheck(%s)", rollout.Namespace, rollout.Name, expectedTime.String()) | ||
} | ||
return c.RecheckTime, nil | ||
} | ||
|
||
// handle adding and handle finalizer logic, it turns if we should continue to reconcile | ||
func (r *RolloutReconciler) handleFinalizer(rollout *v1alpha1.Rollout) error { | ||
// delete rollout crd, remove finalizer | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5485,6 +5485,88 @@ var _ = SIGDescribe("Rollout", func() { | |
}) | ||
|
||
}) | ||
|
||
KruiseDescribe("Disabled rollout tests", func() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an ut about enable a disabled rollout |
||
rollout := &v1alpha1.Rollout{} | ||
Expect(ReadYamlToObject("./test_data/rollout/rollout_disabled.yaml", rollout)).ToNot(HaveOccurred()) | ||
It("Rollout status tests", func() { | ||
By("Create an enabled rollout") | ||
rollout1 := rollout.DeepCopy() | ||
rollout1.Name = "rollout-demo1" | ||
rollout1.Spec.Disabled = false | ||
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 commentThe 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. |
||
rollout2 := rollout.DeepCopy() | ||
rollout2.Name = "rollout-demo2" | ||
rollout2.Spec.Disabled = false | ||
rollout2.SetNamespace(namespace) | ||
Expect(k8sClient.Create(context.TODO(), rollout2)).Should(HaveOccurred()) | ||
|
||
By("Creating a disabled rollout") | ||
rollout3 := rollout.DeepCopy() | ||
rollout3.Name = "rollout-demo3" | ||
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)) | ||
|
||
By("Create workload") | ||
deploy := &apps.Deployment{} | ||
Expect(ReadYamlToObject("./test_data/rollout/deployment_disabled.yaml", deploy)).ToNot(HaveOccurred()) | ||
CreateObject(deploy) | ||
WaitDeploymentAllPodsReady(deploy) | ||
Expect(GetObject(rollout1.Name, rollout1)).NotTo(HaveOccurred()) | ||
Expect(rollout1.Status.Phase).Should(Equal(v1alpha1.RolloutPhaseHealthy)) | ||
|
||
By("Updating deployment version-1 to version-2") | ||
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) | ||
time.Sleep(5 * time.Second) | ||
|
||
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)) | ||
}) | ||
}) | ||
}) | ||
|
||
func mergeEnvVar(original []v1.EnvVar, add v1.EnvVar) []v1.EnvVar { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: workload-demo | ||
namespace: default | ||
spec: | ||
replicas: 10 | ||
selector: | ||
matchLabels: | ||
app: demo | ||
template: | ||
metadata: | ||
labels: | ||
app: demo | ||
spec: | ||
containers: | ||
- name: busybox | ||
image: busybox:latest | ||
imagePullPolicy: IfNotPresent | ||
command: ["/bin/sh", "-c", "sleep 100d"] | ||
env: | ||
- name: VERSION | ||
value: "version-1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: rollouts.kruise.io/v1alpha1 | ||
kind: Rollout | ||
metadata: | ||
name: rollouts-demo | ||
namespace: default | ||
annotations: | ||
rollouts.kruise.io/rolling-style: partition | ||
spec: | ||
disabled: false | ||
objectRef: | ||
workloadRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: workload-demo | ||
strategy: | ||
canary: | ||
steps: | ||
- replicas: 2 | ||
- replicas: 50% |
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 {