model

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package model defines the declarative node specification (BootSpec), settled node identity (NodeIdentity), disruption budgets, and lifecycle hook models.

Index

Constants

View Source
const (
	DefaultWriterHostPrefix = "writer-"
	DefaultReaderHostPrefix = "reader-"
)

Default host prefixes: the claim-table key and DNS record are prefix+ordinal, and inventory (live-claims and static fallback both) matches claims by these prefixes when the spec leaves them unset.

View Source
const DefaultBackupCalendar = "*-*-* 02:00:00"

DefaultBackupCalendar is the default systemd OnCalendar schedule for clickhouse-backup when Backup.Schedule is unset (02:00 UTC daily).

View Source
const DefaultMinHealthyWriters = 1

DefaultMinHealthyWriters applies when the spec leaves the floor zero (the safe default for the writer path).

Variables

This section is empty.

Functions

func CronToCalendar

func CronToCalendar(expr string) string

CronToCalendar converts a 5-field POSIX cron expression ("min hour dom month dow", e.g. "0 2 * * *" or "30 4 * * 1-5") into a systemd OnCalendar specification ("*-*-* 02:00:00" or "Mon..Fri *-*-* 04:30:00"). Non-5-field strings (already systemd OnCalendar syntax such as "*-*-* 02:00:00", "daily", "hourly") pass through verbatim; an empty string returns DefaultBackupCalendar.

Types

type Backup

type Backup struct {
	Bucket                string `yaml:"bucket"                             json:"bucket"`
	Prefix                string `yaml:"prefix,omitempty"                   json:"prefix,omitempty"`
	RetentionDays         int    `yaml:"retention_days,omitempty"           json:"retention_days,omitempty"`
	CompressionFormat     string `yaml:"compression_format,omitempty"       json:"compression_format,omitempty"`
	IsBackupReplica       bool   `yaml:"is_backup_replica"                  json:"is_backup_replica"`
	BackupReplicaHostname string `yaml:"backup_replica_hostname,omitempty"  json:"backup_replica_hostname,omitempty"`
	// Schedule is the cron expression ("0 2 * * *") or systemd
	// OnCalendar expression ("*-*-* 02:00:00") for the backup pass.
	// Empty defaults to "*-*-* 02:00:00" (02:00 UTC daily).
	Schedule string `yaml:"schedule,omitempty"  json:"schedule,omitempty"`
	// OnDemand spins the dedicated backup replica up on Schedule and
	// stops it once the backup pass completes (the StatefulSet 0<->1
	// pattern: the ordinal-0 writer wakes backup-0 on Schedule;
	// backup-0 syncs its replica catalog, runs clickhouse-backup, and
	// stops its own instance).
	OnDemand bool `yaml:"on_demand,omitempty" json:"on_demand,omitempty"`
}

Backup configures clickhouse-backup against provider object storage.

func (Backup) CalendarSchedule

func (b Backup) CalendarSchedule() string

CalendarSchedule returns the systemd OnCalendar expression for Backup.Schedule, converting 5-field standard cron expressions ("0 2 * * *") into systemd calendar syntax ("*-*-* 02:00:00").

type BootSpec

type BootSpec struct {
	// Cloud, when set, overrides cloud detection (used by packer builds
	// and tests; the booting node normally relies on detection).
	Cloud string `yaml:"cloud,omitempty" json:"cloud,omitempty"`

	// Node identity.
	Role             Role         `yaml:"role"                        json:"role"`
	IdentityMode     IdentityMode `yaml:"identity_mode"               json:"identity_mode"`
	ReaderHostPrefix string       `yaml:"reader_hostname_prefix,omitempty" json:"reader_hostname_prefix,omitempty"`

	// ReaderCount is the readers' baseline count (render-time
	// inventory: the reserved host-name list). In lease mode the
	// ordinal claim ceiling is ReaderMax (the ASG max — scale-out
	// beyond this baseline must be able to claim); ReaderCount stays
	// the compat baseline the pre-max Terraform render relies on.
	ReaderCount int `yaml:"reader_count,omitempty" json:"reader_count,omitempty"`

	// ReaderMax is the ordinal claim ceiling for leased readers = the
	// readers ASG max_size. Readers claim ordinals in [0, ReaderMax).
	// Why: the ASG can scale past ReaderCount, so the ceiling must be
	// the maximum the fleet can ever reach, not today's baseline
	// otherwise a scale-out boots a node that can never claim an
	// identity. Empty/0 for non-leased readers (static inventory uses
	// ReaderCount).
	ReaderMax int `yaml:"reader_max,omitempty" json:"reader_max,omitempty"`

	// WriterHostPrefix is the hostname prefix leased writers claim
	// (writer-0, writer-1, ...). Consumers default it to "writer-" so
	// the Terraform template can omit it. Why a prefix field at all:
	// the claim-table key and DNS record are prefix+ordinal, and tests
	// render both from one place.
	WriterHostPrefix string `yaml:"writer_hostname_prefix,omitempty" json:"writer_hostname_prefix,omitempty"`

	// WriterMax is the ordinal claim ceiling for leased writers = the
	// writers ASG max_size. Writers claim ordinals in [0, WriterMax).
	// Why: CR slots are rendered from fixed ceilings (stable CR names
	// across scaling events), and the claimer needs the bound it may
	// hand out. 0 for static writers (the octet map fixes the ordinal).
	WriterMax int `yaml:"writer_max,omitempty" json:"writer_max,omitempty"`

	// Cluster topology (rendered into the CHI/keeper spec macros).
	ClusterName string `yaml:"cluster_name"             json:"cluster_name"`
	DNSZoneName string `yaml:"dns_zone_name"            json:"dns_zone_name"`

	// WriterCount and WriterNodes are DEPRECATED for lease identity:
	// they remain the source for the static-identity writer path only
	// (static EC2s with fixed IPs, being replaced by the writer ASG).
	// Lease-mode writers derive identity from WriterHostPrefix/WriterMax
	// instead. Retire both fields when the static writer path is gone.
	WriterCount int      `yaml:"writer_count"             json:"writer_count"`
	WriterNodes []string `yaml:"writer_nodes,omitempty"  json:"writer_nodes,omitempty"`
	KeeperNodes []string `yaml:"keeper_nodes,omitempty"   json:"keeper_nodes,omitempty"`

	// Config bundle: the S3/Blob prefix bootstrap.sh downloaded from.
	// chinit fetches it itself now (config_bundle_sha256 pins the exact
	// content: a spec edit rolls the hash and the fleet follows).
	ConfigBundle ConfigBundle `yaml:"config_bundle" json:"config_bundle"`

	// S3 data bucket (the tiered storage's raw disk endpoint root) and
	// the node timezone: the boot writes both into the server's
	// EnvironmentFile (storage.xml reads the endpoint via from_env
	// an unset variable is a START error, Code 36 Empty protocol in
	// the URL, not a warning).
	S3DataBucket string `yaml:"s3_data_bucket,omitempty" json:"s3_data_bucket,omitempty"`
	Timezone     string `yaml:"timezone,omitempty"        json:"timezone,omitempty"`

	// CasEnabled mirrors the Terraform cas_config.enabled opt-in. When
	// true, the server EnvironmentFile pins CH_CAS_SERVER_ROOT_ID to the
	// node's deterministic root id (storage.xml's from_env contract), so
	// every ASG replacement of an ordinal claims the SAME CAS server-root
	// anchor across fresh EBS. Unset/false keeps the /etc payload exactly
	// as before 0.2.1 (no env contract), and CAS disks using from_env
	// resolve per-incarnation roots (empty var → server uuid).
	CasEnabled bool `yaml:"cas_enabled,omitempty" json:"cas_enabled,omitempty"`

	// ClaimerTableName is the provider's ordinal-lease table (lease
	// identity: DynamoDB on AWS, Table storage on Azure). The settle
	// step claims reader-N/writer-N from it.
	ClaimerTableName string `yaml:"claimer_table_name,omitempty" json:"claimer_table_name,omitempty"`

	// Disk labels (mount by LABEL, never device path — NVMe renaming).
	Disks Disks `yaml:"disks" json:"disks"`

	// Secrets to resolve via the provider's SecretSource. Names only;
	// values never enter the spec, the state file or logs.
	Secrets Secrets `yaml:"secrets" json:"secrets"`

	// Network access lists (ClickHouse <networks> sources).
	Network Network `yaml:"network" json:"network"`

	// Backup (clickhouse-backup) — rendered against the provider's
	// object storage; empty bucket = backups disabled.
	Backup Backup `yaml:"backup" json:"backup"`

	// Remote log shipping (optional; empty endpoint = disabled).
	LogShipping LogShipping `yaml:"log_shipping" json:"log_shipping"`

	// Disruption is the fleet's voluntary-disruption budget (the
	// operator's PodDisruptionBudget equivalent): the healthy-node
	// floors the drain/refresh/rollout gates enforce. Optional; zero
	// floors take the safe defaults (writers: 1).
	Disruption DisruptionBudget `yaml:"disruption" json:"disruption"`

	// Hooks is the lifecycle hook list (the operator's
	// spec.reconcile.hooks parity): commands at the boot and drain
	// boundaries. Optional; the boundaries are no-ops without hooks.
	Hooks Hooks `yaml:"hooks" json:"hooks"`

	// Providers append their region/zone here after metadata probing.
	Region string `yaml:"region"         json:"region"`
	Zone   string `yaml:"zone,omitempty" json:"zone,omitempty"`

	// MultiAZ configures multi-AZ replica placement and the required
	// shared-blob cold storage tier ("cas").
	MultiAZ MultiAZ `yaml:"multi_az,omitempty" json:"multi_az,omitempty"`
}

BootSpec is the complete, validated input to a node boot.

func (*BootSpec) NodeSubnetCIDRs

func (s *BootSpec) NodeSubnetCIDRs() []string

NodeSubnetCIDRs answers every nodes-subnet CIDR peer traffic can arrive from: the node's own subnet plus the multi-AZ extras (deduplicated, the SubnetCIDR first — the Single-AZ shape answers exactly the historical one-entry list).

func (*BootSpec) ReaderCeiling

func (s *BootSpec) ReaderCeiling() int

ReaderCeiling is the readers' enumeration bound for inventory: the ASG max when set (a scale-out past ReaderCount must still be listed once it claims), else the static baseline ReaderCount.

func (*BootSpec) ReaderPrefix

func (s *BootSpec) ReaderPrefix() string

ReaderPrefix is the leased-reader hostname prefix ("reader-").

func (*BootSpec) Validate

func (s *BootSpec) Validate() error

Validate checks the invariants every role shares. Role-specific shapes (readers need reader_count, keepers need keeper_nodes) are validated where consumed; this catches the malformed-spec class early, before any provider client is built.

func (*BootSpec) WriterCeiling

func (s *BootSpec) WriterCeiling() int

WriterCeiling is the fixed writer section size of the CR's replica list: WriterMax (the ASG max — every ordinal a writer can ever claim) when set, else WriterCount (the static baseline). Why a ceiling and not count: reader CR slots are rendered at writerCeiling+ordinal, so the slot an ordinal maps to must never shift when a writer scales in/out — that would re-key every reader's CR name mid-flight (the CR-slot stability contract).

func (*BootSpec) WriterPrefix

func (s *BootSpec) WriterPrefix() string

WriterPrefix is the leased-writer hostname prefix ("writer-").

type ConfigBundle

type ConfigBundle struct {
	Bucket string `yaml:"bucket"     json:"bucket"`
	Prefix string `yaml:"prefix"     json:"prefix"`
	// SHA256 of the bundle contents; empty skips the gate (dev only).
	SHA256 string `yaml:"sha256,omitempty" json:"sha256,omitempty"`
}

ConfigBundle locates and pins the node's configuration bundle in the provider's object storage.

type Disks

type Disks struct {
	MetadataLabel string `yaml:"metadata_label" json:"metadata_label"`
	CacheLabel    string `yaml:"cache_label,omitempty"   json:"cache_label,omitempty"`
	KeeperLabel   string `yaml:"keeper_label,omitempty"  json:"keeper_label,omitempty"`
}

Disks are the volume labels the mount step resolves (label survives NVMe device renaming; first boot falls back to the EBS device path).

type DisruptionBudget

type DisruptionBudget struct {
	// MinHealthyWriters is the floor of healthy writer nodes during
	// any voluntary disruption (0 = the default: 1 — a fleet with a
	// single live writer never voluntarily takes it down; a multi-
	// writer fleet always keeps one serving).
	MinHealthyWriters int `yaml:"min_healthy_writers,omitempty" json:"min_healthy_writers,omitempty"`
	// MinHealthyReaders is the floor of healthy reader nodes (0 = no
	// reader floor: readers are disposable; native ASG policies own
	// their horizontal scaling).
	MinHealthyReaders int `yaml:"min_healthy_readers,omitempty" json:"min_healthy_readers,omitempty"`
}

DisruptionBudget is the fleet's voluntary-disruption policy — the VM-level PDB equivalent. The operator relies on Kubernetes PodDisruptionBudgets to bound concurrent replica outages during evictions; chinit's fleet has no scheduler to ask, so every voluntary termination path (drain, refresh, rollout) gates on this budget computed from the live claims + status rows.

The budget bounds CONCURRENT outages, not total ones: a rollout may replace every writer, one at a time, waiting for each replacement to be healthy before the next.

type Hook

type Hook struct {
	// Event is the boundary this hook fires at.
	Event HookEvent `yaml:"event" json:"event"`
	// Name labels the hook in the journal (required: the journal line
	// must name WHAT ran, not just that something did).
	Name string `yaml:"name" json:"name"`
	// Command is the shell command (`sh -c`).
	Command string `yaml:"command" json:"command"`
	// TimeoutSeconds bounds the command (0 = 30s default).
	TimeoutSeconds int `yaml:"timeout_seconds,omitempty" json:"timeout_seconds,omitempty"`
	// Critical: true = a failure aborts the boundary (the boot fails,
	// the drain proceeds anyway — a drain can never be blocked by a
	// hook, the node is already going down); false = the failure is
	// logged and the boundary continues.
	Critical bool `yaml:"critical,omitempty" json:"critical,omitempty"`
}

Hook is one lifecycle command: the operator's spec.reconcile.hooks parity at the VM level. The command runs under `sh -c` with the node's identity in the environment (CHINIT_ROLE, CHINIT_HOSTNAME, CHINIT_CLUSTER).

func (Hook) HookTimeout

func (h Hook) HookTimeout() time.Duration

HookTimeout applies the hook's default.

type HookEvent

type HookEvent string

HookEvent is the lifecycle boundary a hook fires at.

const (
	// HookPreBoot fires before the boot pipeline's first step (the
	// operator's pre-create moment: register the node with external
	// systems).
	HookPreBoot HookEvent = "pre_boot"
	// HookPostBoot fires after the last step (the operator's
	// HostCreate POST hook: notify, validate, warm caches).
	HookPostBoot HookEvent = "post_boot"
	// HookPreDrain fires before the drain's first step (the
	// operator's HostShutdown moment).
	HookPreDrain HookEvent = "pre_drain"
	// HookPostDrain fires after the drain completes (the operator's
	// HostDelete hook).
	HookPostDrain HookEvent = "post_drain"
)

type Hooks

type Hooks struct {
	// Items is the ordered hook list (the events fire in list order).
	Items []Hook `yaml:"items,omitempty" json:"items,omitempty"`
}

Hooks is the spec's `hooks:` section.

func (*Hooks) HooksFor

func (hs *Hooks) HooksFor(event HookEvent) []Hook

HooksFor answers the hooks bound to one event, in list order.

type IdentityMode

type IdentityMode string

IdentityMode selects how the node derives its hostname:

  • static: derives the hostname from the private IP's last octet.
  • lease: claims a stable ordinal from the cloud provider's lease table before rendering configuration.
const (
	IdentityStatic IdentityMode = "static"
	IdentityLease  IdentityMode = "lease"
)

type LogShipping

type LogShipping struct {
	Agent           string `yaml:"agent,omitempty"       json:"agent,omitempty"`
	Endpoint        string `yaml:"endpoint,omitempty"     json:"endpoint,omitempty"`
	Headers         string `yaml:"headers,omitempty"      json:"headers,omitempty"`
	FluentbitOutput string `yaml:"fluentbit_output,omitempty" json:"fluentbit_output,omitempty"`
}

LogShipping is the optional remote log pipeline (OTEL or Fluent Bit).

type MultiAZ

type MultiAZ struct {
	// Enabled mirrors the Terraform-side opt-in; false = single-AZ
	// shard placement (the cross-AZ part-fetch tax never applies).
	Enabled bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	// ColdTier names the shared-blob cold tier multi-AZ placement
	// rides on ("cas" = Altinity Antalya CAS). Empty with Enabled
	// fails validation — the pairing IS the contract.
	ColdTier string `yaml:"cold_tier,omitempty" json:"cold_tier,omitempty"`
}

MultiAZ is the spec's multi-AZ placement policy. The zero value is the safe default everywhere: disabled (single-AZ shard placement).

type Network

type Network struct {
	SubnetCIDR                 string   `yaml:"subnet_cidr"                    json:"subnet_cidr"`
	NLBSubnetCIDR              string   `yaml:"nlb_subnet_cidr,omitempty"       json:"nlb_subnet_cidr,omitempty"`
	AdminAllowedNetworks       []string `yaml:"admin_allowed_networks,omitempty"       json:"admin_allowed_networks,omitempty"`
	WriterAllowedNetworks      []string `yaml:"writer_allowed_networks,omitempty"      json:"writer_allowed_networks,omitempty"`
	DefaultUserAllowedNetworks []string `yaml:"default_user_allowed_networks,omitempty" json:"default_user_allowed_networks,omitempty"`
	// SubnetCIDRs are the EXTRA per-AZ nodes subnet CIDRs multi-AZ
	// placement adds (peers in other AZs arrive from those CIDRs;
	// each render allowlists them beside the node's own SubnetCIDR).
	// Empty in the Single-AZ posture (the pre-multi-AZ shape).
	SubnetCIDRs []string `yaml:"subnet_cidrs,omitempty" json:"subnet_cidrs,omitempty"`
}

Network carries the per-role network allow lists and the subnet CIDRs the <networks> sections consume.

type NodeIdentity

type NodeIdentity struct {
	Role        Role   `json:"role"`
	Hostname    string `json:"hostname"`
	InstanceID  string `json:"instance_id"`
	PrivateIP   string `json:"private_ip"`
	Region      string `json:"region"`
	ClusterName string `json:"cluster_name"`
	DNSZone     string `json:"dns_zone"`
	// CRName is the operator CR host name for server nodes ("01-0"),
	// empty for the backup replica (not in the CR) and keepers.
	CRName string `json:"cr_name,omitempty"`
	// CROrdinal is the numeric suffix of CRName (writers/readers), or
	// the keeper's own ordinal; -1 when not applicable.
	CROrdinal int `json:"cr_ordinal"`
	// ZoneID is the private DNS zone (provider cache of the claim-time
	// resolution); the spot drain releases the record through it.
	ZoneID string `json:"zone_id,omitempty"`
	// LeaseTable is the provider's ordinal lease table when the node
	// holds a lease (readers); the drain releases it.
	LeaseTable string `json:"lease_table,omitempty"`
}

NodeIdentity is the SETTLED identity every later step and unit uses. It is snapshotted after the hostname is claimed/derived — never before (the pre-claim ip-* capture is the bug class the node-env contract killed; the typed struct makes the same guarantee in Go).

type Role

type Role string

Role is the node's role in the cluster.

const (
	RoleWriter Role = "writer"
	RoleReader Role = "reader"
	RoleKeeper Role = "keeper"
	RoleBackup Role = "backup"
)

type Secrets

type Secrets struct {
	DefaultPassword  string `yaml:"default_password"           json:"default_password"`
	AdminPassword    string `yaml:"admin_password"             json:"admin_password"`
	WriterPassword   string `yaml:"writer_password,omitempty"   json:"writer_password,omitempty"`
	TLSCertificate   string `yaml:"tls_certificate,omitempty"   json:"tls_certificate,omitempty"`
	TLSPrivateKey    string `yaml:"tls_private_key,omitempty"   json:"tls_private_key,omitempty"`
	TLSCACertificate string `yaml:"tls_ca_certificate,omitempty" json:"tls_ca_certificate,omitempty"`
}

Secrets names the secret-store entries the boot must resolve.

type SpecError

type SpecError struct {
	Field  string
	Reason string
}

SpecError names the spec field that failed validation so the operator reading boot logs can fix the tfvars, not the code.

func (*SpecError) Error

func (e *SpecError) Error() string

type StateFile

type StateFile struct {
	Version  int          `json:"version"`
	Identity NodeIdentity `json:"identity"`
	Steps    []StepResult `json:"steps"`
	BootTime string       `json:"boot_time,omitempty"`
}

StateFile is the persistent, non-secret boot record. Completed steps short-circuit on re-run (convergence); identity is the settled snapshot subcommands (schema-sync, spot-watch, …) reload instead of re-deriving.

func (*StateFile) FindStep

func (st *StateFile) FindStep(name string) *StepResult

FindStep returns the recorded result for a step, or nil when it has never run to completion (Pending steps re-run).

func (*StateFile) RecordStep

func (st *StateFile) RecordStep(r StepResult)

RecordStep stores or replaces a step result.

type StepResult

type StepResult struct {
	Name      string     `json:"name"`
	Status    StepStatus `json:"status"`
	Duration  int64      `json:"duration_ms"`
	Error     string     `json:"error,omitempty"`
	StartedAt string     `json:"started_at,omitempty"`
}

StepResult records one step execution for resume and triage. Duration feeds the [TIMING] summary the bash script printed (kept verbatim dashboards grep it).

type StepStatus

type StepStatus string

StepStatus is the recorded outcome of one boot step.

const (
	StepPending StepStatus = "pending"
	StepDone    StepStatus = "done"
	StepFailed  StepStatus = "failed"
	StepSkipped StepStatus = "skipped"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL