Skip to content

Commit

Permalink
add e2e test for sidecarset upgrade out of image fields(#1272)
Browse files Browse the repository at this point in the history
Signed-off-by: MarkLux <[email protected]>
  • Loading branch information
MarkLux committed Jun 28, 2023
1 parent 88bf496 commit dd4faad
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/e2e/apps/sidecarset.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,69 @@ var _ = SIGDescribe("SidecarSet", func() {
ginkgo.By(fmt.Sprintf("sidecarSet upgrade cold sidecar container failed image, and only update one pod done"))
})

framework.ConformanceIt("sidecarSet upgrade sidecar container (more than image field), no pod should be updated", func() {
// create sidecarSet
sidecarSetIn := tester.NewBaseSidecarSet(ns)
sidecarSetIn.Spec.UpdateStrategy = appsv1alpha1.SidecarSetUpdateStrategy{
Type: appsv1alpha1.RollingUpdateSidecarSetStrategyType,
}
sidecarSetIn.Spec.Containers = sidecarSetIn.Spec.Containers[:1]
ginkgo.By(fmt.Sprintf("Creating SidecarSet %s", sidecarSetIn.Name))
sidecarSetIn, _ = tester.CreateSidecarSet(sidecarSetIn)
time.Sleep(time.Second)

// create deployment
deploymentIn := tester.NewBaseDeployment(ns)
deploymentIn.Spec.Replicas = utilpointer.Int32Ptr(2)
ginkgo.By(fmt.Sprintf("Creating Deployment(%s/%s)", deploymentIn.Namespace, deploymentIn.Name))
tester.CreateDeployment(deploymentIn)

sidecarSetIn, err := kc.AppsV1alpha1().SidecarSets().Get(context.TODO(), sidecarSetIn.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
//check pod sidecar upgrade spec annotations
pods, err := tester.GetSelectorPods(deploymentIn.Namespace, deploymentIn.Spec.Selector)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
for _, pod := range pods {
origin := sets.String{}
for _, sidecar := range sidecarSetIn.Spec.Containers {
origin.Insert(sidecar.Name)
}
// SidecarSetHashAnnotation = "kruise.io/sidecarset-hash"
upgradeSpec1 := sidecarcontrol.GetPodSidecarSetUpgradeSpecInAnnotations(sidecarSetIn.Name, sidecarcontrol.SidecarSetHashAnnotation, pod)
gomega.Expect(upgradeSpec1.SidecarSetName).To(gomega.Equal(sidecarSetIn.Name))
gomega.Expect(upgradeSpec1.SidecarSetHash).To(gomega.Equal(sidecarcontrol.GetSidecarSetRevision(sidecarSetIn)))
target1 := sets.NewString(upgradeSpec1.SidecarList...)
gomega.Expect(reflect.DeepEqual(origin.List(), target1.List())).To(gomega.Equal(true))
// SidecarSetHashWithoutImageAnnotation = "kruise.io/sidecarset-hash-without-image"
upgradeSpec2 := sidecarcontrol.GetPodSidecarSetUpgradeSpecInAnnotations(sidecarSetIn.Name, sidecarcontrol.SidecarSetHashWithoutImageAnnotation, pod)
gomega.Expect(upgradeSpec2.SidecarSetName).To(gomega.Equal(sidecarSetIn.Name))
gomega.Expect(upgradeSpec2.SidecarSetHash).To(gomega.Equal(sidecarcontrol.GetSidecarSetWithoutImageRevision(sidecarSetIn)))
target2 := sets.NewString(upgradeSpec2.SidecarList...)
gomega.Expect(reflect.DeepEqual(origin.List(), target2.List())).To(gomega.Equal(true))
}

// modify sidecarSet sidecar field out of image
sidecarSetIn.Spec.Containers[0].Command = []string{"sleep", "1000"}
tester.UpdateSidecarSet(sidecarSetIn)
except := &appsv1alpha1.SidecarSetStatus{
MatchedPods: 2,
UpdatedPods: 0,
UpdatedReadyPods: 0,
ReadyPods: 2,
}
tester.WaitForSidecarSetUpgradeComplete(sidecarSetIn, except)

// check all the pods' condition
pods, err = tester.GetSelectorPods(deploymentIn.Namespace, deploymentIn.Spec.Selector)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
for _, pod := range pods {
_, condition := podutil.GetPodCondition(&pod.Status, sidecarcontrol.SidecarSetUpgradable)
gomega.Expect(condition.Status).Should(gomega.Equal(corev1.ConditionFalse))
}

ginkgo.By(fmt.Sprintf("sidecarSet upgrade sidecar container (more than image field), no pod should be updated done"))
})

framework.ConformanceIt("sidecarSet upgrade cold sidecar container image, and paused", func() {
// create sidecarSet
sidecarSetIn := tester.NewBaseSidecarSet(ns)
Expand Down

0 comments on commit dd4faad

Please sign in to comment.