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

Commit

Permalink
Add a test for releasing initContainers
Browse files Browse the repository at this point in the history
.. and make it pass.
  • Loading branch information
squaremo committed Sep 10, 2018
1 parent 44d5c24 commit a2ffde2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cluster/kubernetes/resource/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (t PodTemplate) SetContainerImage(container string, ref image.Ref) error {
}
for i, c := range t.Spec.InitContainers {
if c.Name == container {
t.Spec.Containers[i].Image = ref.String()
t.Spec.InitContainers[i].Image = ref.String()
return nil
}
}
Expand Down
19 changes: 19 additions & 0 deletions cluster/kubernetes/testfiles/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var ResourceMap = map[flux.ResourceID]string{
flux.MustParseResourceID("default:deployment/list-deploy"): "list.yaml",
flux.MustParseResourceID("default:service/list-service"): "list.yaml",
flux.MustParseResourceID("default:deployment/semver"): "semver-deploy.yaml",
flux.MustParseResourceID("default:daemonset/init"): "init.yaml",
}

// ServiceMap ... given a base path, construct the map representing
Expand All @@ -66,6 +67,7 @@ func ServiceMap(dir string) map[flux.ResourceID][]string {
flux.MustParseResourceID("default:deployment/multi-deploy"): []string{filepath.Join(dir, "multi.yaml")},
flux.MustParseResourceID("default:deployment/list-deploy"): []string{filepath.Join(dir, "list.yaml")},
flux.MustParseResourceID("default:deployment/semver"): []string{filepath.Join(dir, "semver-deploy.yaml")},
flux.MustParseResourceID("default:daemonset/init"): []string{filepath.Join(dir, "init.yaml")},
}
}

Expand Down Expand Up @@ -238,6 +240,23 @@ items:
app: list-app
`,

// A daemonset using initContainers
"init.yaml": `---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: init
spec:
template:
spec:
initContainers:
- name: greeter
image: quay.io/weaveworks/helloworld:master-a000001
containers:
- name: unimportant
image: alpine:1.0
`,

// A tricksy chart directory, which should be skipped entirely. Adapted from
// https://github.com/kubernetes/helm/tree/master/docs/examples
"charts/nginx/Chart.yaml": `---
Expand Down
51 changes: 51 additions & 0 deletions release/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,57 @@ func (x expected) Result() update.Result {
return result
}

func Test_InitContainer(t *testing.T) {
initWorkloadID := flux.MustParseResourceID("default:daemonset/init")
initSvc := cluster.Controller{
ID: initWorkloadID,
Containers: cluster.ContainersOrExcuse{
Containers: []resource.Container{
{
Name: helloContainer,
Image: oldRef,
},
},
},
}

cluster := mockCluster(hwSvc, lockedSvc, initSvc)

expect := expected{
Specific: update.Result{
initWorkloadID: update.ControllerResult{
Status: update.ReleaseStatusSuccess,
PerContainer: []update.ContainerUpdate{
update.ContainerUpdate{
Container: helloContainer,
Current: oldRef,
Target: newHwRef,
},
},
},
},
Else: ignoredNotIncluded,
}

initSpec, _ := update.ParseResourceSpec(initWorkloadID.String())
spec := update.ReleaseSpec{
ServiceSpecs: []update.ResourceSpec{initSpec},
ImageSpec: update.ImageSpecLatest,
Kind: update.ReleaseKindExecute,
}

checkout, clean := setup(t)
defer clean()

testRelease(t, &ReleaseContext{
cluster: cluster,
manifests: mockManifests,
registry: mockRegistry,
repo: checkout,
}, spec, expect.Result())

}

func Test_FilterLogic(t *testing.T) {
cluster := mockCluster(hwSvc, lockedSvc) // no testsvc in cluster, but it _is_ in repo

Expand Down

0 comments on commit a2ffde2

Please sign in to comment.