Skip to content

Commit

Permalink
Merge pull request #293 from leanix/bugfix/HEL-2791
Browse files Browse the repository at this point in the history
bugfix/HEL-2791
  • Loading branch information
daniellesarmiento authored Jun 20, 2023
2 parents 890ece2 + cbe1273 commit fe4903b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/iris/common/services/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import (

func FilterForDeletedItems(oldResultMap map[string]models.DiscoveryEvent, workspaceId string, configId string, runId string) ([]models.DiscoveryEvent, error) {
deletedEvents := make([]models.DiscoveryEvent, 0)
for _, oldItem := range oldResultMap {
for id, oldItem := range oldResultMap {
if oldItem.HeaderProperties.Class == models.EventClassNamespace {
mappedData, err := ParseNamespaceData(oldItem)
if err != nil {
return nil, err
}
deletedEvent := namespace.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionDeleted, *mappedData, workspaceId, configId)
deletedEvent := namespace.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionDeleted, id, *mappedData, workspaceId, configId)
deletedEvents = append(deletedEvents, deletedEvent)
} else if oldItem.HeaderProperties.Class == models.EventClassWorkload {
mappedData, err := ParseWorkloadData(oldItem)
if err != nil {
return nil, err
}
deletedEvent := workload.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionDeleted, *mappedData, runId, workspaceId, configId)
deletedEvent := workload.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionDeleted, id, *mappedData, runId, workspaceId, configId)
deletedEvents = append(deletedEvents, deletedEvent)
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/iris/namespaces/models/eventsEcst.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ func (eb *ecstEventBuilder) Build() models.DiscoveryEvent {
}

// CreateEcstDiscoveryEvent ECST Discovery Items
func CreateEcstDiscoveryEvent(eventType string, changeAction string, data Data, workspaceId string, configId string) models.DiscoveryEvent {
func CreateEcstDiscoveryEvent(eventType string, changeAction string, id string, data Data, workspaceId string, configId string) models.DiscoveryEvent {
// Metadata for the event
id := GenerateId(workspaceId, configId, data)
time := time2.Now().Format(time2.RFC3339)

var header models.HeaderProperties
Expand Down
4 changes: 2 additions & 2 deletions pkg/iris/namespaces/services/events/eventProducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (p *eventProducer) FilterForChangedItems(newData map[string]namespace.Data,
for id, newItem := range newData {
// if the current element from the freshly discovered items is not in the old results, create an CREATED event
if oldItem, ok := oldData[id]; !ok {
createdEcstDiscoveryEvent := namespace.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionCreated, newItem, p.workspaceId, configId)
createdEcstDiscoveryEvent := namespace.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionCreated, id, newItem, p.workspaceId, configId)
created = append(created, createdEcstDiscoveryEvent)
// if item has been discovered before, check if there are any changes in the new payload
} else {
Expand All @@ -119,7 +119,7 @@ func (p *eventProducer) FilterForChangedItems(newData map[string]namespace.Data,
}

if oldItemHash != newItemHash {
updated = append(updated, namespace.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionUpdated, newItem, p.workspaceId, configId))
updated = append(updated, namespace.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionUpdated, id, newItem, p.workspaceId, configId))
}
// Remove key from oldData results, so we only have the entries inside which shall be deleted
delete(oldData, id)
Expand Down
2 changes: 1 addition & 1 deletion pkg/iris/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (
WORKLOAD string = "WORKLOAD"
)

const StatusErrorFormat = "Scan failed while posting status. RunId: '%s', with reason: '%v'"
const StatusErrorFormat = "Scan failed while posting status. Run Id: '%s', with reason: '%v'"

func (s *scanner) Scan(getKubernetesAPI kubernetes.GetKubernetesAPI, config *rest.Config, configurationName string) error {
configuration, err := s.configService.GetConfiguration(configurationName)
Expand Down
3 changes: 1 addition & 2 deletions pkg/iris/workloads/models/eventsEcst.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ func (cb *commandBuilder) Build() models.CommandEvent {
}

// CreateEcstDiscoveryEvent ECST Discovery Items
func CreateEcstDiscoveryEvent(eventType string, changeAction string, data Data, runId string, workspaceId string, configId string) models.DiscoveryEvent {
func CreateEcstDiscoveryEvent(eventType string, changeAction string, id string, data Data, runId string, workspaceId string, configId string) models.DiscoveryEvent {
// Metadata for the event
id := GenerateId(workspaceId, configId, data)
time := time2.Now().Format(time2.RFC3339)

var header models.HeaderProperties
Expand Down
4 changes: 2 additions & 2 deletions pkg/iris/workloads/services/events/eventProducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (p *workloadEventProducer) FilterForChangedItems(newData map[string]workloa
for id, newItem := range newData {
// if the current element from the freshly discovered items is not in the old results, create an CREATED event
if oldItem, ok := oldData[id]; !ok {
createdEcstDiscoveryEvent := workload.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionCreated, newItem, p.runId, p.workspaceId, configId)
createdEcstDiscoveryEvent := workload.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionCreated, id, newItem, p.runId, p.workspaceId, configId)
created = append(created, createdEcstDiscoveryEvent)
// if item has been discovered before, check if there are any changes in the new payload
} else {
Expand All @@ -119,7 +119,7 @@ func (p *workloadEventProducer) FilterForChangedItems(newData map[string]workloa
}

if oldItemHash != newItemHash {
updated = append(updated, workload.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionUpdated, newItem, p.runId, p.workspaceId, configId))
updated = append(updated, workload.CreateEcstDiscoveryEvent(models.EventTypeChange, models.EventActionUpdated, id, newItem, p.runId, p.workspaceId, configId))
}
// Remove key from oldData results, so we only have the entries inside which shall be deleted
delete(oldData, id)
Expand Down

0 comments on commit fe4903b

Please sign in to comment.