mirror of
https://github.com/jenkinsci/kubernetes-operator.git
synced 2026-10-21 12:39:33 +02:00
Remove cron validation (#748)
* Remove cron validation * Bump git plugin
This commit is contained in:
@@ -163,7 +163,6 @@ type SeedJobs interface {
|
||||
isRecreatePodNeeded(jenkins v1alpha2.Jenkins) bool
|
||||
createAgent(jenkinsClient jenkinsclient.Jenkins, k8sClient client.Client, jenkinsManifest *v1alpha2.Jenkins, namespace string, agentName string) error
|
||||
ValidateSeedJobs(jenkins v1alpha2.Jenkins) ([]string, error)
|
||||
validateSchedule(job v1alpha2.SeedJob, str string, key string) []string
|
||||
validateGitHubPushTrigger(jenkins v1alpha2.Jenkins) []string
|
||||
validateBitbucketPushTrigger(jenkins v1alpha2.Jenkins) []string
|
||||
validateIfIDIsUnique(seedJobs []v1alpha2.SeedJob) []string
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/jenkinsci/kubernetes-operator/api/v1alpha2"
|
||||
|
||||
stackerr "github.com/pkg/errors"
|
||||
"github.com/robfig/cron"
|
||||
"golang.org/x/crypto/ssh"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -89,22 +88,6 @@ func (s *seedJobs) ValidateSeedJobs(jenkins v1alpha2.Jenkins) ([]string, error)
|
||||
}
|
||||
}
|
||||
|
||||
if len(seedJob.BuildPeriodically) > 0 {
|
||||
if msg := s.validateSchedule(seedJob, seedJob.BuildPeriodically, "buildPeriodically"); len(msg) > 0 {
|
||||
for _, m := range msg {
|
||||
messages = append(messages, fmt.Sprintf("seedJob `%s` %s", seedJob.ID, m))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(seedJob.PollSCM) > 0 {
|
||||
if msg := s.validateSchedule(seedJob, seedJob.PollSCM, "pollSCM"); len(msg) > 0 {
|
||||
for _, m := range msg {
|
||||
messages = append(messages, fmt.Sprintf("seedJob `%s` %s", seedJob.ID, m))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if seedJob.GitHubPushTrigger {
|
||||
if msg := s.validateGitHubPushTrigger(jenkins); len(msg) > 0 {
|
||||
for _, m := range msg {
|
||||
@@ -125,15 +108,6 @@ func (s *seedJobs) ValidateSeedJobs(jenkins v1alpha2.Jenkins) ([]string, error)
|
||||
return messages, nil
|
||||
}
|
||||
|
||||
func (s *seedJobs) validateSchedule(job v1alpha2.SeedJob, str string, key string) []string {
|
||||
var messages []string
|
||||
_, err := cron.Parse(str)
|
||||
if err != nil {
|
||||
messages = append(messages, fmt.Sprintf("`%s` schedule '%s' is invalid cron spec in `%s`", key, str, job.ID))
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
func (s *seedJobs) validateGitHubPushTrigger(jenkins v1alpha2.Jenkins) []string {
|
||||
var messages []string
|
||||
if err := checkPluginExists(jenkins, "github"); err != nil {
|
||||
|
||||
@@ -696,7 +696,7 @@ func TestValidateSeedJobs(t *testing.T) {
|
||||
TypeMeta: secretTypeMeta,
|
||||
ObjectMeta: secretObjectMeta,
|
||||
Data: map[string][]byte{
|
||||
AppIDSecretKey: []byte("some-id"),
|
||||
AppIDSecretKey: []byte("some-id"),
|
||||
PrivateKeySecretKey: []byte("some-key"),
|
||||
},
|
||||
}
|
||||
@@ -737,7 +737,7 @@ func TestValidateSeedJobs(t *testing.T) {
|
||||
TypeMeta: secretTypeMeta,
|
||||
ObjectMeta: secretObjectMeta,
|
||||
Data: map[string][]byte{
|
||||
AppIDSecretKey: []byte(""),
|
||||
AppIDSecretKey: []byte(""),
|
||||
PrivateKeySecretKey: []byte("some-key"),
|
||||
},
|
||||
}
|
||||
@@ -779,7 +779,7 @@ func TestValidateSeedJobs(t *testing.T) {
|
||||
TypeMeta: secretTypeMeta,
|
||||
ObjectMeta: secretObjectMeta,
|
||||
Data: map[string][]byte{
|
||||
AppIDSecretKey: []byte("some-id"),
|
||||
AppIDSecretKey: []byte("some-id"),
|
||||
PrivateKeySecretKey: []byte(""),
|
||||
},
|
||||
}
|
||||
@@ -883,39 +883,6 @@ func TestValidateSeedJobs(t *testing.T) {
|
||||
|
||||
assert.Equal(t, result, []string{"seedJob `example` required data 'privateKey' not found in secret 'deploy-keys'", "seedJob `example` required data 'privateKey' is empty in secret 'deploy-keys'"})
|
||||
})
|
||||
t.Run("Invalid with wrong cron spec", func(t *testing.T) {
|
||||
jenkins := v1alpha2.Jenkins{
|
||||
Spec: v1alpha2.JenkinsSpec{
|
||||
SeedJobs: []v1alpha2.SeedJob{
|
||||
{
|
||||
ID: "example",
|
||||
CredentialID: "jenkins-operator-e2e",
|
||||
JenkinsCredentialType: v1alpha2.NoJenkinsCredentialCredentialType,
|
||||
Targets: "cicd/jobs/*.jenkins",
|
||||
RepositoryBranch: "master",
|
||||
RepositoryURL: "https://github.com/jenkinsci/kubernetes-operator.git",
|
||||
BuildPeriodically: "invalid-cron-spec",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
fakeClient := fake.NewClientBuilder().Build()
|
||||
|
||||
config := configuration.Configuration{
|
||||
Client: fakeClient,
|
||||
ClientSet: kubernetes.Clientset{},
|
||||
Notifications: nil,
|
||||
Jenkins: &v1alpha2.Jenkins{},
|
||||
}
|
||||
|
||||
seedJobs := New(nil, config)
|
||||
result, err := seedJobs.ValidateSeedJobs(jenkins)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, result, []string{"seedJob `example` `buildPeriodically` schedule 'invalid-cron-spec' is invalid cron spec in `example`"})
|
||||
})
|
||||
t.Run("Valid with good cron spec", func(t *testing.T) {
|
||||
jenkins := v1alpha2.Jenkins{
|
||||
Spec: v1alpha2.JenkinsSpec{
|
||||
|
||||
@@ -2,7 +2,7 @@ package plugins
|
||||
|
||||
const (
|
||||
configurationAsCodePlugin = "configuration-as-code:1346.ve8cfa_3473c94"
|
||||
gitPlugin = "git:4.10.3"
|
||||
gitPlugin = "git:4.11.3"
|
||||
jobDslPlugin = "job-dsl:1.78.1"
|
||||
kubernetesPlugin = "kubernetes:1.31.3"
|
||||
kubernetesCredentialsProviderPlugin = "kubernetes-credentials-provider:0.20"
|
||||
|
||||
Reference in New Issue
Block a user