Skip to content

Commit

Permalink
fix handling of cross-provider assets discovery for run command
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Sep 4, 2023
1 parent fc33b15 commit 1a93e86
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
44 changes: 43 additions & 1 deletion apps/cnquery/cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,49 @@ func (c *cnqueryPlugin) RunQuery(conf *run.RunQueryConfig, runtime *providers.Ru
}
}

for i := range filteredAssets {
for _, asset := range filteredAssets {
// If the assets have platform IDs, then we have already connected to them via the
// current provider.
if len(asset.PlatformIds) > 0 {
continue
}

// Make sure the provider for the asset is present
if err := runtime.DetectProvider(asset); err != nil {
return err
}

err := runtime.Connect(&pp.ConnectReq{
Features: config.Features,
Asset: asset,
Upstream: upstreamConfig,
})
if err != nil {
return err
}
}

// TODO: filter unique assets by platform ID
uniqueAssets := []*inventory.Asset{}
platformIds := map[string]struct{}{}
for _, asset := range filteredAssets {
found := false
for _, platformId := range asset.PlatformIds {
if _, ok := platformIds[platformId]; ok {
found = true
}
}
if found {
continue
}

uniqueAssets = append(uniqueAssets, asset)
for _, platformId := range asset.PlatformIds {
platformIds[platformId] = struct{}{}
}
}

for i := range uniqueAssets {
connectAsset := filteredAssets[i]
if err := runtime.DetectProvider(connectAsset); err != nil {
return err
Expand Down
16 changes: 0 additions & 16 deletions providers/k8s/resources/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,22 +623,6 @@ func discoverContainerImages(runtime *plugin.Runtime, invConfig *inventory.Confi
})
}

// Convert the container images to assets.
// assets := make(map[string]*inventory.Asset)
// for _, i := range runningImages {
// a, err := newPodImageAsset(i)
// if err != nil {
// log.Error().Err(err).Msg("failed to convert container image to asset")
// continue
// }

// // It is still possible to have unique images at this point. There might be
// // multiple image tags that actually point to the same digest. If we are scanning
// // a manifest, where there is no container status, we can only know that the 2 images
// // are identical after we resolve them with the container registry.
// assets[a.Labels["docker.io/digest"]] = a
// log.Debug().Str("name", a.Name).Str("image", a.Connections[0].Host).Msg("resolved pod")
// }
return assetList, nil
}

Expand Down

0 comments on commit 1a93e86

Please sign in to comment.