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 #1351 from weaveworks/issue/1345-init-containers
Browse files Browse the repository at this point in the history
Fix verification of initContainer releases
  • Loading branch information
squaremo authored Sep 11, 2018
2 parents bcca62c + a2ffde2 commit f949465
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 201 deletions.
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
41 changes: 41 additions & 0 deletions cluster/kubernetes/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ func TestUpdates(t *testing.T) {
{"in kubernetes List resource", case10resource, case10containers, case10image, case10, case10out},
{"FluxHelmRelease (simple image encoding)", case11resource, case11containers, case11image, case11, case11out},
{"FluxHelmRelease (multi image encoding)", case12resource, case12containers, case12image, case12, case12out},
{"initContainer", case13resource, case13containers, case13image, case13, case13out},
} {
t.Run(c.name, func(t *testing.T) {
t.Parallel()
testUpdate(t, c)
})
}
Expand Down Expand Up @@ -868,3 +870,42 @@ spec:
sidecar:
image: sidecar:v1
`

const case13 = `---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: weave
spec:
replicas: 1
template:
metadata:
labels:
name: weave
spec:
initContainers:
- name: weave
image: 'weaveworks/weave-kube:2.2.0'
`

const case13resource = "default:deployment/weave"
const case13image = "weaveworks/weave-kube:2.2.1"

var case13containers = []string{"weave"}

const case13out = `---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: weave
spec:
replicas: 1
template:
metadata:
labels:
name: weave
spec:
initContainers:
- name: weave
image: 'weaveworks/weave-kube:2.2.1'
`
13 changes: 12 additions & 1 deletion git/gittest/repo.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package gittest

import (
"context"
"io/ioutil"
"os/exec"
"path/filepath"
"testing"

"context"
"github.com/weaveworks/flux"
"github.com/weaveworks/flux/cluster/kubernetes/testfiles"
"github.com/weaveworks/flux/git"
)
Expand Down Expand Up @@ -61,6 +62,16 @@ func Repo(t *testing.T) (*git.Repo, func()) {
}
}

// Workloads is a shortcut to getting the names of the workloads (NB
// not all resources, just the workloads) represented in the test
// files.
func Workloads() (res []flux.ResourceID) {
for k, _ := range testfiles.ServiceMap("") {
res = append(res, k)
}
return res
}

// CheckoutWithConfig makes a standard repo, clones it, and returns
// the clone, the original repo, and a cleanup function.
func CheckoutWithConfig(t *testing.T, config git.Config) (*git.Checkout, *git.Repo, func()) {
Expand Down
Loading

0 comments on commit f949465

Please sign in to comment.