Skip to content

Commit

Permalink
Merge pull request #480 from kubescape/sbom
Browse files Browse the repository at this point in the history
use ToolVersionMetadataKey from k8s-interface
  • Loading branch information
matthyx authored Feb 13, 2025
2 parents 497e9cb + 50bdde7 commit aaba2f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/inspektor-gadget/inspektor-gadget v0.36.1
github.com/kubescape/backend v0.0.25
github.com/kubescape/go-logger v0.0.23
github.com/kubescape/k8s-interface v0.0.183
github.com/kubescape/k8s-interface v0.0.188
github.com/kubescape/storage v0.0.158
github.com/moby/sys/mountinfo v0.7.2
github.com/opencontainers/go-digest v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,8 @@ github.com/kubescape/backend v0.0.25 h1:PLESA7KGJskebR5hiSqPeJ1cPQ8Ra+4yNYXKyIej
github.com/kubescape/backend v0.0.25/go.mod h1:FpazfN+c3Ucuvv4jZYCnk99moSBRNMVIxl5aWCZAEBo=
github.com/kubescape/go-logger v0.0.23 h1:5xh+Nm8eGImhFbtippRKLaFgsvlKE1ufvQhNM2P/570=
github.com/kubescape/go-logger v0.0.23/go.mod h1:Ayg7g769c7sXVB+P3fkJmbsJpoEmMmaUf9jeo+XuC3U=
github.com/kubescape/k8s-interface v0.0.183 h1:eTuHlKJkBYYA03AR/YGr4KUC+xnbV6SG0/8+yrt9Yrs=
github.com/kubescape/k8s-interface v0.0.183/go.mod h1:YjIAQtrK4nCy+XQ/6jwo+BqlLyJk7DN2Mx4pUcbzq10=
github.com/kubescape/k8s-interface v0.0.188 h1:muG8qzXqA3dQ0myreg/V4DgxLx5A2S+Jj6Ur+OJCefc=
github.com/kubescape/k8s-interface v0.0.188/go.mod h1:j9snZbH+RxOaa1yG/bWgTClj90q7To0rGgQepxy4b+k=
github.com/kubescape/storage v0.0.158 h1:TbI1/rrRq+0gNbbPl8Z1weik0ShTWPJfy8lXjnzaDjw=
github.com/kubescape/storage v0.0.158/go.mod h1:K3QWf+zcXmXxfeQ2HD0dd0bF4FJ5gbxLTRZ7nx4dHXw=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand Down
21 changes: 10 additions & 11 deletions pkg/sbommanager/v1/sbom_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ import (
)

const (
digestDelim = "@"
NodeNameMetadataKey = "kubescape.io/node-name"
ToolVersionMetadataKey = "kubescape.io/tool-version"
digestDelim = "@"
NodeNameMetadataKey = "kubescape.io/node-name"
)

type SbomManager struct {
Expand Down Expand Up @@ -187,11 +186,11 @@ func (s *SbomManager) processContainer(notif containercollection.PubSubEvent) {
ObjectMeta: metav1.ObjectMeta{
Name: sbomName,
Annotations: map[string]string{
helpersv1.ImageIDMetadataKey: imageID,
helpersv1.ImageTagMetadataKey: sharedData.ImageTag,
helpersv1.StatusMetadataKey: helpersv1.Initializing,
NodeNameMetadataKey: s.cfg.NodeName,
ToolVersionMetadataKey: s.version,
helpersv1.ImageIDMetadataKey: imageID,
helpersv1.ImageTagMetadataKey: sharedData.ImageTag,
helpersv1.StatusMetadataKey: helpersv1.Initializing,
NodeNameMetadataKey: s.cfg.NodeName,
helpersv1.ToolVersionMetadataKey: s.version,
},
Labels: labelsFromImageID(imageID),
},
Expand Down Expand Up @@ -222,7 +221,7 @@ func (s *SbomManager) processContainer(notif containercollection.PubSubEvent) {
return
case wipSbom.Annotations[helpersv1.StatusMetadataKey] == helpersv1.Ready:
// only skip if the SBOM was created with the same version of tool
if wipSbom.Annotations[ToolVersionMetadataKey] == s.version {
if wipSbom.Annotations[helpersv1.ToolVersionMetadataKey] == s.version {
logger.L().Debug("SbomManager - SBOM is already created, skipping",
helpers.String("namespace", notif.Container.K8s.Namespace),
helpers.String("pod", notif.Container.K8s.PodName),
Expand All @@ -235,10 +234,10 @@ func (s *SbomManager) processContainer(notif containercollection.PubSubEvent) {
helpers.String("pod", notif.Container.K8s.PodName),
helpers.String("container", notif.Container.K8s.ContainerName),
helpers.String("sbomName", sbomName),
helpers.String("got version", wipSbom.Annotations[ToolVersionMetadataKey]),
helpers.String("got version", wipSbom.Annotations[helpersv1.ToolVersionMetadataKey]),
helpers.String("expected version", s.version))
// update the version of the tool
wipSbom.Annotations[ToolVersionMetadataKey] = s.version
wipSbom.Annotations[helpersv1.ToolVersionMetadataKey] = s.version
// continue to create SBOM
case wipSbom.Annotations[NodeNameMetadataKey] != s.cfg.NodeName:
logger.L().Debug("SbomManager - SBOM is already being processed by another node, skipping",
Expand Down

0 comments on commit aaba2f0

Please sign in to comment.