versioning

package
v0.0.0-...-1e56a0a Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const ComponentType runtime.ComponentType = "rule versioning"
View Source
const DeleteSpecJSON = "{}"

DeleteSpecJSON is the canonical snapshot stored for a rule delete marker.

Variables

View Source
var (
	ErrVersionNotFound   = errors.New("rule version not found")
	ErrVersionStoreError = errors.New("rule version store error")
	ErrRollbackToDelete  = errors.New("cannot roll back to a DELETE marker")
	ErrRollbackToCurrent = errors.New("cannot roll back to a version identical to current")
)

Functions

func HashSpecJSON

func HashSpecJSON(specJSON string) string

HashSpecJSON hashes canonical spec JSON for comparison and dedup filters. It is not sufficient on its own to prove operation source.

func NormalizeResource

func NormalizeResource(res coremodel.Resource) (string, string, error)

func NormalizeSpec

func NormalizeSpec(spec coremodel.ResourceSpec) (specHash string, specJSON string, err error)

NormalizeSpec returns the spec hash followed by canonical JSON for stable comparisons. It does not validate whether the spec is acceptable to the registry.

func RecordBootstrapState

func RecordBootstrapState(ctx context.Context, store *ResourceStoreAdapter, maxVersions int64, res coremodel.Resource) error

RecordBootstrapState creates a baseline history entry for a rule that already exists before rule history starts tracking it. Bootstrap is not reconciliation: once any history exists, startup must not record the current registry state as an UPDATE.

func ResourceFromSpecJSON

func ResourceFromSpecJSON(kind coremodel.ResourceKind, mesh, ruleName, specJSON string) (coremodel.Resource, error)

ResourceFromSpecJSON rebuilds a typed rule Resource from a stored version's spec JSON. Used by rollback to re-publish a historical snapshot through the normal ResourceManager mutation path. Only the three governor-managed rule kinds are supported. protojson is tried first (matching how specs are normalized), falling back to plain JSON for resilience.

Types

type Component

type Component interface {
	runtime.Component
	Service() *Service
}

type DiffResult

type DiffResult struct {
	Left  DiffSide `json:"left"`
	Right DiffSide `json:"right"`
}

type DiffSide

type DiffSide struct {
	VersionNo int64  `json:"versionNo"`
	SpecJSON  string `json:"specJson"`
}

type HistorySnapshot

type HistorySnapshot struct {
	Versions []Version
	Head     *Version
	Deleted  bool
}

type InsertRequest

type InsertRequest struct {
	RuleKind                coremodel.ResourceKind
	Mesh                    string
	ResourceKey             string
	RuleName                string
	SpecJSON                string
	ContentHash             string
	Source                  Source
	Operation               Operation
	Author                  string
	Reason                  string
	RolledBackFromVersionNo *int64
	CreatedAt               time.Time
}

func BuildInsertRequest

func BuildInsertRequest(res coremodel.Resource, op Operation, source Source, author, reason string, rolledBackFromVersionNo *int64, createdAt time.Time) (InsertRequest, error)

type ListResult

type ListResult struct {
	Items                   []Version `json:"items"`
	Total                   int64     `json:"total"`
	LatestRecordedVersionNo int64     `json:"latestRecordedVersionNo,omitempty"`
	LatestRecordedDeleted   bool      `json:"latestRecordedDeleted"`
}

type Operation

type Operation string
const (
	OperationCreate Operation = "CREATE"
	OperationUpdate Operation = "UPDATE"
	OperationDelete Operation = "DELETE"
)

type ResourceStoreAdapter

type ResourceStoreAdapter struct {
	// contains filtered or unexported fields
}

ResourceStoreAdapter routes RuleVersion resources through the existing resource store. The striped mutexes only keep a single adapter instance internally consistent while it derives monotonically increasing version numbers for audit entries.

func NewResourceStoreAdapter

func NewResourceStoreAdapter(versionStore store.ResourceStore) *ResourceStoreAdapter

func (*ResourceStoreAdapter) GetVersion

func (a *ResourceStoreAdapter) GetVersion(kind coremodel.ResourceKind, resourceKey string, versionNo int64) (*Version, error)

func (*ResourceStoreAdapter) HistorySnapshot

func (a *ResourceStoreAdapter) HistorySnapshot(kind coremodel.ResourceKind, resourceKey string) (*HistorySnapshot, error)

func (*ResourceStoreAdapter) InsertVersion

func (a *ResourceStoreAdapter) InsertVersion(ctx context.Context, req InsertRequest, maxVersions int64) (*Version, error)

func (*ResourceStoreAdapter) LatestVersion

func (a *ResourceStoreAdapter) LatestVersion(kind coremodel.ResourceKind, resourceKey string) (*Version, error)

func (*ResourceStoreAdapter) ListLatestVersions

func (a *ResourceStoreAdapter) ListLatestVersions(kind coremodel.ResourceKind) ([]Version, error)

func (*ResourceStoreAdapter) ListVersions

func (a *ResourceStoreAdapter) ListVersions(kind coremodel.ResourceKind, resourceKey string) ([]Version, error)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides rule history operations. RuleVersion entries are audit records and rollback material; live current state is still owned by ResourceManager and the backing registry.

func NewService

func NewService(maxVersions int64, store *ResourceStoreAdapter) *Service

func (*Service) Append

func (s *Service) Append(ctx context.Context, res coremodel.Resource, op Operation, source Source, author, reason string, rolledBackFromVersionNo *int64) (*Version, error)

func (*Service) DiffHistoryVersions

func (s *Service) DiffHistoryVersions(kind coremodel.ResourceKind, mesh, ruleName string, versionNo int64, against string) (*DiffResult, error)

func (*Service) Get

func (s *Service) Get(kind coremodel.ResourceKind, mesh, ruleName string, versionNo int64) (*Version, error)

func (*Service) HasHistory

func (s *Service) HasHistory(kind coremodel.ResourceKind, mesh, ruleName string) (bool, error)

func (*Service) LatestVersion

func (s *Service) LatestVersion(kind coremodel.ResourceKind, mesh, ruleName string) (*Version, error)

func (*Service) List

func (s *Service) List(kind coremodel.ResourceKind, mesh, ruleName string) (*ListResult, error)

type Source

type Source string

Source identifies where a rule mutation originated. Used for auditing and distinguishing user-initiated changes from system-generated ones.

const (
	SourceAdmin Source = "ADMIN" // User edit via Admin UI/API
	// SourceUpstream marks a version imported from an upstream registry event.
	SourceUpstream Source = "UPSTREAM"
	// SourceBootstrap represents a baseline record for an existing rule when it
	// is first brought under version tracking.
	SourceBootstrap Source = "BOOTSTRAP"
	// SourceRollback marks a version produced by re-publishing a historical
	// snapshot. Rollback records a new version and does not rewrite history.
	SourceRollback Source = "ROLLBACK"
)

type Version

type Version struct {
	RuleKind    coremodel.ResourceKind `json:"ruleKind"`
	Mesh        string                 `json:"mesh"`
	ResourceKey string                 `json:"resourceKey"`
	RuleName    string                 `json:"ruleName"`
	VersionNo   int64                  `json:"versionNo"`
	ContentHash string                 `json:"contentHash"`
	SpecJSON    string                 `json:"specJson"`
	Source      Source                 `json:"source"`
	Operation   Operation              `json:"operation"`
	Author      string                 `json:"author"`
	Reason      string                 `json:"reason,omitempty"`
	// RolledBackFromVersionNo records the historical version whose snapshot was
	// re-published to produce this version. It is audit metadata only.
	RolledBackFromVersionNo *int64    `json:"rolledBackFromVersionNo,omitempty"`
	CreatedAt               time.Time `json:"createdAt"`
	RecordedAt              time.Time `json:"recordedAt"`
	IsLatestRecorded        bool      `json:"isLatestRecorded"`
}

Version represents a snapshot of a rule's spec at a point in time. Version entries are immutable after creation. Rollback appends a new version, while retention may delete the oldest entries. IsLatestRecorded is derived from history only; it is not proof that this snapshot equals the live rule.

Jump to

Keyboard shortcuts

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