diff --git a/cicd/jobs/e2e.jenkins b/cicd/jobs/e2e.jenkins index e1cc35f3a..011b18475 100644 --- a/cicd/jobs/e2e.jenkins +++ b/cicd/jobs/e2e.jenkins @@ -1,7 +1,7 @@ #!/usr/bin/env groovy pipelineJob('e2e-jenkins-operator') { - displayName('Dummy job to e2e testing') + displayName('Dummy job for e2e testing') logRotator { numToKeep(10) diff --git a/pkg/controller/jenkins/configuration/base/resources/base_configuration_configmap.go b/pkg/controller/jenkins/configuration/base/resources/base_configuration_configmap.go index 258e57564..3aac343b5 100644 --- a/pkg/controller/jenkins/configuration/base/resources/base_configuration_configmap.go +++ b/pkg/controller/jenkins/configuration/base/resources/base_configuration_configmap.go @@ -15,12 +15,11 @@ import jenkins.model.JenkinsLocationConfiguration import hudson.model.Node.Mode def jenkins = Jenkins.instance -//Number of jobs that run simultaneously on master, currently only SeedJob. +//Number of jobs that run simultaneously on master. jenkins.setNumExecutors(%d) //Jobs must specify that they want to run on master jenkins.setMode(Mode.EXCLUSIVE) jenkins.save() - ` const enableCSRF = ` diff --git a/pkg/controller/jenkins/constants/constants.go b/pkg/controller/jenkins/constants/constants.go index 61efec9d2..373071a35 100644 --- a/pkg/controller/jenkins/constants/constants.go +++ b/pkg/controller/jenkins/constants/constants.go @@ -9,10 +9,6 @@ const ( SeedJobSuffix = "job-dsl-seed" // DefaultJenkinsMasterImage is the default Jenkins master docker image DefaultJenkinsMasterImage = "jenkins/jenkins:lts" - // UserConfigurationJobName is the Jenkins job name used to configure Jenkins by groovy scripts provided by user - UserConfigurationJobName = OperatorName + "-user-configuration" - // UserConfigurationCASCJobName is the Jenkins job name used to configure Jenkins by Configuration as code yaml configs provided by user - UserConfigurationCASCJobName = OperatorName + "-user-configuration-casc" // DefaultHTTPPortInt32 is the default Jenkins HTTP port DefaultHTTPPortInt32 = int32(8080) // DefaultSlavePortInt32 is the default Jenkins port for slaves diff --git a/test/e2e/restart_test.go b/test/e2e/restart_test.go index fab56c468..47d9445a0 100644 --- a/test/e2e/restart_test.go +++ b/test/e2e/restart_test.go @@ -28,6 +28,7 @@ func TestJenkinsMasterPodRestart(t *testing.T) { waitForJenkinsBaseConfigurationToComplete(t, jenkins) } +// FIXME java.lang.Exception: AuthorizationStrategy.Unsecured is not set func TestSafeRestart(t *testing.T) { t.Parallel() namespace, ctx := setupTest(t) diff --git a/test/e2e/restorebackup_test.go b/test/e2e/restorebackup_test.go index c4c3183be..475e32925 100644 --- a/test/e2e/restorebackup_test.go +++ b/test/e2e/restorebackup_test.go @@ -3,12 +3,12 @@ package e2e import ( "context" "testing" + "time" + "github.com/jenkinsci/kubernetes-operator/internal/try" "github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client" "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources" - "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants" - framework "github.com/operator-framework/operator-sdk/pkg/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -25,28 +25,41 @@ func TestBackupAndRestore(t *testing.T) { // Deletes test namespace defer ctx.Cleanup() + jobID := "e2e-jenkins-operator" createPVC(t, namespace) jenkins := createJenkinsWithBackupAndRestoreConfigured(t, "e2e", namespace) waitForJenkinsUserConfigurationToComplete(t, jenkins) + + jenkinsClient := verifyJenkinsAPIConnection(t, jenkins) + waitForJob(t, jenkinsClient, jobID) + job, err := jenkinsClient.GetJob(jobID) + require.NoError(t, err, job) + i, err := job.InvokeSimple(map[string]string{}) + require.NoError(t, err, i) + time.Sleep(60 * time.Second) // wait for the build to complete + restartJenkinsMasterPod(t, jenkins) waitForRecreateJenkinsMasterPod(t, jenkins) waitForJenkinsUserConfigurationToComplete(t, jenkins) - jenkinsClient := verifyJenkinsAPIConnection(t, jenkins) - verifyJobBuildsAfterRestoreBackup(t, jenkinsClient) + jenkinsClient = verifyJenkinsAPIConnection(t, jenkins) + waitForJob(t, jenkinsClient, jobID) + verifyJobBuildsAfterRestoreBackup(t, jenkinsClient, jobID) } -func verifyJobBuildsAfterRestoreBackup(t *testing.T, jenkins client.Jenkins) { - job, err := jenkins.GetJob(constants.UserConfigurationJobName) - require.NoError(t, err) - build, err := job.GetLastBuild() - require.NoError(t, err) - assert.Equal(t, int64(2), build.GetBuildNumber()) +func waitForJob(t *testing.T, jenkinsClient client.Jenkins, jobID string) { + err := try.Until(func() (end bool, err error) { + _, err = jenkinsClient.GetJob(jobID) + return err == nil, err + }, time.Second*2, time.Minute*2) + require.NoErrorf(t, err, "Jenkins job '%s' not created by seed job", jobID) +} - job, err = jenkins.GetJob(constants.UserConfigurationCASCJobName) +func verifyJobBuildsAfterRestoreBackup(t *testing.T, jenkinsClient client.Jenkins, jobID string) { + job, err := jenkinsClient.GetJob(jobID) require.NoError(t, err) - build, err = job.GetLastBuild() + build, err := job.GetLastBuild() require.NoError(t, err) - assert.Equal(t, int64(2), build.GetBuildNumber()) + assert.Equal(t, int64(1), build.GetBuildNumber()) } func createPVC(t *testing.T, namespace string) { @@ -136,6 +149,17 @@ func createJenkinsWithBackupAndRestoreConfigured(t *testing.T, name, namespace s }, }, }, + SeedJobs: []v1alpha2.SeedJob{ + { + ID: "jenkins-operator", + CredentialID: "jenkins-operator", + JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType, + Targets: "cicd/jobs/*.jenkins", + Description: "Jenkins Operator repository", + RepositoryBranch: "master", + RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git", + }, + }, }, }