Skip to content

Commit

Permalink
Add DNS1123 validation to namespace and job names
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Sevilla <[email protected]>
  • Loading branch information
rsevilla87 committed Sep 27, 2020
1 parent 3717a22 commit 6a5836d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ All the magic `kube-burner` does is described in the configuration file. This fi
| cleanup | Cleanup clean up old namespaces | Boolean | true | true |
| podWait | Wait for all pods to be running before moving forward to the next job iteration | Boolean | true | true |
| waitWhenFinished | Wait for all pods to be running when all iterations are completed | Boolean | true | false |
| maxWaitTimeout | Maximum wait timeout in seconds | Integer | 3600 | 43200 (12 hours) |
| waitFor | List containing the objects Kind wait for. Wait for all if empty | List | ["Deployment", "Build", "DaemonSet"]| [] |
| jobIterationDelay | How many milliseconds to wait between each job iteration | Integer | 2000 | false |
| jobPause | How many milliseconds to pause after finishing the job | Integer | 10000 | 0 |
Expand Down
17 changes: 17 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"

"gopkg.in/yaml.v3"
"k8s.io/apimachinery/pkg/util/validation"
)

// ConfigSpec configuration object
Expand Down Expand Up @@ -46,6 +47,7 @@ func (j *Job) UnmarshalYAML(unmarshal func(interface{}) error) error {
ErrorOnVerify: false,
JobType: CreationJob,
WaitForDeletion: true,
MaxWaitTimeout: 43200,
}
if err := unmarshal(&raw); err != nil {
return err
Expand All @@ -69,5 +71,20 @@ func Parse(c string) error {
if len(ConfigSpec.Jobs) <= 0 {
return fmt.Errorf("No jobs found at configuration file")
}
if err := validateDNS1123(); err != nil {
return err
}
return nil
}

func validateDNS1123() error {
for _, job := range ConfigSpec.Jobs {
if errs := validation.IsDNS1123Subdomain(job.Name); len(errs) > 0 {
return fmt.Errorf("Job %s name validation error: %s", job.Name, fmt.Sprint(errs))
}
if errs := validation.IsDNS1123Subdomain(job.Namespace); job.JobType == CreationJob && len(errs) > 0 {
return fmt.Errorf("Namespace %s name validation error: %s", job.Namespace, fmt.Sprint(errs))
}
}
return nil
}

0 comments on commit 6a5836d

Please sign in to comment.