Skip to content

Commit

Permalink
disabled rollout
Browse files Browse the repository at this point in the history
Signed-off-by: Kuromesi <blackfacepan@163.com>
  • Loading branch information
Kuromesi committed Jun 28, 2023
1 parent b69e206 commit 1b516ea
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/e2e/rollout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5485,6 +5485,81 @@ 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() {
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")
rollout2 := rollout.DeepCopy()
rollout2.Name = "rollout-demo2"
rollout2.Spec.Disabled = false
rollout2.SetNamespace(namespace)
By("Webhook should throw an error")
Expect(k8sClient.Create(context.TODO(), rollout2)).Should(HaveOccurred())

By("Creating a disabled rollout")
rollout3 := rollout.DeepCopy()
rollout3.Name = "rollout-demo3"
rollout3.Spec.Disabled = true
CreateObject(rollout3)

By("Creating another disabled rollout")
rollout4 := rollout.DeepCopy()
rollout4.Name = "rollout-demo4"
rollout4.Spec.Disabled = true
CreateObject(rollout4)

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

Expect(GetObject(rollout3.Name, rollout3)).NotTo(HaveOccurred())
Expect(rollout3.Status.Phase).Should(Equal(v1alpha1.RolloutPhaseDisabled))

Expect(GetObject(rollout4.Name, rollout4)).NotTo(HaveOccurred())
Expect(rollout4.Status.Phase).Should(Equal(v1alpha1.RolloutPhaseDisabled))
})

It("Disable a rolling rollout", func() {
By("Create an enabled rollout")
rollout1 := rollout.DeepCopy()
rollout1.Spec.Disabled = false
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())
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)

By("Disable a rolling rollout")
rollout1.Spec.Disabled = true
UpdateRollout(rollout1)
// wait for reconciling
time.Sleep(3 * time.Second)
Expect(GetObject(rollout1.Name, rollout1)).NotTo(HaveOccurred())
Expect(rollout1.Status.Phase).Should(Equal(v1alpha1.RolloutPhaseDisabled))
})

})
})

func mergeEnvVar(original []v1.EnvVar, add v1.EnvVar) []v1.EnvVar {
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/test_data/rollout/deployment_disabled.yaml
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"
19 changes: 19 additions & 0 deletions test/e2e/test_data/rollout/rollout_disabled.yaml
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%

0 comments on commit 1b516ea

Please sign in to comment.