Full rebrand across cosmetic branding, code identifiers, and infrastructure/data-plane naming, using the supplied Cairn OBS logo package. Cosmetic: favicon/logo swap (also closes a stale license-audit finding -- the old favicon was SvelteKit's unreplaced scaffold logo), new centered welcome landing page, larger/legible sidebar logo, page titles, CLAUDE.md/README/docs prose. Code identifiers: Go module path github.com/sentry/sentry -> github.com/cairnobs/cairnobs across all 13 modules and ~91 files (protoc regenerated); Rust crates sentry-agent/sentry-parser/sentry-search -> cairnobs-*; CLI sentryctl -> cairnobsctl; Terraform provider fully renamed (sentry_dashboard etc. -> cairnobs_dashboard, provider type, env vars); every session/auth cookie name; agent config paths and Windows service identity. Deliberately preserved: the gRPC wire protocol's protobuf packages (sentry.logs.v1, sentry.agent.v1) and their Go import directory (proto/sentry/...) -- renaming the wire-level package would break every currently-deployed agent binary (confirmed two real hosts, including mail.inbuxa.com, are actively streaming through this exact contract) until rebuilt and redeployed in lockstep with an ingest cutover. Only the Go module path wrapping the generated code changes. Infrastructure: every docker-compose container name (root and three component-level compose files); the Helm chart (directory, Chart.yaml, named-template helpers, all templates, values.yaml image repos); Kubernetes Operator (CRD group sentry.io -> cairnobs.io, both CRD YAML files, Go identifiers, RBAC markers); the coupled enterprise/tenantcrd package. Caught and fixed real path-coupling bugs along the way: the Helm chart's search/ingest volume mounts and the dev-only-credential detection constant vs. docker-compose.yml's literal values had to move together or a security warning would have silently stopped firing. Data plane: Postgres database sentry_metadata -> cairnobs_metadata and role sentry -> cairnobs; ClickHouse database sentry -> cairnobs; Kafka topic sentry.logs.raw -> cairnobs.logs.raw and its consumer groups. Source-level defaults, docker-compose.yml, and every migrate.sh/ provision script default updated together; already-applied migration files left untouched per this repo's immutable-migration convention. Verified at every layer: all 13 Go modules build/vet/test clean, both Rust workspaces (agent, search) build/clippy/test clean, npm run check/ build clean, docker compose config validates on all four compose files. Live-verified against a real docker stack multiple times through this work, including a final fresh-volume run confirming the actual renamed Postgres database/role, ClickHouse database, and Kafka topic all work end to end with a real login and query, zero console errors.
178 lines
6.9 KiB
Go
178 lines
6.9 KiB
Go
// Tests use controller-runtime's fake client (sigs.k8s.io/
|
|
// controller-runtime/pkg/client/fake), not envtest -- envtest needs a
|
|
// real kube-apiserver/etcd binary pair (setup-envtest) that isn't
|
|
// available in this environment (see package doc comment and
|
|
// deploy/README.md's verification section). A fake client exercises
|
|
// Reconcile's actual logic (status derivation, condition writes) against
|
|
// an in-memory tracker; what it can't exercise is anything a real
|
|
// apiserver would do for you (defaulting, admission, watch-triggered
|
|
// re-reconciliation) -- so passing here is real signal about this
|
|
// reconciler's logic, not proof it behaves correctly against a live
|
|
// cluster.
|
|
package controller
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
|
|
|
cairnobsv1alpha1 "github.com/cairnobs/cairnobs/deploy/operator/api/v1alpha1"
|
|
)
|
|
|
|
func newFakeReconciler(t *testing.T, objs ...client.Object) *TenantReconciler {
|
|
t.Helper()
|
|
scheme := runtime.NewScheme()
|
|
if err := corev1.AddToScheme(scheme); err != nil {
|
|
t.Fatalf("adding corev1 to scheme: %v", err)
|
|
}
|
|
if err := cairnobsv1alpha1.AddToScheme(scheme); err != nil {
|
|
t.Fatalf("adding cairnobsv1alpha1 to scheme: %v", err)
|
|
}
|
|
fakeClient := fake.NewClientBuilder().
|
|
WithScheme(scheme).
|
|
WithObjects(objs...).
|
|
WithStatusSubresource(&cairnobsv1alpha1.Tenant{}).
|
|
Build()
|
|
return &TenantReconciler{Client: fakeClient, Scheme: scheme}
|
|
}
|
|
|
|
func testTenant(name string, suspended bool) *cairnobsv1alpha1.Tenant {
|
|
return &cairnobsv1alpha1.Tenant{
|
|
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: "default"},
|
|
Spec: cairnobsv1alpha1.TenantSpec{DisplayName: name, Suspended: suspended},
|
|
}
|
|
}
|
|
|
|
func reconcile(t *testing.T, r *TenantReconciler, name string) cairnobsv1alpha1.Tenant {
|
|
t.Helper()
|
|
ctx := context.Background()
|
|
if _, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: types.NamespacedName{Name: name, Namespace: "default"}}); err != nil {
|
|
t.Fatalf("Reconcile: %v", err)
|
|
}
|
|
var got cairnobsv1alpha1.Tenant
|
|
if err := r.Get(ctx, types.NamespacedName{Name: name, Namespace: "default"}, &got); err != nil {
|
|
t.Fatalf("getting tenant: %v", err)
|
|
}
|
|
return got
|
|
}
|
|
|
|
// TestReconcileUnprovisionedTenantIsProvisioningNotActive is the
|
|
// regression test for the pre-unification bug: this controller must
|
|
// never claim PhaseActive just because a Tenant object exists -- only
|
|
// enterprise-api -provision-tenant setting Status.ClickHouseDatabaseName
|
|
// (real ClickHouse provisioning having actually succeeded) earns that.
|
|
func TestReconcileUnprovisionedTenantIsProvisioningNotActive(t *testing.T) {
|
|
tenant := testTenant("acme", false)
|
|
r := newFakeReconciler(t, tenant)
|
|
|
|
got := reconcile(t, r, "acme")
|
|
|
|
if got.Status.Phase != cairnobsv1alpha1.PhaseProvisioning {
|
|
t.Fatalf("Phase = %q, want Provisioning (nothing has provisioned this tenant yet)", got.Status.Phase)
|
|
}
|
|
cond := readyCondition(got)
|
|
if cond == nil || cond.Status != metav1.ConditionFalse {
|
|
t.Fatalf("Ready condition = %+v, want status False", cond)
|
|
}
|
|
}
|
|
|
|
// TestReconcileReflectsProvisioningStateProvisionTenantSets is the core
|
|
// "lightweight unification" behavior: once something external (in
|
|
// production, -provision-tenant; here, simulated directly against the
|
|
// fake client the way a real K8s API server write would land) sets
|
|
// ClickHouseDatabaseName, this controller must report PhaseActive.
|
|
func TestReconcileReflectsProvisioningStateProvisionTenantSets(t *testing.T) {
|
|
tenant := testTenant("acme", false)
|
|
r := newFakeReconciler(t, tenant)
|
|
ctx := context.Background()
|
|
|
|
var toUpdate cairnobsv1alpha1.Tenant
|
|
if err := r.Get(ctx, types.NamespacedName{Name: "acme", Namespace: "default"}, &toUpdate); err != nil {
|
|
t.Fatalf("getting tenant: %v", err)
|
|
}
|
|
toUpdate.Status.ClickHouseDatabaseName = "acme"
|
|
toUpdate.Status.ClickHouseSecretRef = "cairnobs-tenant-acme-clickhouse"
|
|
toUpdate.Status.TantivyIndexPath = "/var/lib/cairnobs-search/tenants/acme"
|
|
if err := r.Status().Update(ctx, &toUpdate); err != nil {
|
|
t.Fatalf("simulating -provision-tenant's status write: %v", err)
|
|
}
|
|
|
|
got := reconcile(t, r, "acme")
|
|
|
|
if got.Status.Phase != cairnobsv1alpha1.PhaseActive {
|
|
t.Fatalf("Phase = %q, want Active", got.Status.Phase)
|
|
}
|
|
if got.Status.ClickHouseDatabaseName != "acme" || got.Status.ClickHouseSecretRef != "cairnobs-tenant-acme-clickhouse" || got.Status.TantivyIndexPath != "/var/lib/cairnobs-search/tenants/acme" {
|
|
t.Fatalf("reconcile must not clobber the fields -provision-tenant set: %+v", got.Status)
|
|
}
|
|
cond := readyCondition(got)
|
|
if cond == nil || cond.Status != metav1.ConditionTrue {
|
|
t.Fatalf("Ready condition = %+v, want status True", cond)
|
|
}
|
|
}
|
|
|
|
func TestReconcileSuspendedOverridesProvisionedState(t *testing.T) {
|
|
tenant := testTenant("acme", true)
|
|
tenant.Status.ClickHouseDatabaseName = "acme" // already provisioned
|
|
r := newFakeReconciler(t, tenant)
|
|
|
|
got := reconcile(t, r, "acme")
|
|
|
|
if got.Status.Phase != cairnobsv1alpha1.PhaseSuspended {
|
|
t.Fatalf("Phase = %q, want Suspended even though the tenant is provisioned", got.Status.Phase)
|
|
}
|
|
}
|
|
|
|
// TestReconcileUnsuspendingReturnsToActiveNotProvisioning is the
|
|
// regression test for why Phase is *derived* fresh every reconcile
|
|
// (from Spec.Suspended + whether ClickHouseDatabaseName is set) rather
|
|
// than toggled in place: un-suspending an already-provisioned tenant
|
|
// must return it straight to Active, not demote it to Provisioning just
|
|
// because the last observed Phase happened to be Suspended.
|
|
func TestReconcileUnsuspendingReturnsToActiveNotProvisioning(t *testing.T) {
|
|
tenant := testTenant("acme", true)
|
|
tenant.Status.ClickHouseDatabaseName = "acme"
|
|
r := newFakeReconciler(t, tenant)
|
|
ctx := context.Background()
|
|
|
|
_ = reconcile(t, r, "acme") // establishes Suspended
|
|
|
|
var toUpdate cairnobsv1alpha1.Tenant
|
|
if err := r.Get(ctx, types.NamespacedName{Name: "acme", Namespace: "default"}, &toUpdate); err != nil {
|
|
t.Fatalf("getting tenant: %v", err)
|
|
}
|
|
toUpdate.Spec.Suspended = false
|
|
if err := r.Update(ctx, &toUpdate); err != nil {
|
|
t.Fatalf("unsuspending: %v", err)
|
|
}
|
|
|
|
got := reconcile(t, r, "acme")
|
|
if got.Status.Phase != cairnobsv1alpha1.PhaseActive {
|
|
t.Fatalf("Phase = %q, want Active after unsuspending an already-provisioned tenant", got.Status.Phase)
|
|
}
|
|
}
|
|
|
|
func TestReconcileMissingTenantIsNoOp(t *testing.T) {
|
|
r := newFakeReconciler(t)
|
|
_, err := r.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{Name: "does-not-exist", Namespace: "default"}})
|
|
if err != nil {
|
|
t.Fatalf("Reconcile on a missing tenant should be a no-op, got error: %v", err)
|
|
}
|
|
}
|
|
|
|
func readyCondition(tenant cairnobsv1alpha1.Tenant) *metav1.Condition {
|
|
for i := range tenant.Status.Conditions {
|
|
if tenant.Status.Conditions[i].Type == cairnobsv1alpha1.ConditionReady {
|
|
return &tenant.Status.Conditions[i]
|
|
}
|
|
}
|
|
return nil
|
|
}
|