diff --git a/chartvalidator/checker/.gitignore b/chartvalidator/checker/.gitignore index ac192d1..a6ed6fb 100644 --- a/chartvalidator/checker/.gitignore +++ b/chartvalidator/checker/.gitignore @@ -4,4 +4,5 @@ helm_output *.bin manifests imageLists -test_output \ No newline at end of file +test_output +checker \ No newline at end of file diff --git a/chartvalidator/checker/go.mod b/chartvalidator/checker/go.mod index 4e30820..3f3bf10 100644 --- a/chartvalidator/checker/go.mod +++ b/chartvalidator/checker/go.mod @@ -1,4 +1,4 @@ -module github.com/interledger/interledger-app-deploy/ci +module github.com/builderslab/chartvalidator/checker go 1.24.5 diff --git a/chartvalidator/checker/main.go b/chartvalidator/checker/main.go index 9c6f361..3ca44ad 100644 --- a/chartvalidator/checker/main.go +++ b/chartvalidator/checker/main.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "os" + "sync" ) var srcPrefix string = "../" @@ -22,6 +23,8 @@ func main() { switch command { case "run-checks": runChartChecksCommand(args) + case "render-only": + runRenderOnlyCommand(args) case "help", "-h", "--help": printUsage() default: @@ -32,10 +35,11 @@ func main() { } func printUsage() { - fmt.Println("Usage: run-manifest-checks [flags]") + fmt.Println("Usage: chart-checker [flags]") fmt.Println("") fmt.Println("Commands:") fmt.Println(" run-checks Runs all available checks on the charts for given environment.") + fmt.Println(" render-only Renders the charts for the given environment without performing validations.") fmt.Println(" help Displays this help message.") fmt.Println("") fmt.Println("Use 'run-manifest-checks -h' to see command-specific flags.") @@ -82,6 +86,89 @@ func runChartChecksCommand(args []string) { } +func runRenderOnlyCommand(args []string) { + fs := flag.NewFlagSet("render-only", flag.ExitOnError) + + var ( + singleEnv = fs.String("env", "", "Only process this environment (folder name under -envdir).") + envDir = fs.String("envdir", "../env", "Base directory containing environment folders.") + outputDir = fs.String("output", "manifests", "Output directory for rendered charts.") + verbose = fs.Bool("v", false, "Enable verbose logging.") + ) + + fs.Usage = func() { + fmt.Println("Usage: run-manifest-checks render-only [flags]") + fmt.Println("") + fmt.Println("Renders all charts found in the ApplicationSets in the specified environment and outputs the manifests to the specified output directory.") + fmt.Println("") + fs.PrintDefaults() + } + + if err := fs.Parse(args); err != nil { + os.Exit(1) + } + + verboseLogging = *verbose + + if err := runAllChartRenders(*singleEnv, *envDir, *outputDir); err != nil { + fmt.Fprintf(os.Stderr, "Error running chart renders: %v\n", err) + os.Exit(1) + } + +} + + +func runAllChartRenders(singleEnv, envDir, outputDir string) error { + fmt.Println("Starting chart renders...") + params, err := findChartsInAppsets(envDir, singleEnv) + if err != nil { + return fmt.Errorf("failed to find charts in ApplicationSets: %w", err) + } + + fmt.Printf("Found %d charts to process.\n", len(params)) + + context := context.Background() + + // Delete output dir if it exists + if err := os.RemoveAll(outputDir); err != nil { + return fmt.Errorf("failed to clear output directory: %w", err) + } + + renderer := ChartRenderingEngine{ + context: context, + executor: &RealCommandExecutor{}, + outputDir: outputDir, + inputChan: make(chan ChartRenderParams), + resultChan: make(chan RenderResult), + name: "ChartRenderer", + errorChan: make(chan ErrorResult), + workerWaitGroup: sync.WaitGroup{}, + } + renderer.Start(10) + + go func() { + for _, p := range params { + renderer.inputChan <- p + } + close(renderer.inputChan) + }() + + busy := true + for busy { + select { + case renderResult, ok := <-renderer.resultChan: + if !ok { + fmt.Println("No more render results.") + busy = false + } + fmt.Printf(">>> chart %s %s from env %s: ✓ Rendered successfully to %s\n", renderResult.Chart.ChartName, renderResult.Chart.ChartVersion, renderResult.Chart.Env, renderResult.ManifestPath) + case renderErr := <-renderer.errorChan: + fmt.Printf(">>> chart %s %s from env %s: ✗ Error: %v\n", renderErr.Chart.ChartName, renderErr.Chart.ChartVersion, renderErr.Chart.Env, renderErr.Error) + } + } + fmt.Printf("Done") + return nil +} func runAllChartChecks(singleEnv, envDir, outputDir string) error { fmt.Println("Starting chart checks...")