Skip to content

⭐️ add annotations support for scanned assets#1379

Merged
chris-rock merged 5 commits intomainfrom
add-annotations-to-scanned-assets
Feb 9, 2026
Merged

⭐️ add annotations support for scanned assets#1379
chris-rock merged 5 commits intomainfrom
add-annotations-to-scanned-assets

Conversation

@chris-rock
Copy link
Copy Markdown
Member

Summary

  • Adds annotations field to MondooAuditConfigSpec to allow users to define custom key-value pairs
  • Annotations are attached to all scanned assets, making them searchable and filterable in the Mondoo Console
  • Supports all scan types: K8s resources, nodes, container images, and resource watcher

Usage Example

apiVersion: k8s.mondoo.com/v1alpha2
kind: MondooAuditConfig
metadata:
  name: mondoo-client
spec:
  mondooCredsSecretRef:
    name: mondoo-credentials
  annotations:
    environment: production
    team: platform
    cost-center: "12345"
  kubernetesResources:
    enable: true
  nodes:
    enable: true

Implementation

Annotations are passed to cnspec via:

  • Inventory files: For K8s resources, nodes, and container image scans (using Asset.AddAnnotations())
  • Command-line flags: For the resource watcher (--annotation key=value)

Test plan

  • make lint passes
  • make test passes
  • Deploy operator with annotations configured and verify they appear on assets in Mondoo Console

Closes #955

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 6, 2026

Test Results

  5 files  ± 0   42 suites  +1   33m 25s ⏱️ +19s
327 tests +21  327 ✅ +21  0 💤 ±0  0 ❌ ±0 
346 runs  +21  344 ✅ +21  2 💤 ±0  0 ❌ ±0 

Results for commit 675d6b0. ± Comparison against base commit e85aae5.

♻️ This comment has been updated with latest results.

@chris-rock
Copy link
Copy Markdown
Member Author

Also fixes #465

@chris-rock chris-rock force-pushed the add-annotations-to-scanned-assets branch from 99bf72f to 072c03e Compare February 6, 2026 18:26
chris-rock and others added 4 commits February 9, 2026 13:10
Add the ability to define custom annotations in MondooAuditConfig that get
attached to all scanned assets. This allows users to tag their assets with
key-value pairs for better searchability and filtering in the Mondoo Console.

The annotations are passed to cnspec via:
- Inventory file annotations for K8s resources, nodes, and container scans
- Command-line --annotation flags for the resource watcher

Closes #955

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sort annotation map keys before building CLI args to prevent spurious
Kubernetes Deployment updates caused by Go's randomized map iteration.
Add tests for annotation propagation across all scan controllers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Extract duplicated annotation CLI arg building into pkg/annotations.AnnotationArgs()
- Add annotations.Validate() to reject empty keys, keys containing '=', and empty values
- Call validation in the reconciler and resource-watcher CLI entrypoint
- Strengthen test assertions to unmarshal inventory YAML and check asset annotations directly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ions

Instead of returning an error (which causes infinite requeue with backoff),
set MondooOperatorDegraded condition so users can see the problem via
kubectl describe. The condition is cleared when annotations become valid.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chris-rock
Copy link
Copy Markdown
Member Author

Future improvement: annotation validation should not skip full reconciliation

When annotations fail validation, the controller currently does return ctrl.Result{}, nil at the annotation check (mondooauditconfig_controller.go:238), which skips ALL remaining reconciliation — not just annotation-related work. This means changes to schedules, enabling/disabling scan types, credential rotation, etc. are all blocked until annotations are fixed.

A future improvement would be to continue reconciliation with Annotations: nil (or the previous valid set) while in a degraded state, so that other spec changes are not blocked by an annotation typo.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chris-rock chris-rock force-pushed the add-annotations-to-scanned-assets branch from 04a3430 to 675d6b0 Compare February 9, 2026 12:21

// AnnotationArgs converts a map of annotations into sorted CLI arguments
// suitable for passing to cnspec via --annotation key=value flags.
func AnnotationArgs(annotations map[string]string) []string {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we may want to switch to inventory files for every scan job. That would make it more straight forward to support additional features.

Copy link
Copy Markdown
Member

@imilchev imilchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chris-rock chris-rock merged commit 704981c into main Feb 9, 2026
24 checks passed
@chris-rock chris-rock deleted the add-annotations-to-scanned-assets branch February 9, 2026 15:08
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add tags to scanned k8s objects

2 participants