From acdc513144dda99063f1c3877a505a77a1cb19bf Mon Sep 17 00:00:00 2001 From: Justin Barrick Date: Sat, 28 Jul 2018 22:03:24 +0000 Subject: [PATCH] My crappy patch. --- .../kubernetes/resource/fluxhelmrelease.go | 12 ++++ .../resource/fluxhelmrelease_test.go | 67 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/cluster/kubernetes/resource/fluxhelmrelease.go b/cluster/kubernetes/resource/fluxhelmrelease.go index 23482784c..dabf6e665 100644 --- a/cluster/kubernetes/resource/fluxhelmrelease.go +++ b/cluster/kubernetes/resource/fluxhelmrelease.go @@ -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 } diff --git a/cluster/kubernetes/resource/fluxhelmrelease_test.go b/cluster/kubernetes/resource/fluxhelmrelease_test.go index 8fd82154d..cc26c55f5 100644 --- a/cluster/kubernetes/resource/fluxhelmrelease_test.go +++ b/cluster/kubernetes/resource/fluxhelmrelease_test.go @@ -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) + } +}