This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
The deadmanssnitch-operator manages Dead Man's Snitch (DMS) heartbeat monitoring for OpenShift Dedicated (OSD) clusters. It runs on Hive, watches ClusterDeployment resources, and for each installed managed cluster: creates a snitch via the DMS API, stores the check-in URL in a Secret, and syncs it into the target cluster's openshift-monitoring namespace via a SyncSet.
The build system uses OpenShift boilerplate (.mk files in boilerplate/). FIPS is enabled by default, which requires GOEXPERIMENT=boringcrypto and generally only builds inside the provided Dockerfile.
# Build, lint, and test (default target)
make
# Individual targets
make go-check # golangci-lint
make go-test # Unit tests (uses setup-envtest for kubebuilder assets)
make go-build # Build binary (FIPS-enabled, may fail outside container)
make lint # YAML validation + go-check
make validate # Ensures generated code is committed and boilerplate is frozen
make generate # Run all code generation (CRDs, deepcopy, openapi, mocks)
# Run a single test
KUBEBUILDER_ASSETS=$(setup-envtest use 1.28.0 --arch amd64 --os linux --bin-dir /tmp/envtest-binaries -p path) \
go test -run TestReconcileClusterDeployment ./controllers/deadmanssnitchintegration/
# Run locally (requires kubeconfig with Hive CRDs)
make run
# Container-based targets (run inside boilerplate container)
make container-test
make container-lint
make container-validate
make container-all # All container validations in sequence
# PKO template validation (requires kubectl-package CLI)
kubectl-package validate deploy_pko/Single controller (DeadmansSnitchIntegrationReconciler) managing one CRD:
- CRD:
DeadmansSnitchIntegration(shortName:dmsi, group:deadmanssnitch.managed.openshift.io/v1alpha1) - Entry point:
main.go-- sets up manager, leader election, custom metrics server (port 8081) - Controller:
controllers/deadmanssnitchintegration/-- reconciles DMSI CRs - Event handlers:
event_handlers.go-- maps ClusterDeployment/Secret/SyncSet changes back to DMSI reconcile requests
- Fetch DMSI CR and load DMS API key from referenced Secret
- List ClusterDeployments matching
spec.clusterDeploymentSelector - For each matching CD that is installed and not hibernating:
- Add finalizer (
dms.managed.openshift.io/deadmanssnitch-{postfix}) - Create/find snitch via DMS API
- Create Secret with snitch check-in URL
- Create SyncSet to sync Secret into cluster's
openshift-monitoringnamespace
- Add finalizer (
- On deletion/hibernation: delete snitch, remove Secret, SyncSet, and finalizer
pkg/dmsclient/-- DMS API client withClientinterface; mock atpkg/dmsclient/mock/(generated viago.uber.org/mock)config/-- Operator constants (namespace, label names, SyncSet postfixes) and FedRAMP env var handlingpkg/localmetrics/-- Prometheus metrics for DMS API call duration, errors, and heartbeatpkg/utils/-- Secret and utility helpers
Tests use controller-runtime's fake client and GoMock for the DMS API client. The setupDefaultMocks() helper in the controller test creates a standard set of test objects (DMSI, ClusterDeployment, Secrets).
PKO template tests (pkg/pko/template_test.go) have two layers:
- Snapshot tests -- golden files in
deploy_pko/.test-fixtures/, validated bykubectl-package validate - Structural tests -- Go assertions on rendered template output (kind, annotations, conditional fields)
To regenerate PKO fixtures after template changes:
rm -rf deploy_pko/.test-fixtures/
kubectl-package validate deploy_pko/make generate runs four generators in sequence: op-generate (controller-gen CRDs + deepcopy), go-generate (mocks), openapi-generate, manifests. CI enforces that generated files are committed via make generate-check.
Generated files (do not edit manually):
api/v1alpha1/zz_generated.deepcopy.goapi/v1alpha1/zz_generated.openapi.gopkg/dmsclient/mock/mock_dmsclient.godeploy/crds/*.yaml
Two deployment models exist side by side:
deploy/-- Traditional OLM-style Kubernetes manifestsdeploy_pko/-- Package Operator format with Go templates (.gotmpl), used for current deployments
PKO config values (deploy_pko/manifest.yaml): image, silentAlertLegalEntityIds, deadmanssnitchOsdTags, fedramp.
This repo consumes openshift/boilerplate v8.3.4 via boilerplate/update. Run make boilerplate-update to pull the latest. Boilerplate provides standard Make targets, golangci-lint config, Tekton pipelines, and OWNERS_ALIASES. Do not edit files under boilerplate/ directly.