Pass Configuration struct to Base and User constructors
This commit is contained in:
parent
c95108e3ac
commit
c249288a2d
|
|
@ -29,7 +29,6 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
|
@ -49,21 +48,14 @@ type ReconcileJenkinsBaseConfiguration struct {
|
|||
}
|
||||
|
||||
// New create structure which takes care of base configuration
|
||||
func New(client client.Client, scheme *runtime.Scheme, logger logr.Logger,
|
||||
jenkins *v1alpha2.Jenkins, local, minikube bool, clientSet kubernetes.Clientset, config *rest.Config,
|
||||
notificationEvents *chan notifications.Event) *ReconcileJenkinsBaseConfiguration {
|
||||
func New(config configuration.Configuration, scheme *runtime.Scheme, logger logr.Logger, local, minikube bool, restConfig *rest.Config) *ReconcileJenkinsBaseConfiguration {
|
||||
return &ReconcileJenkinsBaseConfiguration{
|
||||
Configuration: configuration.Configuration{
|
||||
Client: client,
|
||||
ClientSet: clientSet,
|
||||
Notifications: notificationEvents,
|
||||
Jenkins: jenkins,
|
||||
},
|
||||
scheme: scheme,
|
||||
logger: logger,
|
||||
local: local,
|
||||
minikube: minikube,
|
||||
config: config,
|
||||
Configuration: config,
|
||||
scheme: scheme,
|
||||
logger: logger,
|
||||
local: local,
|
||||
minikube: minikube,
|
||||
config: restConfig,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -462,6 +454,9 @@ func (r *ReconcileJenkinsBaseConfiguration) ensureJenkinsMasterPod(meta metav1.O
|
|||
|
||||
messages := r.isRecreatePodNeeded(*currentJenkinsMasterPod, userAndPasswordHash)
|
||||
if hasMessages := len(messages) > 0; hasMessages {
|
||||
for _, msg := range messages {
|
||||
r.logger.Info(msg)
|
||||
}
|
||||
return reconcile.Result{Requeue: true}, r.Configuration.RestartJenkinsMasterPod()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
func TestGetJenkinsOpts(t *testing.T) {
|
||||
|
|
@ -235,7 +234,7 @@ func TestCompareVolumes(t *testing.T) {
|
|||
Volumes: resources.GetJenkinsMasterPodBaseVolumes(jenkins),
|
||||
},
|
||||
}
|
||||
reconciler := New(nil, nil, nil, jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
reconciler := New(configuration.Configuration{Jenkins: jenkins}, nil, nil, false, false, nil)
|
||||
|
||||
got := reconciler.compareVolumes(pod)
|
||||
|
||||
|
|
@ -259,7 +258,7 @@ func TestCompareVolumes(t *testing.T) {
|
|||
Volumes: resources.GetJenkinsMasterPodBaseVolumes(jenkins),
|
||||
},
|
||||
}
|
||||
reconciler := New(nil, nil, nil, jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
reconciler := New(configuration.Configuration{Jenkins: jenkins}, nil, nil, false, false, nil)
|
||||
|
||||
got := reconciler.compareVolumes(pod)
|
||||
|
||||
|
|
@ -283,7 +282,7 @@ func TestCompareVolumes(t *testing.T) {
|
|||
Volumes: append(resources.GetJenkinsMasterPodBaseVolumes(jenkins), corev1.Volume{Name: "added"}),
|
||||
},
|
||||
}
|
||||
reconciler := New(nil, nil, nil, jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
reconciler := New(configuration.Configuration{Jenkins: jenkins}, nil, nil, false, false, nil)
|
||||
|
||||
got := reconciler.compareVolumes(pod)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ package base
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/base/resources"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/constants"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/plugins"
|
||||
|
|
@ -15,15 +17,13 @@ import (
|
|||
"k8s.io/api/core/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
|
||||
)
|
||||
|
||||
func TestValidatePlugins(t *testing.T) {
|
||||
log.SetupLogger(true)
|
||||
baseReconcileLoop := New(nil, nil, log.Log,
|
||||
nil, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{}, nil, log.Log, false, false, nil)
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
var requiredBasePlugins []plugins.Plugin
|
||||
var basePlugins []v1alpha2.Plugin
|
||||
|
|
@ -163,10 +163,13 @@ func TestReconcileJenkinsBaseConfiguration_validateImagePullSecrets(t *testing.T
|
|||
err := fakeClient.Create(context.TODO(), secret)
|
||||
assert.NoError(t, err)
|
||||
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, err := baseReconcileLoop.validateImagePullSecrets()
|
||||
fmt.Println(got)
|
||||
assert.Nil(t, got)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
|
@ -184,8 +187,10 @@ func TestReconcileJenkinsBaseConfiguration_validateImagePullSecrets(t *testing.T
|
|||
|
||||
fakeClient := fake.NewFakeClient()
|
||||
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: &jenkins,
|
||||
}, nil, nil, false, false, nil)
|
||||
|
||||
got, _ := baseReconcileLoop.validateImagePullSecrets()
|
||||
|
||||
|
|
@ -218,8 +223,10 @@ func TestReconcileJenkinsBaseConfiguration_validateImagePullSecrets(t *testing.T
|
|||
err := fakeClient.Create(context.TODO(), secret)
|
||||
assert.NoError(t, err)
|
||||
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: &jenkins,
|
||||
}, nil, nil, false, false, nil)
|
||||
|
||||
got, _ := baseReconcileLoop.validateImagePullSecrets()
|
||||
|
||||
|
|
@ -252,8 +259,10 @@ func TestReconcileJenkinsBaseConfiguration_validateImagePullSecrets(t *testing.T
|
|||
err := fakeClient.Create(context.TODO(), secret)
|
||||
assert.NoError(t, err)
|
||||
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, _ := baseReconcileLoop.validateImagePullSecrets()
|
||||
|
||||
|
|
@ -286,8 +295,10 @@ func TestReconcileJenkinsBaseConfiguration_validateImagePullSecrets(t *testing.T
|
|||
err := fakeClient.Create(context.TODO(), secret)
|
||||
assert.NoError(t, err)
|
||||
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, _ := baseReconcileLoop.validateImagePullSecrets()
|
||||
|
||||
|
|
@ -320,8 +331,10 @@ func TestReconcileJenkinsBaseConfiguration_validateImagePullSecrets(t *testing.T
|
|||
err := fakeClient.Create(context.TODO(), secret)
|
||||
assert.NoError(t, err)
|
||||
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, _ := baseReconcileLoop.validateImagePullSecrets()
|
||||
|
||||
|
|
@ -352,8 +365,9 @@ func TestValidateJenkinsMasterPodEnvs(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateJenkinsMasterPodEnvs()
|
||||
assert.Nil(t, got)
|
||||
})
|
||||
|
|
@ -378,8 +392,9 @@ func TestValidateJenkinsMasterPodEnvs(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateJenkinsMasterPodEnvs()
|
||||
|
||||
assert.Equal(t, got, []string{"Jenkins Master container env 'JENKINS_HOME' cannot be overridden"})
|
||||
|
|
@ -401,8 +416,9 @@ func TestValidateJenkinsMasterPodEnvs(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateJenkinsMasterPodEnvs()
|
||||
|
||||
assert.Equal(t, got, []string{"Jenkins Master container env 'JAVA_OPTS' doesn't have required flag '-Djava.awt.headless=true'"})
|
||||
|
|
@ -424,8 +440,9 @@ func TestValidateJenkinsMasterPodEnvs(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateJenkinsMasterPodEnvs()
|
||||
|
||||
assert.Equal(t, got, []string{"Jenkins Master container env 'JAVA_OPTS' doesn't have required flag '-Djenkins.install.runSetupWizard=false'"})
|
||||
|
|
@ -445,8 +462,9 @@ func TestValidateReservedVolumes(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateReservedVolumes()
|
||||
assert.Nil(t, got)
|
||||
})
|
||||
|
|
@ -462,8 +480,9 @@ func TestValidateReservedVolumes(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateReservedVolumes()
|
||||
|
||||
assert.Equal(t, got, []string{"Jenkins Master pod volume 'jenkins-home' is reserved please choose different one"})
|
||||
|
|
@ -477,8 +496,9 @@ func TestValidateContainerVolumeMounts(t *testing.T) {
|
|||
Master: v1alpha2.JenkinsMaster{},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateContainerVolumeMounts(v1alpha2.Container{})
|
||||
assert.Nil(t, got)
|
||||
})
|
||||
|
|
@ -504,8 +524,9 @@ func TestValidateContainerVolumeMounts(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateContainerVolumeMounts(jenkins.Spec.Master.Containers[0])
|
||||
assert.Nil(t, got)
|
||||
})
|
||||
|
|
@ -531,8 +552,9 @@ func TestValidateContainerVolumeMounts(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateContainerVolumeMounts(jenkins.Spec.Master.Containers[0])
|
||||
assert.Equal(t, got, []string{"mountPath not set for 'example' volume mount in container ''"})
|
||||
})
|
||||
|
|
@ -553,8 +575,9 @@ func TestValidateContainerVolumeMounts(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseReconcileLoop := New(nil, nil, logf.ZapLogger(false),
|
||||
&jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: &jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got := baseReconcileLoop.validateContainerVolumeMounts(jenkins.Spec.Master.Containers[0])
|
||||
|
||||
assert.Equal(t, got, []string{"Not found volume for 'missing-volume' volume mount in container ''"})
|
||||
|
|
@ -574,8 +597,9 @@ func TestValidateConfigMapVolume(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fakeClient := fake.NewFakeClient()
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
nil, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, err := baseReconcileLoop.validateConfigMapVolume(volume)
|
||||
|
||||
|
|
@ -600,8 +624,10 @@ func TestValidateConfigMapVolume(t *testing.T) {
|
|||
fakeClient := fake.NewFakeClient()
|
||||
err := fakeClient.Create(context.TODO(), &configMap)
|
||||
assert.NoError(t, err)
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, err := baseReconcileLoop.validateConfigMapVolume(volume)
|
||||
|
||||
|
|
@ -624,8 +650,10 @@ func TestValidateConfigMapVolume(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fakeClient := fake.NewFakeClient()
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, err := baseReconcileLoop.validateConfigMapVolume(volume)
|
||||
|
||||
|
|
@ -648,8 +676,9 @@ func TestValidateSecretVolume(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fakeClient := fake.NewFakeClient()
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
nil, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, err := baseReconcileLoop.validateSecretVolume(volume)
|
||||
|
||||
|
|
@ -672,8 +701,10 @@ func TestValidateSecretVolume(t *testing.T) {
|
|||
fakeClient := fake.NewFakeClient()
|
||||
err := fakeClient.Create(context.TODO(), &secret)
|
||||
assert.NoError(t, err)
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, err := baseReconcileLoop.validateSecretVolume(volume)
|
||||
|
||||
|
|
@ -694,8 +725,10 @@ func TestValidateSecretVolume(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fakeClient := fake.NewFakeClient()
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
Jenkins: jenkins,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
got, err := baseReconcileLoop.validateSecretVolume(volume)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -716,8 +749,10 @@ func TestValidateCustomization(t *testing.T) {
|
|||
t.Run("empty", func(t *testing.T) {
|
||||
customization := v1alpha2.Customization{}
|
||||
fakeClient := fake.NewFakeClient()
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: jenkins,
|
||||
Client: fakeClient,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
|
||||
got, err := baseReconcileLoop.validateCustomization(customization, "spec.groovyScripts")
|
||||
|
||||
|
|
@ -736,8 +771,10 @@ func TestValidateCustomization(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fakeClient := fake.NewFakeClient()
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: jenkins,
|
||||
Client: fakeClient,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
err := fakeClient.Create(context.TODO(), secret)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -765,8 +802,10 @@ func TestValidateCustomization(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fakeClient := fake.NewFakeClient()
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: jenkins,
|
||||
Client: fakeClient,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
err := fakeClient.Create(context.TODO(), secret)
|
||||
require.NoError(t, err)
|
||||
err = fakeClient.Create(context.TODO(), configMap)
|
||||
|
|
@ -790,8 +829,10 @@ func TestValidateCustomization(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fakeClient := fake.NewFakeClient()
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: jenkins,
|
||||
Client: fakeClient,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
err := fakeClient.Create(context.TODO(), configMap)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -813,8 +854,10 @@ func TestValidateCustomization(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fakeClient := fake.NewFakeClient()
|
||||
baseReconcileLoop := New(fakeClient, nil, logf.ZapLogger(false),
|
||||
jenkins, false, false, kubernetes.Clientset{}, nil, nil)
|
||||
baseReconcileLoop := New(configuration.Configuration{
|
||||
Jenkins: jenkins,
|
||||
Client: fakeClient,
|
||||
}, nil, logf.ZapLogger(false), false, false, nil)
|
||||
err := fakeClient.Create(context.TODO(), secret)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package user
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"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"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/backuprestore"
|
||||
|
|
@ -11,12 +11,9 @@ import (
|
|||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user/casc"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration/user/seedjobs"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/groovy"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/notifications"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
)
|
||||
|
||||
|
|
@ -29,15 +26,9 @@ type ReconcileUserConfiguration struct {
|
|||
}
|
||||
|
||||
// New create structure which takes care of user configuration
|
||||
func New(client client.Client, jenkinsClient jenkinsclient.Jenkins, logger logr.Logger,
|
||||
jenkins *v1alpha2.Jenkins, clientSet kubernetes.Clientset, config rest.Config, notificationEvents *chan notifications.Event) *ReconcileUserConfiguration {
|
||||
func New(configuration configuration.Configuration, jenkinsClient jenkinsclient.Jenkins, logger logr.Logger, config rest.Config) *ReconcileUserConfiguration {
|
||||
return &ReconcileUserConfiguration{
|
||||
Configuration: configuration.Configuration{
|
||||
Client: client,
|
||||
ClientSet: clientSet,
|
||||
Notifications: notificationEvents,
|
||||
Jenkins: jenkins,
|
||||
},
|
||||
Configuration: configuration,
|
||||
jenkinsClient: jenkinsClient,
|
||||
logger: logger,
|
||||
config: config,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package jenkins
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/controller/jenkins/configuration"
|
||||
"reflect"
|
||||
|
||||
"github.com/jenkinsci/kubernetes-operator/pkg/apis/jenkins/v1alpha2"
|
||||
|
|
@ -202,7 +203,12 @@ func (r *ReconcileJenkins) reconcile(request reconcile.Request, logger logr.Logg
|
|||
return reconcile.Result{}, jenkins, err
|
||||
}
|
||||
// Reconcile base configuration
|
||||
baseConfiguration := base.New(r.client, r.scheme, logger, jenkins, r.local, r.minikube, r.clientSet, &r.config, r.notificationEvents)
|
||||
baseConfiguration := base.New(configuration.Configuration{
|
||||
Client: r.client,
|
||||
ClientSet: r.clientSet,
|
||||
Notifications: r.notificationEvents,
|
||||
Jenkins: jenkins,
|
||||
}, r.scheme, logger, r.local, r.minikube, &r.config)
|
||||
|
||||
messages, err := baseConfiguration.Validate(jenkins)
|
||||
if err != nil {
|
||||
|
|
@ -255,7 +261,12 @@ func (r *ReconcileJenkins) reconcile(request reconcile.Request, logger logr.Logg
|
|||
logger.Info(message)
|
||||
}
|
||||
// Reconcile user configuration
|
||||
userConfiguration := user.New(r.client, jenkinsClient, logger, jenkins, r.clientSet, r.config, r.notificationEvents)
|
||||
userConfiguration := user.New(configuration.Configuration{
|
||||
Client: r.client,
|
||||
ClientSet: r.clientSet,
|
||||
Notifications: r.notificationEvents,
|
||||
Jenkins: jenkins,
|
||||
}, jenkinsClient, logger, r.config)
|
||||
|
||||
messages, err = userConfiguration.Validate(jenkins)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue