Skip to content

Commit

Permalink
Fix flaky Defer Phase tests (#1391)
Browse files Browse the repository at this point in the history
* Fix flaky controller tests

* Use kanister-tools image const in tests

* Revert TestKopiaCommand change
  • Loading branch information
pavannd1 committed Apr 20, 2022
1 parent a5f36d8 commit 6ee8981
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
2 changes: 2 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ const (
ProfileResourceName = "profile"
ProfileResourceNamePlural = "profiles"
)

const LatestKanisterToolsImage = "ghcr.io/kanisterio/kanister-tools:v9.99.9-dev"
17 changes: 9 additions & 8 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ type ControllerSuite struct {
var _ = Suite(&ControllerSuite{})

const (
testAction = "myAction"
mysqlSidecarImage = "ghcr.io/kanisterio/mysql-sidecar:0.74.0"
testAction = "myAction"
)

func (s *ControllerSuite) SetUpSuite(c *C) {
Expand Down Expand Up @@ -291,7 +290,7 @@ func phaseWithNameAndCMD(name string, command []string) *crv1alpha1.BlueprintPha
Name: name,
Func: function.KubeTaskFuncName,
Args: map[string]interface{}{
"image": mysqlSidecarImage,
"image": consts.LatestKanisterToolsImage,
"namespace": "default",
"command": command,
},
Expand Down Expand Up @@ -669,13 +668,14 @@ func (s *ControllerSuite) TestDeferPhase(c *C) {
c.Assert(err, IsNil)
err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning)
c.Assert(err, IsNil)
err = s.waitOnActionSetState(c, as, crv1alpha1.StateComplete)
c.Assert(err, IsNil)

// make sure deferPhase is also run successfully
err = s.waitOnDeferPhaseState(c, as, crv1alpha1.StateComplete)
c.Assert(err, IsNil)

err = s.waitOnActionSetState(c, as, crv1alpha1.StateComplete)
c.Assert(err, IsNil)

as, err = s.crCli.ActionSets(s.namespace).Get(ctx, as.Name, metav1.GetOptions{})
c.Assert(err, IsNil)

Expand Down Expand Up @@ -754,13 +754,14 @@ func (s *ControllerSuite) TestDeferPhaseDeferErr(c *C) {

err = s.waitOnActionSetState(c, as, crv1alpha1.StateRunning)
c.Assert(err, IsNil)
err = s.waitOnActionSetState(c, as, crv1alpha1.StateFailed)
c.Assert(err, IsNil)

// wait for deferPhase to be completed, because actionset status would be set to failed as soon as a main phase fails
// wait for deferPhase to fail
err = s.waitOnDeferPhaseState(c, as, crv1alpha1.StateFailed)
c.Assert(err, IsNil)

err = s.waitOnActionSetState(c, as, crv1alpha1.StateFailed)
c.Assert(err, IsNil)

// get the actionset again to have updated status
as, err = s.crCli.ActionSets(s.namespace).Get(ctx, as.Name, metav1.GetOptions{})
c.Assert(err, IsNil)
Expand Down
3 changes: 2 additions & 1 deletion pkg/function/kube_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/param"
)
Expand Down Expand Up @@ -66,7 +67,7 @@ func outputPhase(namespace string) crv1alpha1.BlueprintPhase {
Func: KubeTaskFuncName,
Args: map[string]interface{}{
KubeTaskNamespaceArg: namespace,
KubeTaskImageArg: "ghcr.io/kanisterio/kanister-tools:0.20.0",
KubeTaskImageArg: consts.LatestKanisterToolsImage,
KubeTaskCommandArg: []string{
"sh",
"-c",
Expand Down
25 changes: 12 additions & 13 deletions pkg/kube/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ type PodSuite struct {
}

const (
testSAName = "test-sa"
controllerSA = "controller-sa"
kanisterToolsImage = "ghcr.io/kanisterio/kanister-tools:v9.99.9-dev"
testSAName = "test-sa"
controllerSA = "controller-sa"
)

var _ = Suite(&PodSuite{})
Expand Down Expand Up @@ -94,36 +93,36 @@ func (s *PodSuite) TestPod(c *C) {
{
Namespace: s.namespace,
GenerateName: "test-",
Image: kanisterToolsImage,
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "tail -f /dev/null"},
},
{
Namespace: s.namespace,
GenerateName: "test-",
Image: kanisterToolsImage,
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "tail -f /dev/null"},
ServiceAccountName: testSAName,
RestartPolicy: v1.RestartPolicyAlways,
},
{
Namespace: cns,
GenerateName: "test-",
Image: kanisterToolsImage,
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "tail -f /dev/null"},
RestartPolicy: v1.RestartPolicyOnFailure,
},
{
Namespace: cns,
GenerateName: "test-",
Image: kanisterToolsImage,
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "tail -f /dev/null"},
ServiceAccountName: testSAName,
RestartPolicy: v1.RestartPolicyNever,
},
{
Namespace: s.namespace,
GenerateName: "test-",
Image: kanisterToolsImage,
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "tail -f /dev/null"},
Annotations: map[string]string{
"test-annotation": "true",
Expand All @@ -132,7 +131,7 @@ func (s *PodSuite) TestPod(c *C) {
{
Namespace: s.namespace,
GenerateName: "test-",
Image: kanisterToolsImage,
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "tail -f /dev/null"},
Labels: map[string]string{
"run": "pod",
Expand All @@ -141,7 +140,7 @@ func (s *PodSuite) TestPod(c *C) {
{
Namespace: s.namespace,
GenerateName: "test-",
Image: kanisterToolsImage,
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "tail -f /dev/null"},
Resources: v1.ResourceRequirements{
Limits: v1.ResourceList{
Expand All @@ -157,7 +156,7 @@ func (s *PodSuite) TestPod(c *C) {
{
Namespace: s.namespace,
GenerateName: "test-",
Image: kanisterToolsImage,
Image: consts.LatestKanisterToolsImage,
ContainerName: "test-container",
Command: []string{"sh", "-c", "tail -f /dev/null"},
Labels: map[string]string{
Expand Down Expand Up @@ -269,7 +268,7 @@ func (s *PodSuite) TestPodWithVolumes(c *C) {
pod, err := CreatePod(ctx, cli, &PodOptions{
Namespace: s.namespace,
GenerateName: "test-",
Image: "ghcr.io/kanisterio/kanister-tools:v9.99.9-dev",
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "tail -f /dev/null"},
Volumes: vols,
})
Expand All @@ -286,7 +285,7 @@ func (s *PodSuite) TestGetPodLogs(c *C) {
pod, err := CreatePod(context.Background(), s.cli, &PodOptions{
Namespace: s.namespace,
GenerateName: "test-",
Image: "ghcr.io/kanisterio/kanister-tools:latest",
Image: consts.LatestKanisterToolsImage,
Command: []string{"sh", "-c", "echo hello"},
})
c.Assert(err, IsNil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func newTestPodTemplateSpec() v1.PodTemplateSpec {
Containers: []v1.Container{
v1.Container{
Name: "test-container",
Image: "ghcr.io/kanisterio/kanister-tools:v9.99.9-dev",
Image: consts.LatestKanisterToolsImage,
Command: []string{"tail"},
Args: []string{"-f", "/dev/null"},
},
Expand Down

0 comments on commit 6ee8981

Please sign in to comment.