Skip to content

Commit

Permalink
add owner tags for jobs and pods (tailwarden#1064)
Browse files Browse the repository at this point in the history
* add cronJob support

Signed-off-by: shubhindia <[email protected]>

* drop fmt.Printf()

Signed-off-by: shubhindia <[email protected]>

* don't use separate cronJob collector

Signed-off-by: shubhindia <[email protected]>

* use owner_kind instead of owner

Signed-off-by: shubhindia <[email protected]>

* add owner tags for pods as well

Signed-off-by: shubhindia <[email protected]>

---------

Signed-off-by: shubhindia <[email protected]>
Co-authored-by: Azanul Haque <[email protected]>
  • Loading branch information
shubhindia and Azanul authored Oct 10, 2023
1 parent 5513ebe commit 476b273
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
17 changes: 16 additions & 1 deletion providers/k8s/core/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ func Jobs(ctx context.Context, client providers.ProviderClient) ([]models.Resour
})
}

if len(job.OwnerReferences) > 0 {
// we use the owner kind of first owner only as the owner tag
ownerTags := []models.Tag{
{
Key: "owner_kind",
Value: job.OwnerReferences[0].Kind,
},
{
Key: "owner_name",
Value: job.OwnerReferences[0].Name,
},
}
tags = append(tags, ownerTags...)
}

cost := 0.0
if opencostEnabled {
cost = jobsCost[job.Name].TotalCost
Expand Down Expand Up @@ -70,7 +85,7 @@ func Jobs(ctx context.Context, client providers.ProviderClient) ([]models.Resour
log.WithFields(log.Fields{
"provider": "Kubernetes",
"account": client.Name,
"service": "DaemonSet",
"service": "Job",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
Expand Down
15 changes: 15 additions & 0 deletions providers/k8s/core/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ func Pods(ctx context.Context, client providers.ProviderClient) ([]models.Resour
})
}

if len(pod.OwnerReferences) > 0 {
// we use the owner kind of first owner only as the owner tag
ownerTags := []models.Tag{
{
Key: "owner_kind",
Value: pod.OwnerReferences[0].Kind,
},
{
Key: "owner_name",
Value: pod.OwnerReferences[0].Name,
},
}
tags = append(tags, ownerTags...)
}

cost := 0.0
if opencostEnabled {
cost = podsCost[pod.Name].TotalCost
Expand Down

0 comments on commit 476b273

Please sign in to comment.