chore(configmap): Manage binary data in configMap
We should be now able to detect and manage binary files to be injected in configMaps
This commit is contained in:
@@ -2,8 +2,13 @@ package generator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"katenary/generator/labels"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
v1 "k8s.io/api/apps/v1"
|
||||
@@ -149,6 +154,73 @@ services:
|
||||
}
|
||||
}
|
||||
|
||||
func TestBinaryMount(t *testing.T) {
|
||||
composeFile := `
|
||||
services:
|
||||
web:
|
||||
image: nginx
|
||||
volumes:
|
||||
- ./images/foo.png:/var/www/foo
|
||||
labels:
|
||||
%[1]s/configmap-files: |-
|
||||
- ./images/foo.png
|
||||
`
|
||||
composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix)
|
||||
tmpDir := setup(composeFile)
|
||||
log.Println(tmpDir)
|
||||
defer teardown(tmpDir)
|
||||
|
||||
os.Mkdir(filepath.Join(tmpDir, "images"), 0o755)
|
||||
|
||||
// create a png image
|
||||
pngFile := tmpDir + "/images/foo.png"
|
||||
w, h := 100, 100
|
||||
img := image.NewRGBA(image.Rect(0, 0, w, h))
|
||||
red := color.RGBA{255, 0, 0, 255}
|
||||
for y := 0; y < h; y++ {
|
||||
for x := 0; x < w; x++ {
|
||||
img.Set(x, y, red)
|
||||
}
|
||||
}
|
||||
|
||||
blue := color.RGBA{0, 0, 255, 255}
|
||||
for y := 30; y < 70; y++ {
|
||||
for x := 30; x < 70; x++ {
|
||||
img.Set(x, y, blue)
|
||||
}
|
||||
}
|
||||
currentDir, _ := os.Getwd()
|
||||
os.Chdir(tmpDir)
|
||||
defer os.Chdir(currentDir)
|
||||
|
||||
f, err := os.Create(pngFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
png.Encode(f, img)
|
||||
f.Close()
|
||||
output := internalCompileTest(t, "-s", "templates/web/deployment.yaml")
|
||||
d := v1.Deployment{}
|
||||
yaml.Unmarshal([]byte(output), &d)
|
||||
volumes := d.Spec.Template.Spec.Volumes
|
||||
if len(volumes) != 1 {
|
||||
t.Errorf("Expected 1 volume, got %d", len(volumes))
|
||||
}
|
||||
|
||||
cm := corev1.ConfigMap{}
|
||||
cmContent, err := helmTemplate(ConvertOptions{
|
||||
OutputDir: "chart",
|
||||
}, "-s", "templates/web/statics/images/configmap.yaml")
|
||||
yaml.Unmarshal([]byte(cmContent), &cm)
|
||||
if im, ok := cm.BinaryData["foo.png"]; !ok {
|
||||
t.Errorf("Expected foo.png to be in the configmap")
|
||||
} else {
|
||||
if len(im) == 0 {
|
||||
t.Errorf("Expected image to be non-empty")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBindFrom(t *testing.T) {
|
||||
composeFile := `
|
||||
services:
|
||||
|
Reference in New Issue
Block a user