mirror of
https://github.com/jenkinsci/kubernetes-operator.git
synced 2026-10-18 14:01:04 +02:00
Use v1alpha2 Jenkins schema
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
|
||||
@@ -30,10 +30,10 @@ func TestConfiguration(t *testing.T) {
|
||||
systemMessage := "Configuration as Code integration works!!!"
|
||||
systemMessageEnvName := "SYSTEM_MESSAGE"
|
||||
mySeedJob := seedJobConfig{
|
||||
SeedJob: v1alpha1.SeedJob{
|
||||
SeedJob: v1alpha2.SeedJob{
|
||||
ID: "jenkins-operator",
|
||||
CredentialID: "jenkins-operator",
|
||||
JenkinsCredentialType: v1alpha1.NoJenkinsCredentialCredentialType,
|
||||
JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
|
||||
Targets: "cicd/jobs/*.jenkins",
|
||||
Description: "Jenkins Operator repository",
|
||||
RepositoryBranch: "master",
|
||||
@@ -64,7 +64,7 @@ func TestConfiguration(t *testing.T) {
|
||||
// base
|
||||
createUserConfigurationSecret(t, jenkinsCRName, namespace, systemMessageEnvName, systemMessage)
|
||||
createUserConfigurationConfigMap(t, jenkinsCRName, namespace, numberOfExecutors, fmt.Sprintf("${%s}", systemMessageEnvName))
|
||||
jenkins := createJenkinsCR(t, jenkinsCRName, namespace, &[]v1alpha1.SeedJob{mySeedJob.SeedJob}, volumes)
|
||||
jenkins := createJenkinsCR(t, jenkinsCRName, namespace, &[]v1alpha2.SeedJob{mySeedJob.SeedJob}, volumes)
|
||||
createDefaultLimitsForContainersInNamespace(t, namespace)
|
||||
createKubernetesCredentialsProviderSecret(t, namespace, mySeedJob)
|
||||
waitForJenkinsBaseConfigurationToComplete(t, jenkins)
|
||||
@@ -153,7 +153,7 @@ func createDefaultLimitsForContainersInNamespace(t *testing.T, namespace string)
|
||||
}
|
||||
}
|
||||
|
||||
func verifyJenkinsMasterPodAttributes(t *testing.T, jenkins *v1alpha1.Jenkins) {
|
||||
func verifyJenkinsMasterPodAttributes(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||
jenkinsPod := getJenkinsMasterPod(t, jenkins)
|
||||
jenkins = getJenkins(t, jenkins.Namespace, jenkins.Name)
|
||||
|
||||
@@ -222,7 +222,7 @@ func verifyContainer(t *testing.T, expected corev1.Container, actual corev1.Cont
|
||||
}
|
||||
}
|
||||
|
||||
func verifyPlugins(t *testing.T, jenkinsClient jenkinsclient.Jenkins, jenkins *v1alpha1.Jenkins) {
|
||||
func verifyPlugins(t *testing.T, jenkinsClient jenkinsclient.Jenkins, jenkins *v1alpha2.Jenkins) {
|
||||
installedPlugins, err := jenkinsClient.GetPlugins(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
+14
-14
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
)
|
||||
|
||||
func getJenkins(t *testing.T, namespace, name string) *v1alpha1.Jenkins {
|
||||
jenkins := &v1alpha1.Jenkins{}
|
||||
func getJenkins(t *testing.T, namespace, name string) *v1alpha2.Jenkins {
|
||||
jenkins := &v1alpha2.Jenkins{}
|
||||
namespaceName := types.NamespacedName{Namespace: namespace, Name: name}
|
||||
if err := framework.Global.Client.Get(context.TODO(), namespaceName, jenkins); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -27,7 +27,7 @@ func getJenkins(t *testing.T, namespace, name string) *v1alpha1.Jenkins {
|
||||
return jenkins
|
||||
}
|
||||
|
||||
func getJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.Jenkins) *v1.Pod {
|
||||
func getJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) *v1.Pod {
|
||||
lo := metav1.ListOptions{
|
||||
LabelSelector: labels.SelectorFromSet(resources.BuildResourceLabels(jenkins)).String(),
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func getJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.Jenkins) *v1.Pod {
|
||||
return &podList.Items[0]
|
||||
}
|
||||
|
||||
func createJenkinsAPIClient(jenkins *v1alpha1.Jenkins) (jenkinsclient.Jenkins, error) {
|
||||
func createJenkinsAPIClient(jenkins *v1alpha2.Jenkins) (jenkinsclient.Jenkins, error) {
|
||||
adminSecret := &v1.Secret{}
|
||||
namespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: resources.GetOperatorCredentialsSecretName(jenkins)}
|
||||
if err := framework.Global.Client.Get(context.TODO(), namespaceName, adminSecret); err != nil {
|
||||
@@ -60,21 +60,21 @@ func createJenkinsAPIClient(jenkins *v1alpha1.Jenkins) (jenkinsclient.Jenkins, e
|
||||
)
|
||||
}
|
||||
|
||||
func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha1.SeedJob, volumes []corev1.Volume) *v1alpha1.Jenkins {
|
||||
var seedJobs []v1alpha1.SeedJob
|
||||
func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha2.SeedJob, volumes []corev1.Volume) *v1alpha2.Jenkins {
|
||||
var seedJobs []v1alpha2.SeedJob
|
||||
if seedJob != nil {
|
||||
seedJobs = append(seedJobs, *seedJob...)
|
||||
}
|
||||
|
||||
jenkins := &v1alpha1.Jenkins{
|
||||
jenkins := &v1alpha2.Jenkins{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
},
|
||||
Spec: v1alpha1.JenkinsSpec{
|
||||
Master: v1alpha1.JenkinsMaster{
|
||||
Spec: v1alpha2.JenkinsSpec{
|
||||
Master: v1alpha2.JenkinsMaster{
|
||||
Annotations: map[string]string{"test": "label"},
|
||||
Container: v1alpha1.Container{
|
||||
Container: v1alpha2.Container{
|
||||
Image: "jenkins/jenkins",
|
||||
Env: []v1.EnvVar{
|
||||
{
|
||||
@@ -107,7 +107,7 @@ func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha1.S
|
||||
FailureThreshold: int32(10),
|
||||
},
|
||||
},
|
||||
Containers: []v1alpha1.Container{
|
||||
Containers: []v1alpha2.Container{
|
||||
{
|
||||
Name: "envoyproxy",
|
||||
Image: "envoyproxy/envoy-alpine",
|
||||
@@ -132,7 +132,7 @@ func createJenkinsCR(t *testing.T, name, namespace string, seedJob *[]v1alpha1.S
|
||||
return jenkins
|
||||
}
|
||||
|
||||
func verifyJenkinsAPIConnection(t *testing.T, jenkins *v1alpha1.Jenkins) jenkinsclient.Jenkins {
|
||||
func verifyJenkinsAPIConnection(t *testing.T, jenkins *v1alpha2.Jenkins) jenkinsclient.Jenkins {
|
||||
client, err := createJenkinsAPIClient(jenkins)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -142,7 +142,7 @@ func verifyJenkinsAPIConnection(t *testing.T, jenkins *v1alpha1.Jenkins) jenkins
|
||||
return client
|
||||
}
|
||||
|
||||
func restartJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.Jenkins) {
|
||||
func restartJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||
t.Log("Restarting Jenkins master pod")
|
||||
jenkinsPod := getJenkinsMasterPod(t, jenkins)
|
||||
err := framework.Global.Client.Delete(context.TODO(), jenkinsPod)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
|
||||
|
||||
f "github.com/operator-framework/operator-sdk/pkg/test"
|
||||
@@ -35,10 +35,10 @@ func setupTest(t *testing.T) (string, *framework.TestCtx) {
|
||||
t.Fatalf("could not initialize cluster resources: %v", err)
|
||||
}
|
||||
|
||||
jenkinsServiceList := &v1alpha1.JenkinsList{
|
||||
jenkinsServiceList := &v1alpha2.JenkinsList{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: v1alpha1.Kind,
|
||||
APIVersion: v1alpha1.SchemeGroupVersion.String(),
|
||||
Kind: v1alpha2.Kind,
|
||||
APIVersion: v1alpha2.SchemeGroupVersion.String(),
|
||||
},
|
||||
}
|
||||
err = framework.AddToFrameworkScheme(apis.AddToScheme, jenkinsServiceList)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
|
||||
|
||||
@@ -86,8 +86,8 @@ func checkIfAuthorizationStrategyUnsecuredIsSet(t *testing.T, jenkinsClient jenk
|
||||
require.NoError(t, err, logs)
|
||||
}
|
||||
|
||||
func checkBaseConfigurationCompleteTimeIsNotSet(t *testing.T, jenkins *v1alpha1.Jenkins) {
|
||||
jenkinsStatus := &v1alpha1.Jenkins{}
|
||||
func checkBaseConfigurationCompleteTimeIsNotSet(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||
jenkinsStatus := &v1alpha2.Jenkins{}
|
||||
namespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: jenkins.Name}
|
||||
err := framework.Global.Client.Get(context.TODO(), namespaceName, jenkinsStatus)
|
||||
if err != nil {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/internal/try"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user/seedjobs"
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
type seedJobConfig struct {
|
||||
v1alpha1.SeedJob
|
||||
v1alpha2.SeedJob
|
||||
JobNames []string `json:"jobNames,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
@@ -44,7 +44,7 @@ func TestSeedJobs(t *testing.T) {
|
||||
defer ctx.Cleanup()
|
||||
|
||||
jenkinsCRName := "e2e"
|
||||
var seedJobs []v1alpha1.SeedJob
|
||||
var seedJobs []v1alpha2.SeedJob
|
||||
|
||||
// base
|
||||
for _, seedJobConfig := range seedJobsConfig.SeedJobs {
|
||||
@@ -79,7 +79,7 @@ func loadSeedJobsConfig(t *testing.T) seedJobsConfig {
|
||||
}
|
||||
|
||||
func createKubernetesCredentialsProviderSecret(t *testing.T, namespace string, config seedJobConfig) {
|
||||
if config.JenkinsCredentialType == v1alpha1.NoJenkinsCredentialCredentialType {
|
||||
if config.JenkinsCredentialType == v1alpha2.NoJenkinsCredentialCredentialType {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ func createKubernetesCredentialsProviderSecret(t *testing.T, namespace string, c
|
||||
func verifyJenkinsSeedJobs(t *testing.T, jenkinsClient jenkinsclient.Jenkins, seedJobs []seedJobConfig) {
|
||||
var err error
|
||||
for _, seedJob := range seedJobs {
|
||||
if seedJob.JenkinsCredentialType == v1alpha1.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha1.UsernamePasswordCredentialType {
|
||||
if seedJob.JenkinsCredentialType == v1alpha2.BasicSSHCredentialType || seedJob.JenkinsCredentialType == v1alpha2.UsernamePasswordCredentialType {
|
||||
err = verifyIfJenkinsCredentialExists(jenkinsClient, seedJob.CredentialID)
|
||||
assert.NoErrorf(t, err, "Jenkins credential '%s' not created for seed job ID '%s'", seedJob.CredentialID, seedJob.ID)
|
||||
}
|
||||
|
||||
+9
-9
@@ -7,7 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/internal/try"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha1"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
jenkinsclient "github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/client"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
|
||||
|
||||
@@ -27,11 +27,11 @@ var (
|
||||
)
|
||||
|
||||
// checkConditionFunc is used to check if a condition for the jenkins CR is set
|
||||
type checkConditionFunc func(*v1alpha1.Jenkins, error) bool
|
||||
type checkConditionFunc func(*v1alpha2.Jenkins, error) bool
|
||||
|
||||
func waitForJenkinsBaseConfigurationToComplete(t *testing.T, jenkins *v1alpha1.Jenkins) {
|
||||
func waitForJenkinsBaseConfigurationToComplete(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||
t.Log("Waiting for Jenkins base configuration to complete")
|
||||
_, err := WaitUntilJenkinsConditionSet(retryInterval, 150, jenkins, func(jenkins *v1alpha1.Jenkins, err error) bool {
|
||||
_, err := WaitUntilJenkinsConditionSet(retryInterval, 150, jenkins, func(jenkins *v1alpha2.Jenkins, err error) bool {
|
||||
t.Logf("Current Jenkins status: '%+v', error '%s'", jenkins.Status, err)
|
||||
return err == nil && jenkins.Status.BaseConfigurationCompletedTime != nil
|
||||
})
|
||||
@@ -44,7 +44,7 @@ func waitForJenkinsBaseConfigurationToComplete(t *testing.T, jenkins *v1alpha1.J
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func waitForRecreateJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.Jenkins) {
|
||||
func waitForRecreateJenkinsMasterPod(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||
err := wait.Poll(retryInterval, 30*retryInterval, func() (bool, error) {
|
||||
lo := metav1.ListOptions{
|
||||
LabelSelector: labels.SelectorFromSet(resources.BuildResourceLabels(jenkins)).String(),
|
||||
@@ -65,9 +65,9 @@ func waitForRecreateJenkinsMasterPod(t *testing.T, jenkins *v1alpha1.Jenkins) {
|
||||
t.Log("Jenkins pod has been recreated")
|
||||
}
|
||||
|
||||
func waitForJenkinsUserConfigurationToComplete(t *testing.T, jenkins *v1alpha1.Jenkins) {
|
||||
func waitForJenkinsUserConfigurationToComplete(t *testing.T, jenkins *v1alpha2.Jenkins) {
|
||||
t.Log("Waiting for Jenkins user configuration to complete")
|
||||
_, err := WaitUntilJenkinsConditionSet(retryInterval, 70, jenkins, func(jenkins *v1alpha1.Jenkins, err error) bool {
|
||||
_, err := WaitUntilJenkinsConditionSet(retryInterval, 70, jenkins, func(jenkins *v1alpha2.Jenkins, err error) bool {
|
||||
t.Logf("Current Jenkins status: '%+v', error '%s'", jenkins.Status, err)
|
||||
return err == nil && jenkins.Status.UserConfigurationCompletedTime != nil
|
||||
})
|
||||
@@ -92,8 +92,8 @@ func waitForJenkinsSafeRestart(t *testing.T, jenkinsClient jenkinsclient.Jenkins
|
||||
}
|
||||
|
||||
// WaitUntilJenkinsConditionSet retries until the specified condition check becomes true for the jenkins CR
|
||||
func WaitUntilJenkinsConditionSet(retryInterval time.Duration, retries int, jenkins *v1alpha1.Jenkins, checkCondition checkConditionFunc) (*v1alpha1.Jenkins, error) {
|
||||
jenkinsStatus := &v1alpha1.Jenkins{}
|
||||
func WaitUntilJenkinsConditionSet(retryInterval time.Duration, retries int, jenkins *v1alpha2.Jenkins, checkCondition checkConditionFunc) (*v1alpha2.Jenkins, error) {
|
||||
jenkinsStatus := &v1alpha2.Jenkins{}
|
||||
err := wait.Poll(retryInterval, time.Duration(retries)*retryInterval, func() (bool, error) {
|
||||
namespacedName := types.NamespacedName{Namespace: jenkins.Namespace, Name: jenkins.Name}
|
||||
err := framework.Global.Client.Get(goctx.TODO(), namespacedName, jenkinsStatus)
|
||||
|
||||
Reference in New Issue
Block a user