/
add-on-cron-jobs.go
106 lines (94 loc) · 3.9 KB
/
add-on-cron-jobs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package eksconfig
import (
"errors"
"fmt"
"github.com/aws/aws-k8s-tester/pkg/timeutil"
)
// AddOnCronJobs defines parameters for EKS cluster
// add-on with CronJob.
type AddOnCronJobs struct {
// Enable is 'true' to create this add-on.
Enable bool `json:"enable"`
// Created is true when the resource has been created.
// Used for delete operations.
Created bool `json:"created" read-only:"true"`
TimeFrameCreate timeutil.TimeFrame `json:"time-frame-create" read-only:"true"`
TimeFrameDelete timeutil.TimeFrame `json:"time-frame-delete" read-only:"true"`
// Namespace is the namespace to create objects in.
Namespace string `json:"namespace"`
// RepositoryBusyboxAccountID is the account ID for tester ECR image.
// e.g. "busybox" for "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/busybox"
RepositoryBusyboxAccountID string `json:"repository-busybox-account-id,omitempty"`
// RepositoryBusyboxRegion is the ECR repository region to pull from.
RepositoryBusyboxRegion string `json:"repository-busybox-region,omitempty"`
// RepositoryBusyboxName is the repositoryName for tester ECR image.
// e.g. "busybox" for "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/busybox"
RepositoryBusyboxName string `json:"repository-busybox-name,omitempty"`
// RepositoryBusyboxImageTag is the image tag for tester ECR image.
// e.g. "latest" for image URI "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/busybox:latest"
RepositoryBusyboxImageTag string `json:"repository-busybox-image-tag,omitempty"`
// Schedule is the cron schedule (e.g. "*/1 * * * *").
Schedule string `json:"schedule"`
// Completes is the desired number of successfully finished pods.
Completes int `json:"completes"`
// Parallels is the the maximum desired number of pods the
// job should run at any given time.
Parallels int `json:"parallels"`
// SuccessfulJobsHistoryLimit is the number of successful finished
// jobs to retain. Defaults to 3.
SuccessfulJobsHistoryLimit int32 `json:"successful-jobs-history-limit"`
// FailedJobsHistoryLimit is the number of failed finished jobs
// to retain. Defaults to 1.
FailedJobsHistoryLimit int32 `json:"failed-jobs-history-limit"`
// EchoSize is the job object size in bytes.
// "Request entity too large: limit is 3145728" (3.1 MB).
// "The Job "echo" is invalid: metadata.annotations:
// Too long: must have at most 262144 characters". (0.26 MB)
EchoSize int `json:"echo-size"`
}
// EnvironmentVariablePrefixAddOnCronJobs is the environment variable prefix used for "eksconfig".
const EnvironmentVariablePrefixAddOnCronJobs = AWS_K8S_TESTER_EKS_PREFIX + "ADD_ON_CRON_JOBS_"
// IsEnabledAddOnCronJobs returns true if "AddOnCronJobs" is enabled.
// Otherwise, nil the field for "omitempty".
func (cfg *Config) IsEnabledAddOnCronJobs() bool {
if cfg.AddOnCronJobs == nil {
return false
}
if cfg.AddOnCronJobs.Enable {
return true
}
cfg.AddOnCronJobs = nil
return false
}
func getDefaultAddOnCronJobs() *AddOnCronJobs {
return &AddOnCronJobs{
Enable: false,
Schedule: "*/10 * * * *", // every 10-min
Completes: 10,
Parallels: 10,
SuccessfulJobsHistoryLimit: 3,
FailedJobsHistoryLimit: 1,
EchoSize: 100 * 1024, // 100 KB
}
}
func (cfg *Config) GetAddOnCronJobsRepositoryBusyboxRegion() string {
if !cfg.IsEnabledAddOnCronJobs() {
return cfg.Region
}
return cfg.AddOnCronJobs.RepositoryBusyboxRegion
}
func (cfg *Config) validateAddOnCronJobs() error {
if !cfg.IsEnabledAddOnCronJobs() {
return nil
}
if !cfg.IsEnabledAddOnNodeGroups() && !cfg.IsEnabledAddOnManagedNodeGroups() {
return errors.New("AddOnCronJobs.Enable true but no node group is enabled")
}
if cfg.AddOnCronJobs.Namespace == "" {
cfg.AddOnCronJobs.Namespace = cfg.Name + "-cronjob"
}
if cfg.AddOnCronJobs.EchoSize > 250000 {
return fmt.Errorf("echo size limit is 0.25 MB, got %d", cfg.AddOnCronJobs.EchoSize)
}
return nil
}