Skip to content
Closed
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 SCANNER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.27.x-28-g9c465e66e0
2.27.x-33-g4527742727
4 changes: 4 additions & 0 deletions central/imageintegration/service/service_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (*fakeNodeScanner) GetNodeScan(*storage.Node) (*storage.NodeScan, error) {
panic("implement me")
}

func (*fakeNodeScanner) GetNodeInventoryScan(node *storage.Node, inv *storage.NodeInventory) (*storage.NodeScan, error) {
panic("implement me")
}

func (*fakeNodeScanner) TestNodeScanner() error {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions central/sensor/service/pipeline/all/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"github.com/stackrox/rox/central/sensor/service/pipeline/namespaces"
"github.com/stackrox/rox/central/sensor/service/pipeline/networkflowupdate"
"github.com/stackrox/rox/central/sensor/service/pipeline/networkpolicies"
"github.com/stackrox/rox/central/sensor/service/pipeline/nodeinventory"
"github.com/stackrox/rox/central/sensor/service/pipeline/nodes"
"github.com/stackrox/rox/central/sensor/service/pipeline/nodescansv2"
"github.com/stackrox/rox/central/sensor/service/pipeline/podevents"
"github.com/stackrox/rox/central/sensor/service/pipeline/processindicators"
"github.com/stackrox/rox/central/sensor/service/pipeline/reprocessing"
Expand Down Expand Up @@ -66,7 +66,7 @@ func (s *factoryImpl) PipelineForCluster(ctx context.Context, clusterID string)
auditlogstateupdate.GetPipeline(),
}
if features.RHCOSNodeScanning.Enabled() {
pipelines = append(pipelines, nodescansv2.GetPipeline())
pipelines = append(pipelines, nodeinventory.GetPipeline())
}
if features.ComplianceOperatorCheckResults.Enabled() {
pipelines = append(pipelines,
Expand Down
95 changes: 95 additions & 0 deletions central/sensor/service/pipeline/nodeinventory/pipeline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package nodeinventory

import (
"context"

"github.com/pkg/errors"
clusterDataStore "github.com/stackrox/rox/central/cluster/datastore"
"github.com/stackrox/rox/central/enrichment"
countMetrics "github.com/stackrox/rox/central/metrics"
nodeDatastore "github.com/stackrox/rox/central/node/datastore/dackbox/datastore"
"github.com/stackrox/rox/central/risk/manager"
"github.com/stackrox/rox/central/sensor/service/common"
"github.com/stackrox/rox/central/sensor/service/pipeline"
"github.com/stackrox/rox/central/sensor/service/pipeline/reconciliation"
"github.com/stackrox/rox/generated/internalapi/central"
"github.com/stackrox/rox/pkg/logging"
"github.com/stackrox/rox/pkg/metrics"
"github.com/stackrox/rox/pkg/nodes/enricher"
)

var (
log = logging.LoggerForModule()
)

// GetPipeline returns an instantiation of this particular pipeline
func GetPipeline() pipeline.Fragment {
return NewPipeline(clusterDataStore.Singleton(), nodeDatastore.Singleton(), enrichment.NodeEnricherSingleton(), manager.Singleton())
}

// NewPipeline returns a new instance of Pipeline.
func NewPipeline(clusters clusterDataStore.DataStore, nodes nodeDatastore.DataStore, enricher enricher.NodeEnricher, riskManager manager.Manager) pipeline.Fragment {
return &pipelineImpl{
clusterStore: clusters,
nodeDatastore: nodes,
enricher: enricher,
riskManager: riskManager,
}
}

type pipelineImpl struct {
clusterStore clusterDataStore.DataStore
nodeDatastore nodeDatastore.DataStore
enricher enricher.NodeEnricher
riskManager manager.Manager
}

func (p *pipelineImpl) Reconcile(ctx context.Context, clusterID string, storeMap *reconciliation.StoreMap) error {
return nil
}

func (p *pipelineImpl) Match(msg *central.MsgFromSensor) bool {
return msg.GetEvent().GetNodeInventory() != nil
}

// Run runs the pipeline template on the input and returns the output.
func (p *pipelineImpl) Run(ctx context.Context, clusterID string, msg *central.MsgFromSensor, _ common.MessageInjector) error {
defer countMetrics.IncrementResourceProcessedCounter(pipeline.ActionToOperation(msg.GetEvent().GetAction()), metrics.NodeInventory)

event := msg.GetEvent()
ninv := event.GetNodeInventory()
if ninv == nil {
return errors.Errorf("unexpected resource type %T for node inventory", event.GetResource())
}

if event.GetAction() == central.ResourceAction_REMOVE_RESOURCE {
// NodeInventory will never be deleted
return nil
}

ninv = ninv.Clone()

node, found, err := p.nodeDatastore.GetNode(ctx, ninv.GetNodeId())
if err != nil || !found {
log.Warnf("Node ID %s not found when processing NodeInventory", ninv.GetNodeId())
return errors.WithMessagef(err, "processing node inventory for node '%s'", ninv.GetNodeId())
}
log.Debugf("Node ID %s found. Will enrich Node with NodeInventory", ninv.GetNodeId())

err = p.enricher.EnrichNodeWithInventory(node, ninv)
if err != nil {
log.Warnf("enriching node with node inventory %s:%s: %v", node.GetClusterName(), node.GetName(), err)
}

// Here NodeInventory stops to matter. All data required for the DB and UI is in node.NodeScan already

if err := p.riskManager.CalculateRiskAndUpsertNode(node); err != nil {
err = errors.Wrapf(err, "upserting node %s:%s into datastore", node.GetClusterName(), node.GetName())
log.Error(err)
return err
}

return nil
}

func (p *pipelineImpl) OnFinish(_ string) {}
57 changes: 0 additions & 57 deletions central/sensor/service/pipeline/nodescansv2/pipeline.go

This file was deleted.

2 changes: 2 additions & 0 deletions compliance/collection/nodeinventorizer/fake_nodeinventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
timestamp "github.com/gogo/protobuf/types"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/pkg/logging"
"github.com/stackrox/rox/pkg/uuid"
)

var (
Expand All @@ -18,6 +19,7 @@ type FakeNodeInventorizer struct {
func (f *FakeNodeInventorizer) Scan(nodeName string) (*storage.NodeInventory, error) {
log.Infof("Generating fake scan result message...")
msg := &storage.NodeInventory{
NodeId: uuid.Nil.String(),
NodeName: nodeName,
ScanTime: timestamp.TimestampNow(),
Components: &storage.NodeInventory_Components{
Expand Down
2 changes: 2 additions & 0 deletions compliance/collection/nodeinventorizer/nodeinventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nodeinventorizer
import (
timestamp "github.com/gogo/protobuf/types"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/pkg/uuid"
"github.com/stackrox/scanner/database"
scannerV1 "github.com/stackrox/scanner/generated/scanner/api/v1"
"github.com/stackrox/scanner/pkg/analyzer/nodes"
Expand Down Expand Up @@ -41,6 +42,7 @@ func (n *NodeInventoryCollector) Scan(nodeName string) (*storage.NodeInventory,
// which only exists in certified versions. Therefore, no specific notes needed
// if uncertifiedRHEL can be true in the future, we can add Note_CERTIFIED_RHEL_SCAN_UNAVAILABLE
m := &storage.NodeInventory{
NodeId: uuid.Nil.String(),
NodeName: nodeName,
ScanTime: timestamp.TimestampNow(),
Components: protoComponents,
Expand Down
Loading