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

Adds Insight Label Processing #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions default_filter_transformers.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
}
],
"keyfact": true
},
{
"type": "handler.InsightsInspectLabel",
"keyfact": true
}
]
}
File renamed without changes.
51 changes: 48 additions & 3 deletions internal/handler/imageInspectParserFilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ func processImageInspectInsightsData(h *Messaging, insights InsightsData, v stri
return nil, "", err
}

facts, err := processFactsFromImageInspect(imageInspect, environment.Id, source)
facts, err := processEnvironmentVariableFactsFromImageInspect(imageInspect, environment.Id, source)
if err != nil {
return nil, "", err
}
labelFacts, err := processLabelFactsFromImageInspect(imageInspect, environment.Id, source)
if err != nil {
return nil, "", err
}
facts = append(facts, labelFacts...)
log.Printf("Successfully decoded image-inspect")

facts, err = KeyFactsFilter(facts)
if err != nil {
return nil, "", err
Expand All @@ -60,7 +64,48 @@ func processImageInspectInsightsData(h *Messaging, insights InsightsData, v stri
return []LagoonFact{}, "", nil
}

func processFactsFromImageInspect(imageInspectData ImageData, id int, source string) ([]LagoonFact, error) {
func processLabelFactsFromImageInspect(imageInspectData ImageData, id int, source string) ([]LagoonFact, error) {
var factsInput []LagoonFact

var filteredFacts []InsightsInspectLabel
keyFactsExistMap := make(map[string]bool)

// Check if image inspect contains useful environment variables
if imageInspectData.Labels != nil {
for k, v := range imageInspectData.Labels {

env := InsightsInspectLabel{
Key: k,
Value: v,
}

// Remove duplicate key facts
if _, ok := keyFactsExistMap[env.Key]; !ok {
keyFactsExistMap[env.Key] = true
filteredFacts = append(filteredFacts, env)
}
}
}

for _, f := range filteredFacts {

fact := LagoonFact{
Environment: id,
Name: f.Key,
Value: f.Value,
Source: source,
Description: "Insights Inspect Label",
KeyFact: false,
Type: FactTypeText,
}
fmt.Println("Processing fact name " + f.Key)
fact, _ = ProcessLagoonFactAgainstRegisteredFilters(fact, f)
factsInput = append(factsInput, fact)
}
return factsInput, nil
}

func processEnvironmentVariableFactsFromImageInspect(imageInspectData ImageData, id int, source string) ([]LagoonFact, error) {
var factsInput []LagoonFact

var filteredFacts []EnvironmentVariable
Expand Down
5 changes: 5 additions & 0 deletions internal/handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ type EnvironmentVariable struct {
Value string
}

type InsightsInspectLabel struct {
Key string
Value string
}

type ResourceDestination struct {
Project string
Environment string
Expand Down