Skip to content

Commit

Permalink
🐛 Prevent k8s scan panic
Browse files Browse the repository at this point in the history
When scanning k8s with container image discovery, it paniced.
That happened because asset data was missing.

Fixes #1749

Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker committed Sep 19, 2023
1 parent 03484e0 commit 95be17b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,11 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
log.Error().Err(err).Msg("unable to connect to asset")
continue
}
inventorySpec := runtime.Provider.Connection
if inventorySpec.Inventory != nil &&
inventorySpec.Inventory.Spec != nil &&
inventorySpec.Inventory.Spec.Assets != nil {
log.Debug().Msgf("adding %d discovered asset(s)", len(runtime.Provider.Connection.Inventory.Spec.Assets))
assetCandidates = append(assetCandidates, inventorySpec.Inventory.Spec.Assets...)
} else {
assetCandidates = append(assetCandidates, runtime.Provider.Connection.Asset)
processedAssets, err := providers.ProcessAssetCandidates(runtime, runtime.Provider.Connection, upstream, "")
if err != nil {
return nil, false, err
}
assetCandidates = append(assetCandidates, processedAssets...)
// TODO: we want to keep better track of errors, since there may be
// multiple assets coming in. It's annoying to abort the scan if we get one
// error at this stage.
Expand Down Expand Up @@ -239,7 +235,12 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up

justAssets := []*inventory.Asset{}
for _, asset := range assets {
asset.asset.KindString = asset.asset.GetPlatform().Kind
if asset.asset.GetPlatform() != nil {
asset.asset.KindString = asset.asset.GetPlatform().Kind
} else {
asset.asset = asset.runtime.Provider.Connection.Asset
asset.asset.KindString = asset.runtime.Provider.Connection.Asset.Platform.Kind
}
justAssets = append(justAssets, asset.asset)
}

Expand Down

0 comments on commit 95be17b

Please sign in to comment.