Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to containerless mode #376

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--list-providers should return instead of starting analysis with container-less/run_local.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize I removed that. Thanks for catching

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
Loading