Skip to content

Commit

Permalink
My crappy patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Barrick committed Jul 28, 2018
1 parent 8a00438 commit acdc513
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cluster/kubernetes/resource/fluxhelmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ func interpret_stringmap(m map[string]interface{}) (image.Ref, ImageSetter, bool
}
}
}
case map[interface{}]interface{}:
if imgRepo, ok := img["repository"].(string); ok {
if imgTag, ok := img["tag"].(string); ok {
imgRef, err := image.ParseRef(imgRepo + ":" + imgTag)
if err == nil {
return imgRef, func(ref image.Ref) {
img["repository"] = ref.Name.String()
img["tag"] = ref.Tag
}, true
}
}
}
}
return image.Ref{}, nil, false
}
Expand Down
67 changes: 67 additions & 0 deletions cluster/kubernetes/resource/fluxhelmrelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,70 @@ spec:
t.Errorf("expected container name %q, got %q", expectedContainer, containers[0].Name)
}
}

func TestParseNamedImageObjectFormatFlat(t *testing.T) {
expectedContainer := ReleaseContainerName
expectedImageName := "bitnami/mariadb"
expectedImageTag := "10.1.30-r1"
expectedImage := expectedImageName + ":" + expectedImageTag

doc := `---
apiVersion: helm.integrations.flux.weave.works/v1alpha2
kind: FluxHelmRelease
metadata:
name: mariadb
namespace: maria
labels:
chart: mariadb
spec:
chartGitPath: mariadb
values:
image:
repository: ` + expectedImageName + `
tag: ` + expectedImageTag + `
persistence:
enabled: false
`

resources, err := ParseMultidoc([]byte(doc), "test")
if err != nil {
t.Fatal(err)
}
res, ok := resources["maria:fluxhelmrelease/mariadb"]
if !ok {
t.Fatalf("expected resource not found; instead got %#v", resources)
}
fhr, ok := res.(resource.Workload)
if !ok {
t.Fatalf("expected resource to be a Workload, instead got %#v", res)
}

containers := fhr.Containers()
if len(containers) != 1 {
t.Fatalf("expected 1 container; got %#v", containers)
}
image := containers[0].Image.String()
if image != expectedImage {
t.Errorf("expected container image %q, got %q", expectedImage, image)
}
if containers[0].Name != expectedContainer {
t.Errorf("expected container name %q, got %q", expectedContainer, containers[0].Name)
}

newImage := containers[0].Image.WithNewTag("some-other-tag")
if err := fhr.SetContainerImage(expectedContainer, newImage); err != nil {
t.Error(err)
}

containers = fhr.Containers()
if len(containers) != 1 {
t.Fatalf("expected 1 container; got %#v", containers)
}
image = containers[0].Image.String()
if image != newImage.String() {
t.Errorf("expected container image %q, got %q", newImage.String(), image)
}
if containers[0].Name != expectedContainer {
t.Errorf("expected container name %q, got %q", expectedContainer, containers[0].Name)
}
}

0 comments on commit acdc513

Please sign in to comment.