This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
make build- Compiles the insights-operator binary to./bin/insights-operatormake build-debug- Compiles with debug symbols for debuggingmake testormake unit- Runs unit tests with race detection and coverage profilingVERBOSE=-v make unit- Run unit tests with verbose outputVERBOSE=-count=1 make test- Run tests without caching
make lint- Run golangci-lint with project configuration (requires golangci-lint >= 1.39)make precommit- Execute pre-commit hook (checks stashed changes)make githooks- Configure repository to use git hooks (recommended setup)
make run- Execute insights-operator with default config (config/local.yaml)CONFIG=config/custom.yaml make run- Run with custom configurationbin/insights-operator start --config=config/local.yaml --kubeconfig=$KUBECONFIG- Direct execution
make build-container- Build container image using podman/dockermake build-debug-container- Build debug container image
make docs- Generate gathered-data documentation from code commentsmake changelog- Update changelog (requires GITHUB_TOKEN environment variable)make vendor- Update Go module dependencies (go mod tidy && go mod vendor && go mod verify)
The Insights Operator is a Kubernetes operator that periodically gathers anonymized cluster data and uploads it to Red Hat Insights for analysis.
Main Entry Point: cmd/insights-operator/main.go - Sets up cobra CLI with subcommands for start, receive, gather, and gather-and-upload operations.
Operator Controller: pkg/controller/operator.go - Main operator logic that coordinates periodic data gathering, uploading, and status reporting.
pkg/gather/- Data gathering logic and gatherer implementationspkg/gatherers/- Three main gatherer types:clusterconfig/- Regular cluster configuration gathering (default 2h interval)workloads/- Workload fingerprint data (12h interval, not configurable)conditional/- Conditional gathering based on external rules from console.redhat.com
pkg/insights/- Insights client for uploading/downloading data and reportspkg/config/- Configuration management and observationpkg/controller/- Operator controllers and status managementgather_commands.go- ContainsGatherJobtype for non-periodic gathering (gather, gather-and-upload commands)operator.go- MainOperatortype for periodic gathering in production
pkg/recorder/- Archive recording and disk managementpkg/anonymization/- Data obfuscation and anonymization
The operator reads configuration from multiple sources (in order of precedence):
insights-configConfigMap inopenshift-insightsnamespacesupportSecret inopenshift-confignamespace- Default configuration from
config/pod.yaml
Authentication uses tokens from the pull-secret secret in openshift-config namespace.
The operator uses wait.Until for periodic tasks:
- Gatherer: Collects cluster data
- Uploader: Uploads archives to console.redhat.com
- Downloader: Downloads Insights analysis reports
- Config Observer: Monitors configuration changes (5min interval)
- Disk Pruner: Removes old archives (runs every second interval)
- SCA Controller: Simple Content Access certificate management
- Cluster Transfer Controller: Handles cluster transfer operations
operator: Main service account for the insights-operator deploymentgather: Privileged service account for cluster-wide data gathering (impersonated by operator)
The Insights Operator uses two main CRDs defined in the openshift/api repository (both v1alpha2):
Provides configuration and status for on-demand Insights data gathering (TechPreview):
- Purpose: Trigger and configure individual data gathering operations
- Key spec fields:
dataPolicy- Optional obfuscation settings (ObfuscateNetworking, WorkloadNames)gatherers- Optional gatherer configuration (All or Custom mode with enable/disable per gatherer)storage- Optional persistent storage configuration (PersistentVolume or Ephemeral)
- Key status fields:
conditions- Status of gathering phases (DataUploaded, DataRecorded, DataProcessed, RemoteConfiguration*)gatherers- Individual gatherer statuses with execution timeinsightsRequestID- Tracking ID for console.redhat.com processinginsightsReport- Downloaded analysis with health checks and recommendationsstartTime/finishTime- Gathering execution timestamps
- Feature gate:
InsightsOnDemandDataGather - Usage: Created automatically for periodic gathering or manually for on-demand gathering
- Scope: Cluster-scoped resource
Provides global configuration for Insights data gathering (TechPreview):
- Purpose: Configure cluster-wide Insights gathering behavior
- Key spec fields:
gatherConfig.dataPolicy- Global obfuscation options (ObfuscateNetworking, WorkloadNames)gatherConfig.gatherers- Gatherer mode configuration (All, None, or Custom)gatherConfig.storage- Persistent storage configuration for gathering jobs
- Gathering modes:
All- All gatherers run and gather dataNone- All gatherers disabled, no data gatheredCustom- Fine-grained control via custom configuration
- Feature gate:
InsightsConfig - Usage: Singleton cluster-scoped resource named "cluster"
- Scope: Cluster-scoped resource
The operator has three main gatherers that run periodically:
- Cluster Config Gatherer (
pkg/gatherers/clusterconfig/) - Collects cluster configuration (default 2h interval) - Workloads Gatherer (
pkg/gatherers/workloads/) - Collects workload fingerprints (12h interval, not configurable) - Conditional Gatherer (
pkg/gatherers/conditional/) - Collects data based on external rules (see below)
The operator supports on-demand gathering via DataGather custom resources:
- GatherAndUpload workflow (
pkg/controller/gather_commands.go):- Creates gatherers and executes data collection
- Records data to archive
- Uploads archive to console.redhat.com
- Polls processing status endpoint to verify data was processed
- Updates
DataGatherCR status with results
- Processing status polling (
wasDataProcessedfunction):- Polls
insights-results-aggregatorservice with InsightsRequestID - Retries independently for network errors, HTTP errors, and processing status
- Uses configurable delay between retries (from
DataReporting.ReportPullingDelay)
- Polls
Conditional gathering enables dynamic data collection based on external rules:
- Purpose: Collect specific data only when certain conditions are met (e.g., specific alerts firing)
- Workflow:
- Downloads gathering rules from console.redhat.com endpoint
- Validates rules against JSON schema (
pkg/gatherers/conditional/gathering_rules.schema.json) - Evaluates conditions (alert firing, cluster version, etc.)
- Executes matching gathering functions with parameters
- Key features:
- Rules defined externally in
insights-operator-gathering-conditionsrepository - Conditions include: alert firing, cluster version ranges, and more
- JSON schema validation (fails safely if invalid)
- Requires Prometheus connection for alert-based conditions
- Gathers targeted data to reduce archive size
- Rules defined externally in
The Anonymizer (pkg/anonymization/) protects sensitive information before upload:
- Purpose: Obfuscate sensitive data (IPs, MAC addresses, hostnames) in gathered data
- Key features:
- Configurable via
DataPolicyin DataGather CR - Can disable specific anonymization types
- Applies to networking data, cluster infrastructure, and more
- Maintains consistency (same input always produces same obfuscated output)
- See
docs/anonymized-data.mdfor full list of anonymized fields
- Configurable via
The Uploader Controller (pkg/insights/insightsuploader/) handles periodic upload of gathered data:
- Purpose: Uploads Insights archives to console.redhat.com for analysis
- Workflow:
- Periodically checks for new data since last upload
- Creates tar.gz archive from recorded data
- Uploads with exponential backoff on failures
- Notifies report downloader on successful upload
- Updates last reported timestamp
- Key features:
- Configurable upload interval (default 2 hours)
- Exponential backoff with 4 retry steps on failures
- Returns
InsightsRequestIDfor tracking (TechPreview) - Dry-run mode when reporting is disabled (logs archive contents)
- Authorization error handling with extended retry delays
The Insights Report Controller (pkg/insights/insightsreport/) downloads and processes analysis reports:
- Purpose: Retrieves recommendations and health analysis for the cluster from Insights backend
- Workflow:
- Waits for archive upload notification
- Downloads analysis report from Smart Proxy or insights-results-aggregator (TechPreview)
- Parses recommendations with risk levels (critical, important, moderate, low)
- Updates Prometheus metrics (
health_statuses_insights) - Updates
InsightsOperatorCR status with active health checks - Creates Insights Advisor links for each recommendation
- Key features:
- Retry logic for failed downloads (up to 2 retries)
- 5-minute download timeout with configurable initial delay
- Supports both legacy Smart Proxy and new TechPreview endpoints
- Exposes recommendations as Prometheus metrics for alerting
- Skips duplicate reports (checks
LastCheckedAttimestamp)
The Prometheus Rules Controller (pkg/insights/prometheus_rules.go) manages Insights-specific alerts:
- Managed alerts:
InsightsDisabled- Fires when Insights operator is disabledSimpleContentAccessNotAvailable- Fires when SCA certificates are unavailableInsightsRecommendationActive- Fires for each active Insights recommendation
- Key features:
- Dynamically creates/removes rules based on
Alerting.Disabledconfiguration - All alerts have
infoseverity level - 5-minute evaluation period (
for: 5m) - Rules created in
openshift-insightsnamespace
- Dynamically creates/removes rules based on
The SCA (Simple Content Access) Controller (pkg/ocm/sca/) periodically pulls Red Hat entitlement certificates from the OCM API:
- Purpose: Manages Red Hat entitlement certificates for clusters to access subscription content
- Workflow:
- Gathers cluster node architectures via Kubernetes API (supports multi-arch clusters)
- Requests SCA certificates from OCM API for each detected architecture
- Creates/updates secrets in
openshift-config-managednamespace:etc-pki-entitlement- Default secret with control plane architecture certificatesetc-pki-entitlement-<arch>- Architecture-specific secrets for multi-arch clusters
- Each secret contains
entitlement.pemandentitlement-key.pemdata
- Key features:
- Exponential backoff retry for HTTP 5xx errors from OCM API
- Architecture mapping between Kubernetes format (amd64, arm64) and SCA API format (x86_64, aarch64)
- Default interval: configurable via
SCA.Interval(typically 8 hours) - Can be disabled via configuration (
SCA.Disabled)
The Cluster Transfer Controller (pkg/ocm/clustertransfer/) handles cluster ownership transfers between organizations:
- Purpose: Automatically updates the cluster's pull-secret when a cluster transfer is initiated in OCM
- Workflow:
- Periodically queries OCM API for accepted cluster transfer requests
- If exactly one accepted transfer exists, retrieves new pull-secret data
- Compares new pull-secret with existing one in
openshift-confignamespace - If different, applies JSON merge patch to update
pull-secretsecret - Updates controller status with operation result
- Key features:
- Exponential backoff retry for HTTP 5xx errors from OCM API
- Validates only one accepted transfer exists (prevents conflicts)
- Uses JSON merge patch to preserve existing pull-secret data while adding new registry credentials
- Default interval: configurable via
ClusterTransfer.Interval(typically 12 hours) - Handles disconnected environments gracefully (logs error but remains healthy)
- All Go code must be formatted with
gofmt - Import groups: stdlib, external dependencies, current project
- Test methods:
Test_<FunctionName>orTest_<GatherName>_<FunctionName> - Use table-driven tests
- File names: lowercase dash-separated (except Dockerfile, Makefile, README)
- Install git hooks:
make githooks - Base work on master branch
- Commit message format: descriptive subject line with detailed body
- Pull requests must reference Bugzilla bugs for enhancements/backports
- Backport branches follow
release-X.Yformat
Always run before creating pull requests:
make lint- Ensure code qualitymake test- Verify all tests pass- Install githooks for automatic pre-commit validation
- Go version: 1.23.0 with toolchain go1.23.4
- Uses vendored dependencies (
GOFLAGS=-mod=vendor) - Local replacements for
github.com/openshift/apiandgithub.com/openshift/client-go - Main dependencies: OpenShift APIs, Kubernetes client libraries, Prometheus client, Cobra CLI