From 20e9337a7fbd2e2a2a0ff074592cc459f9e55115 Mon Sep 17 00:00:00 2001 From: Martin Irungu <68087402+wirungu@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:16:51 +0200 Subject: [PATCH] e2e: add image patch from file --- e2e/internal/kuberesource/resourcegen/main.go | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/e2e/internal/kuberesource/resourcegen/main.go b/e2e/internal/kuberesource/resourcegen/main.go index 344dceb1a4..e3ba4ca2bc 100644 --- a/e2e/internal/kuberesource/resourcegen/main.go +++ b/e2e/internal/kuberesource/resourcegen/main.go @@ -1,7 +1,9 @@ package main import ( + "flag" "fmt" + "log" "os" "path" @@ -9,13 +11,21 @@ import ( ) func main() { - if len(os.Args) != 3 { - fmt.Println("Usage: kuberesource ") + imageReplacementsPath := flag.String("image-replacements", "", "Path to the image replacements file") + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "Usage: %s \n", os.Args[0]) + flag.PrintDefaults() + } + + flag.Parse() + + if len(flag.Args()) != 2 { + flag.Usage() os.Exit(1) } - set := os.Args[1] - dest := os.Args[2] + set := flag.Arg(0) + dest := flag.Arg(1) var resources []any var err error @@ -39,6 +49,22 @@ func main() { os.Exit(1) } + var replacements map[string]string + if *imageReplacementsPath != "" { + f, err := os.Open(*imageReplacementsPath) + if err != nil { + log.Fatalf("could not open image definition file %q: %v", *imageReplacementsPath, err) + } + defer f.Close() + + replacements, err = kuberesource.ImageReplacementsFromFile(f) + if err != nil { + log.Fatalf("could not parse image definition file %q: %v", *imageReplacementsPath, err) + } + } + + kuberesource.PatchImages(resources, replacements) + b, err := kuberesource.EncodeResources(resources...) if err != nil { fmt.Printf("Error: %v\n", err)