Add JenkinsMasterPodRestart e2e test
This commit is contained in:
parent
54aa39c502
commit
38165487ca
|
|
@ -1,17 +1,12 @@
|
||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
virtuslabv1alpha1 "github.com/VirtusLab/jenkins-operator/pkg/apis/virtuslab/v1alpha1"
|
virtuslabv1alpha1 "github.com/VirtusLab/jenkins-operator/pkg/apis/virtuslab/v1alpha1"
|
||||||
|
|
||||||
"github.com/bndr/gojenkins"
|
"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) {
|
func TestBaseConfiguration(t *testing.T) {
|
||||||
|
|
@ -20,33 +15,7 @@ func TestBaseConfiguration(t *testing.T) {
|
||||||
// Deletes test namespace
|
// Deletes test namespace
|
||||||
defer ctx.Cleanup()
|
defer ctx.Cleanup()
|
||||||
|
|
||||||
jenkins := &virtuslabv1alpha1.Jenkins{
|
jenkins := createJenkinsCR(t, namespace)
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
waitForJenkinsBaseConfigurationToComplete(t, jenkins)
|
waitForJenkinsBaseConfigurationToComplete(t, jenkins)
|
||||||
|
|
||||||
verifyJenkinsMasterPodAttributes(t, jenkins)
|
verifyJenkinsMasterPodAttributes(t, jenkins)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import (
|
||||||
"github.com/bndr/gojenkins"
|
"github.com/bndr/gojenkins"
|
||||||
framework "github.com/operator-framework/operator-sdk/pkg/test"
|
framework "github.com/operator-framework/operator-sdk/pkg/test"
|
||||||
"k8s.io/api/core/v1"
|
"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"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
@ -63,3 +65,35 @@ func createJenkinsAPIClient(jenkins *virtuslabv1alpha1.Jenkins) (*gojenkins.Jenk
|
||||||
|
|
||||||
return jenkinsClient, nil
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue