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

⭐ Allow enabling pod discovery with an env var #473

Merged
merged 3 commits into from
Jul 28, 2022
Merged
Changes from 1 commit
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
20 changes: 18 additions & 2 deletions pkg/mondooclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io/ioutil"
"net"
"net/http"
"os"
"time"

"go.mondoo.com/mondoo-operator/pkg/constants"
Expand All @@ -38,6 +39,13 @@ const (
maxIdleConnections = 100
)

var enablePodDiscovery bool

func init() {
_, ok := os.LookupEnv("SCAN_DISCOVER_PODS")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need some way to pass down this environment variable from the mondoo-operator Deployment to the generated CronJob definitions that will instantiate their own MondooClient?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we do. I just added the var to the client but forgot that it's called from the CronJob and not from the operator. Will update that once we can actually test it

enablePodDiscovery = ok
}

//go:generate ./../../bin/mockgen -source=./client.go -destination=./mock/client_generated.go -package=mock

type Client interface {
Expand Down Expand Up @@ -269,10 +277,18 @@ func (s *mondooClient) ScanKubernetesResources(ctx context.Context, integrationM
scanJob.Inventory.Spec.Assets[0].Labels[constants.MondooAssetsIntegrationLabel] = integrationMrn
}

if scanContainerImages {
scanJob.Inventory.Spec.Assets[0].Connections[0].Discover.Targets = []string{"container-images"}
if scanContainerImages || enablePodDiscovery {
scanJob.Inventory.Spec.Assets[0].Connections[0].Options = make(map[string]string)
scanJob.Inventory.Spec.Assets[0].Connections[0].Options["all-namespaces"] = "true"

}

if scanContainerImages {
scanJob.Inventory.Spec.Assets[0].Connections[0].Discover.Targets = append(scanJob.Inventory.Spec.Assets[0].Connections[0].Discover.Targets, "container-images")
}

if enablePodDiscovery {
scanJob.Inventory.Spec.Assets[0].Connections[0].Discover.Targets = append(scanJob.Inventory.Spec.Assets[0].Connections[0].Discover.Targets, "pods")
}

reqBodyBytes, err := json.Marshal(scanJob)
Expand Down