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