Skip to content

Commit

Permalink
Customization for apprepository crontab. (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Schwarz-Fritz authored and Andres Martinez Gotor committed Sep 23, 2019
1 parent 5c429ce commit 6567ec2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions chart/kubeapps/templates/apprepository-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ spec:
- --namespace={{ .Release.Namespace }}
- --mongo-url={{ template "kubeapps.mongodb.fullname" . }}
- --mongo-secret-name={{ .Values.mongodb.existingSecret }}
- --crontab={{ .Values.apprepository.crontab }}
resources:
{{ toYaml .Values.apprepository.resources | indent 12 }}
{{- with .Values.apprepository.nodeSelector }}
Expand Down
2 changes: 2 additions & 0 deletions chart/kubeapps/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ frontend:
apprepository:
# Running a single controller replica to avoid sync job duplication
replicaCount: 1
# Schedule for syncing apprepositories
crontab: "*/10 * * * *"
image:
registry: docker.io
repository: kubeapps/apprepository-controller
Expand Down
3 changes: 1 addition & 2 deletions cmd/apprepository-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ func newCronJob(apprepo *apprepov1alpha1.AppRepository) *batchv1beta1.CronJob {
},
},
Spec: batchv1beta1.CronJobSpec{
// TODO: make schedule customisable
Schedule: "*/10 * * * *",
Schedule: crontab,
// Set to replace as short-circuit in k8s <1.12
// TODO re-evaluate ConcurrentPolicy when 1.12+ is mainstream (i.e 1.14)
// https://github.com/kubernetes/kubernetes/issues/54870
Expand Down
11 changes: 9 additions & 2 deletions cmd/apprepository-controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Test_newCronJob(t *testing.T) {
apprepo *apprepov1alpha1.AppRepository
expected batchv1beta1.CronJob
userAgentComment string
crontab string
}{
{
"my-charts",
Expand Down Expand Up @@ -96,9 +97,10 @@ func Test_newCronJob(t *testing.T) {
},
},
"",
"",
},
{
"my-charts with auth and userAgent comment",
"my-charts with auth, userAgent and crontab configuration",
&apprepov1alpha1.AppRepository{
TypeMeta: metav1.TypeMeta{
Kind: "AppRepository",
Expand Down Expand Up @@ -136,7 +138,7 @@ func Test_newCronJob(t *testing.T) {
},
},
Spec: batchv1beta1.CronJobSpec{
Schedule: "*/10 * * * *",
Schedule: "*/20 * * * *",
ConcurrencyPolicy: "Replace",
JobTemplate: batchv1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Expand Down Expand Up @@ -182,6 +184,7 @@ func Test_newCronJob(t *testing.T) {
},
},
"kubeapps/v2.3",
"*/20 * * * *",
},
}

Expand All @@ -191,6 +194,10 @@ func Test_newCronJob(t *testing.T) {
userAgentComment = tt.userAgentComment
defer func() { userAgentComment = "" }()
}
if tt.crontab != "" {
crontab = tt.crontab
defer func() { crontab = "" }()
}
result := newCronJob(tt.apprepo)
if diff := deep.Equal(tt.expected, *result); diff != nil {
t.Error(diff)
Expand Down
2 changes: 2 additions & 0 deletions cmd/apprepository-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
mongoURL string
mongoSecretName string
userAgentComment string
crontab string
)

func main() {
Expand Down Expand Up @@ -81,4 +82,5 @@ func init() {
flag.StringVar(&mongoURL, "mongo-url", "localhost", "MongoDB URL (see https://godoc.org/labix.org/v2/mgo#Dial for format)")
flag.StringVar(&mongoSecretName, "mongo-secret-name", "mongodb", "Kubernetes secret name for MongoDB credentials")
flag.StringVar(&userAgentComment, "user-agent-comment", "", "UserAgent comment used during outbound requests")
flag.StringVar(&crontab, "crontab", "*/10 * * * *", "CronTab to specify schedule")
}

0 comments on commit 6567ec2

Please sign in to comment.