Skip to content

Commit

Permalink
default to containerless mode
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan committed Nov 17, 2024
1 parent 9ab5f64 commit 3b0c687
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type analyzeCommand struct {
volumeName string
providerContainerNames []string
cleanup bool
runLocal bool

// for containerless cmd
reqMap map[string]string
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand All @@ -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 == "" {
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 0 additions & 9 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 3b0c687

Please sign in to comment.