diff --git a/test/e2e/base_configuration_test.go b/test/e2e/base_configuration_test.go index e8e64143..fd77a488 100644 --- a/test/e2e/base_configuration_test.go +++ b/test/e2e/base_configuration_test.go @@ -1,17 +1,12 @@ package e2e import ( - "context" "reflect" "testing" virtuslabv1alpha1 "github.com/VirtusLab/jenkins-operator/pkg/apis/virtuslab/v1alpha1" "github.com/bndr/gojenkins" - framework "github.com/operator-framework/operator-sdk/pkg/test" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestBaseConfiguration(t *testing.T) { @@ -20,33 +15,7 @@ func TestBaseConfiguration(t *testing.T) { // Deletes test namespace defer ctx.Cleanup() - jenkins := &virtuslabv1alpha1.Jenkins{ - ObjectMeta: metav1.ObjectMeta{ - Name: "e2e", - Namespace: namespace, - }, - Spec: virtuslabv1alpha1.JenkinsSpec{ - Master: virtuslabv1alpha1.JenkinsMaster{ - Image: "jenkins/jenkins", - Annotations: map[string]string{"test": "label"}, - Resources: corev1.ResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("1"), - corev1.ResourceMemory: resource.MustParse("1Gi"), - }, - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse("2"), - corev1.ResourceMemory: resource.MustParse("2Gi"), - }, - }, - }, - }, - } - t.Logf("Jenkins CR %+v", *jenkins) - if err := framework.Global.Client.Create(context.TODO(), jenkins, nil); err != nil { - t.Fatal(err) - } - + jenkins := createJenkinsCR(t, namespace) waitForJenkinsBaseConfigurationToComplete(t, jenkins) verifyJenkinsMasterPodAttributes(t, jenkins) diff --git a/test/e2e/jenkins.go b/test/e2e/jenkins.go index 2cdc0fe8..68f4f6f4 100644 --- a/test/e2e/jenkins.go +++ b/test/e2e/jenkins.go @@ -13,6 +13,8 @@ import ( "github.com/bndr/gojenkins" framework "github.com/operator-framework/operator-sdk/pkg/test" "k8s.io/api/core/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" @@ -63,3 +65,35 @@ func createJenkinsAPIClient(jenkins *virtuslabv1alpha1.Jenkins) (*gojenkins.Jenk return jenkinsClient, nil } + +func createJenkinsCR(t *testing.T, namespace string) *virtuslabv1alpha1.Jenkins { + jenkins := &virtuslabv1alpha1.Jenkins{ + ObjectMeta: metav1.ObjectMeta{ + Name: "e2e", + Namespace: namespace, + }, + Spec: virtuslabv1alpha1.JenkinsSpec{ + Master: virtuslabv1alpha1.JenkinsMaster{ + Image: "jenkins/jenkins", + Annotations: map[string]string{"test": "label"}, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("1"), + corev1.ResourceMemory: resource.MustParse("1Gi"), + }, + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("2"), + corev1.ResourceMemory: resource.MustParse("2Gi"), + }, + }, + }, + }, + } + + t.Logf("Jenkins CR %+v", *jenkins) + if err := framework.Global.Client.Create(context.TODO(), jenkins, nil); err != nil { + t.Fatal(err) + } + + return jenkins +} diff --git a/test/e2e/restart_pod_test.go b/test/e2e/restart_pod_test.go new file mode 100644 index 00000000..ed10a7e2 --- /dev/null +++ b/test/e2e/restart_pod_test.go @@ -0,0 +1,46 @@ +package e2e + +import ( + "context" + "testing" + "time" + + virtuslabv1alpha1 "github.com/VirtusLab/jenkins-operator/pkg/apis/virtuslab/v1alpha1" + + framework "github.com/operator-framework/operator-sdk/pkg/test" + "k8s.io/apimachinery/pkg/types" +) + +func TestJenkinsMasterPodRestart(t *testing.T) { + t.Parallel() + namespace, ctx := setupTest(t) + // Deletes test namespace + defer ctx.Cleanup() + + jenkins := createJenkinsCR(t, namespace) + waitForJenkinsBaseConfigurationToComplete(t, jenkins) + restartJenkinsMasterPod(t, jenkins) + time.Sleep(33 * time.Second) // wait for recreate pod + checkBaseConfigurationCompleteTimeIsNotSet(t, jenkins) + waitForJenkinsBaseConfigurationToComplete(t, jenkins) +} + +func checkBaseConfigurationCompleteTimeIsNotSet(t *testing.T, jenkins *virtuslabv1alpha1.Jenkins) { + jenkinsStatus := &virtuslabv1alpha1.Jenkins{} + namespacedName := types.NamespacedName{Namespace: jenkins.Namespace, Name: jenkins.Name} + err := framework.Global.Client.Get(context.TODO(), namespacedName, jenkinsStatus) + if err != nil { + t.Fatal(err) + } + if jenkinsStatus.Status.BaseConfigurationCompletedTime != nil { + t.Fatalf("Status.BaseConfigurationCompletedTime is set after restart of pod, status %+v", jenkinsStatus.Status) + } +} + +func restartJenkinsMasterPod(t *testing.T, jenkins *virtuslabv1alpha1.Jenkins) { + jenkinsPod := getJenkinsMasterPod(t, jenkins) + err := framework.Global.Client.Delete(context.TODO(), jenkinsPod) + if err != nil { + t.Fatal(err) + } +}