mirror of
https://github.com/jenkinsci/kubernetes-operator.git
synced 2026-10-21 04:23:25 +02:00
Move validation to AWS S3 backup provider
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"regexp"
|
||||
|
||||
virtuslabv1alpha1 "github.com/VirtusLab/jenkins-operator/pkg/apis/virtuslab/v1alpha1"
|
||||
"github.com/VirtusLab/jenkins-operator/pkg/controller/jenkins/backup"
|
||||
"github.com/VirtusLab/jenkins-operator/pkg/controller/jenkins/configuration/base/resources"
|
||||
"github.com/VirtusLab/jenkins-operator/pkg/controller/jenkins/plugins"
|
||||
"github.com/VirtusLab/jenkins-operator/pkg/log"
|
||||
@@ -42,7 +43,12 @@ func (r *ReconcileJenkinsBaseConfiguration) Validate(jenkins *virtuslabv1alpha1.
|
||||
return valid, err
|
||||
}
|
||||
|
||||
if r.jenkins.Spec.Backup == virtuslabv1alpha1.JenkinsBackupTypeAmazonS3 && !r.verifyBackupAmazonS3() {
|
||||
backupProvider, err := backup.GetBackupProvider(r.jenkins.Spec.Backup)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if !backupProvider.IsConfigurationValidForBasePhase(*r.jenkins, r.logger) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -86,8 +92,8 @@ func (r *ReconcileJenkinsBaseConfiguration) verifyBackup() (bool, error) {
|
||||
}
|
||||
|
||||
valid := false
|
||||
for _, backup := range virtuslabv1alpha1.AllowedJenkinsBackups {
|
||||
if r.jenkins.Spec.Backup == backup {
|
||||
for _, backupType := range virtuslabv1alpha1.AllowedJenkinsBackups {
|
||||
if r.jenkins.Spec.Backup == backupType {
|
||||
valid = true
|
||||
}
|
||||
}
|
||||
@@ -114,22 +120,3 @@ func (r *ReconcileJenkinsBaseConfiguration) verifyBackup() (bool, error) {
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (r *ReconcileJenkinsBaseConfiguration) verifyBackupAmazonS3() bool {
|
||||
if len(r.jenkins.Spec.BackupAmazonS3.BucketName) == 0 {
|
||||
r.logger.V(log.VWarn).Info("Bucket name not set in 'spec.backupAmazonS3.bucketName'")
|
||||
return false
|
||||
}
|
||||
|
||||
if len(r.jenkins.Spec.BackupAmazonS3.BucketPath) == 0 {
|
||||
r.logger.V(log.VWarn).Info("Bucket path not set in 'spec.backupAmazonS3.bucketPath'")
|
||||
return false
|
||||
}
|
||||
|
||||
if len(r.jenkins.Spec.BackupAmazonS3.Region) == 0 {
|
||||
r.logger.V(log.VWarn).Info("Region not set in 'spec.backupAmazonS3.region'")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -146,79 +146,3 @@ func TestReconcileJenkinsBaseConfiguration_verifyBackup(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestReconcileJenkinsBaseConfiguration_verifyBackupAmazonS3(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
jenkins *virtuslabv1alpha1.Jenkins
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "happy",
|
||||
jenkins: &virtuslabv1alpha1.Jenkins{
|
||||
Spec: virtuslabv1alpha1.JenkinsSpec{
|
||||
BackupAmazonS3: virtuslabv1alpha1.JenkinsBackupAmazonS3{
|
||||
BucketName: "some-value",
|
||||
BucketPath: "some-value",
|
||||
Region: "some-value",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "fail, no bucket name",
|
||||
jenkins: &virtuslabv1alpha1.Jenkins{
|
||||
Spec: virtuslabv1alpha1.JenkinsSpec{
|
||||
BackupAmazonS3: virtuslabv1alpha1.JenkinsBackupAmazonS3{
|
||||
BucketName: "",
|
||||
BucketPath: "some-value",
|
||||
Region: "some-value",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "fail, no bucket path",
|
||||
jenkins: &virtuslabv1alpha1.Jenkins{
|
||||
Spec: virtuslabv1alpha1.JenkinsSpec{
|
||||
BackupAmazonS3: virtuslabv1alpha1.JenkinsBackupAmazonS3{
|
||||
BucketName: "some-value",
|
||||
BucketPath: "",
|
||||
Region: "some-value",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "fail, no region",
|
||||
jenkins: &virtuslabv1alpha1.Jenkins{
|
||||
Spec: virtuslabv1alpha1.JenkinsSpec{
|
||||
BackupAmazonS3: virtuslabv1alpha1.JenkinsBackupAmazonS3{
|
||||
BucketName: "some-value",
|
||||
BucketPath: "some-value",
|
||||
Region: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &ReconcileJenkinsBaseConfiguration{
|
||||
k8sClient: fake.NewFakeClient(),
|
||||
scheme: nil,
|
||||
logger: logf.ZapLogger(false),
|
||||
jenkins: tt.jenkins,
|
||||
local: false,
|
||||
minikube: false,
|
||||
}
|
||||
got := r.verifyBackupAmazonS3()
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user