Skip to content

Commit

Permalink
e2e: add image patch from file
Browse files Browse the repository at this point in the history
  • Loading branch information
wirungu authored and burgerdev committed Apr 23, 2024
1 parent a289c54 commit 20e9337
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions e2e/internal/kuberesource/resourcegen/main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package main

import (
"flag"
"fmt"
"log"
"os"
"path"

"github.com/edgelesssys/contrast/e2e/internal/kuberesource"
)

func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: kuberesource <set> <dest>")
imageReplacementsPath := flag.String("image-replacements", "", "Path to the image replacements file")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s <set> <dest>\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
Expand All @@ -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)
Expand Down

0 comments on commit 20e9337

Please sign in to comment.