Skip to content

Commit

Permalink
fix: properly maintain imageMap for dtrack
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Kotzbauer <git@ckotzbauer.de>
  • Loading branch information
ckotzbauer committed Oct 1, 2022
1 parent 70abfcc commit 862539a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/target/dtrack/dtrack_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func (g *DependencyTrackTarget) ProcessSbom(ctx *target.TargetContext) error {
logrus.WithError(err).Errorf("Could not update project tags")
}

if g.imageProjectMap == nil {
// prepropulate imageProjectMap
g.LoadImages()
}

g.imageProjectMap[ctx.Image.ImageID] = project.UUID
return nil
}

Expand Down Expand Up @@ -177,7 +183,7 @@ func (g *DependencyTrackTarget) Remove(images []*libk8s.RegistryImage) {

for _, img := range images {
uuid := g.imageProjectMap[img.ImageID]
if uuid.String() == "" {
if uuid.String() == "00000000-0000-0000-0000-000000000000" {
logrus.Warnf("No project found for imageID: %s", img.ImageID)
continue
}
Expand All @@ -199,6 +205,7 @@ func (g *DependencyTrackTarget) Remove(images []*libk8s.RegistryImage) {
logrus.Infof("Removing %v=%v tag from project %v", kubernetesCluster, g.k8sClusterId, currentImageName)
project.Tags = removeTag(project.Tags, kubernetesCluster+"="+g.k8sClusterId)
_, err := client.Project.Update(context.Background(), project)
delete(g.imageProjectMap, img.ImageID)
if err != nil {
logrus.WithError(err).Warnf("Project %s could not be updated", project.UUID.String())
}
Expand All @@ -215,6 +222,7 @@ func (g *DependencyTrackTarget) Remove(images []*libk8s.RegistryImage) {
if sbomOperatorPropFound && len(otherClusterIds) == 0 {
logrus.Infof("Image not running in any cluster - removing %v", currentImageName)
err := client.Project.Delete(context.Background(), project.UUID)
delete(g.imageProjectMap, img.ImageID)
if err != nil {
logrus.WithError(err).Warnf("Project %s could not be deleted", project.UUID.String())
}
Expand Down

0 comments on commit 862539a

Please sign in to comment.