From 56e646162c0ea6b87336e56ea2af944914010ece Mon Sep 17 00:00:00 2001 From: "konveyor-ci-bot[bot]" <159171263+konveyor-ci-bot[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:52:07 -0500 Subject: [PATCH] Default to containerless mode (#376) (#377) default to containerless mode Signed-off-by: Emily McMullan Signed-off-by: Cherry Picker Co-authored-by: Emily McMullan --- .github/workflows/testing.yaml | 2 +- cmd/analyze.go | 17 ++++++++++------- cmd/settings.go | 9 --------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 765be24..cadd07d 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -74,7 +74,7 @@ jobs: - name: Run analysis test and copy output run: | - RUNNER_IMG=localhost/kantra:latest ./kantra analyze --input $(pwd)/example-applications/example-1/ --output ./output/ --rules ./test-data/jni-native-code-test.windup.xml --target cloud-readiness + RUNNER_IMG=localhost/kantra:latest ./kantra analyze --input $(pwd)/example-applications/example-1/ --output ./output/ --rules ./test-data/jni-native-code-test.windup.xml --target cloud-readiness --run-local=false # TODO (pgaikwad): Change this to a yaml test and run `kantra test` - name: Fail if analysis output does not match expected diff --git a/cmd/analyze.go b/cmd/analyze.go index 287fe17..055bb06 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -148,6 +148,7 @@ type analyzeCommand struct { volumeName string providerContainerNames []string cleanup bool + runLocal bool // for containerless cmd reqMap map[string]string @@ -175,7 +176,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command { return err } } - if Settings.RunLocal { + if analyzeCmd.runLocal { err := analyzeCmd.setKantraDir() if err != nil { analyzeCmd.log.Error(err, "unable to get analyze reqs") @@ -200,12 +201,13 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command { defer stop() // ***** RUN CONTAINERLESS MODE ***** - if Settings.RunLocal { + + if analyzeCmd.runLocal { if analyzeCmd.listProviders { log.Info("\n containerless analysis mode set; only java provider supported") return nil } - log.Info("\n running analysis in containerless mode") + log.Info("\n --run-local set. running analysis in containerless mode") if analyzeCmd.listSources || analyzeCmd.listTargets { err := analyzeCmd.listLabelsContainerless(ctx) if err != nil { @@ -221,7 +223,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command { return nil } - log.Info("RUN_LOCAL not set. running analysis in container mode") + log.Info("--run-local not set. running analysis in container mode") // ******* RUN CONTAINERS ****** if analyzeCmd.overrideProviderSettings == "" { @@ -378,6 +380,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command { analyzeCommand.Flags().StringArrayVarP(&analyzeCmd.depFolders, "dependency-folders", "d", []string{}, "directory for dependencies") analyzeCommand.Flags().StringVar(&analyzeCmd.overrideProviderSettings, "override-provider-settings", "", "override the provider settings, the analysis pod will be run on the host network and no providers will be started up") analyzeCommand.Flags().StringArrayVar(&analyzeCmd.provider, "provider", []string{}, "specify which provider(s) to run") + analyzeCommand.Flags().BoolVar(&analyzeCmd.runLocal, "run-local", true, "run Java analysis in containerless mode") return analyzeCommand } @@ -392,7 +395,7 @@ func (a *analyzeCommand) Validate(ctx context.Context) error { // Validate source labels if len(a.sources) > 0 { var sourcesRaw bytes.Buffer - if Settings.RunLocal { + if a.runLocal { a.fetchLabelsContainerless(ctx, true, false, &sourcesRaw) } else { a.fetchLabels(ctx, true, false, &sourcesRaw) @@ -413,7 +416,7 @@ func (a *analyzeCommand) Validate(ctx context.Context) error { // Validate target labels if len(a.targets) > 0 { var targetRaw bytes.Buffer - if Settings.RunLocal { + if a.runLocal { a.fetchLabelsContainerless(ctx, false, true, &targetRaw) } else { a.fetchLabels(ctx, false, true, &targetRaw) @@ -740,7 +743,7 @@ func (a *analyzeCommand) fetchLabels(ctx context.Context, listSources, listTarge a.log.Error(err, "failed getting rules volumes") return err } - args := []string{"analyze"} + args := []string{"analyze", "--run-local=false"} if listSources { args = append(args, "--list-sources") } else { diff --git a/cmd/settings.go b/cmd/settings.go index cf4d5d4..0e58a0c 100644 --- a/cmd/settings.go +++ b/cmd/settings.go @@ -27,15 +27,6 @@ func (c *Config) Load() error { if err := c.loadCommandName(); err != nil { return err } - runContainerlessStr := os.Getenv("RUN_LOCAL") - if runContainerlessStr != "" && runContainerlessStr == "true" { - err := env.Set(c) - if err != nil { - return err - } - // do not need other env vars for containerless analysis - return nil - } if err := c.loadDefaultPodmanBin(); err != nil { return err }