Remove cron validation (#748)
* Remove cron validation * Bump git plugin
This commit is contained in:
parent
56b65aed16
commit
a97f283fb9
|
|
@ -353,7 +353,7 @@ type JenkinsMaster struct {
|
|||
// - name: configuration-as-code
|
||||
// version: "1346.ve8cfa_3473c94"
|
||||
// - name: git
|
||||
// version: "4.10.3"
|
||||
// version: "4.11.3"
|
||||
// - name: job-dsl
|
||||
// version: "1.78.1"
|
||||
// - name: kubernetes
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ spec:
|
|||
description: 'BasePlugins contains plugins required by operator
|
||||
Defaults to : - name: kubernetes version: "1.31.3" - name:
|
||||
workflow-job version: "1145.v7f2433caa07f" - name: workflow-aggregator version:
|
||||
"2.6" - name: git version: "4.10.3" - name: job-dsl version:
|
||||
"2.6" - name: git version: "4.11.3" - name: job-dsl version:
|
||||
"1.78.1" - name: configuration-as-code version: "1346.ve8cfa_3473c94" - name:
|
||||
kubernetes-credentials-provider version: "0.20"'
|
||||
items:
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ jenkins:
|
|||
# - name: configuration-as-code
|
||||
# version: "1346.ve8cfa_3473c94"
|
||||
# - name: git
|
||||
# version: 4.10.3
|
||||
# version: 4.11.3
|
||||
# - name: job-dsl
|
||||
# version: "1.78.1"
|
||||
# - name: kubernetes
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ spec:
|
|||
description: 'BasePlugins contains plugins required by operator
|
||||
Defaults to : - name: kubernetes version: "1.31.3" - name:
|
||||
workflow-job version: "1145.v7f2433caa07f" - name: workflow-aggregator version:
|
||||
"2.6" - name: git version: "4.10.3" - name: job-dsl version:
|
||||
"2.6" - name: git version: "4.11.3" - name: job-dsl version:
|
||||
"1.78.1" - name: configuration-as-code version: "1346.ve8cfa_3473c94" - name:
|
||||
kubernetes-credentials-provider version: "0.20"'
|
||||
items:
|
||||
|
|
|
|||
1
go.mod
1
go.mod
|
|
@ -15,7 +15,6 @@ require (
|
|||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/openshift/api v3.9.0+incompatible
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/robfig/cron v1.2.0
|
||||
github.com/stretchr/testify v1.6.1
|
||||
go.uber.org/zap v1.15.0
|
||||
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ const e2e = "e2e"
|
|||
|
||||
var expectedBasePluginsList = []plugins.Plugin{
|
||||
plugins.Must(plugins.New("configuration-as-code:1346.ve8cfa_3473c94")),
|
||||
plugins.Must(plugins.New("git:4.10.3")),
|
||||
plugins.Must(plugins.New("git:4.11.3")),
|
||||
plugins.Must(plugins.New("kubernetes:1.31.3")),
|
||||
plugins.Must(plugins.New("kubernetes-credentials-provider:0.20")),
|
||||
plugins.Must(plugins.New("job-dsl:1.78.1")),
|
||||
|
|
|
|||
Loading…
Reference in New Issue