Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1133 from weaveworks/fix/parse-cronjob
Browse files Browse the repository at this point in the history
Fix CronJob manifest verification
  • Loading branch information
squaremo authored Jun 11, 2018
2 parents 180d2e3 + 1f4e036 commit a843586
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cluster/kubernetes/resource/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type CronJobSpec struct {
Spec struct {
Template PodTemplate
}
}
} `yaml:"jobTemplate"`
}

func (c CronJob) Containers() []resource.Container {
Expand Down
33 changes: 33 additions & 0 deletions cluster/kubernetes/resource/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/cluster/kubernetes/testfiles"
"github.com/weaveworks/flux/resource"
Expand Down Expand Up @@ -119,6 +121,37 @@ data:
}
}

func TestParseCronJob(t *testing.T) {
doc := `---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
namespace: default
name: weekly-curl-homepage
spec:
jobTemplate:
spec:
template:
spec:
containers:
- name: weekly-curl-homepage
image: centos:7 # Has curl installed by default
`
objs, err := ParseMultidoc([]byte(doc), "test")
assert.NoError(t, err)

obj, ok := objs["default:cronjob/weekly-curl-homepage"]
assert.True(t, ok)
cj, ok := obj.(*CronJob)
assert.True(t, ok)

containers := cj.Spec.JobTemplate.Spec.Template.Spec.Containers
if assert.Len(t, containers, 1) {
assert.Equal(t, "centos:7", containers[0].Image)
assert.Equal(t, "weekly-curl-homepage", containers[0].Name)
}
}

func TestUnmarshalList(t *testing.T) {
doc := `---
kind: List
Expand Down

0 comments on commit a843586

Please sign in to comment.