constants

package
v1.16.6 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 5

README

pkg/constants

Intention

pkg/constants is the region service's shared control vocabulary. It is the single place that defines the service's canonical runtime identity and the metadata keys that other packages rely on for resource linkage, in-place API migration, image-origin discrimination, and a small amount of operational state tracking.

Most of the package is not "just constants" in the casual sense. It contains a small number of contract clusters:

  • runtime identity for the service binary
  • linkage labels that tie stored resources back to their region, identity, or network context
  • an API-generation label used to distinguish old and new external API semantics while keeping storage broadly in place
  • specialized image and server-state metadata that drives snapshot/import provenance and monitor-owned pending-state timing

The same package also defines the process-level build metadata for the running binary: application name, version, revision, and the derived service descriptor/version string used by shared runtime layers.

Invariants And Guard Rails

  • This package is a shared contract package, not a miscellaneous bucket for arbitrary constants.
  • Code that reads or writes the region service's standard labels, annotations, and tags should use these constants rather than open-coded strings.
  • RegionLabel, IdentityLabel, and NetworkLabel are part of the service's resource-linkage model. They are not optional decorative metadata.
  • ResourceAPIVersionLabel is the canonical stored discriminator used to distinguish old and new external API generations when the underlying CRD shape remains broadly stable and objects are migrated in place rather than split into separate storage models.
  • MarshalAPIVersion() and UnmarshalAPIVersion() define the current storage encoding for that API version discriminator as a decimal string.
  • ServerPendingEntryTimeAnnotation has a single-writer operational contract: the region monitor stamps it when a server enters Pending and removes it when the server leaves that state.
  • ImageSourceTag, ImageSourceImport, ImageSourceSnapshot, and ImageOrganizationIDTag are part of the current image-origin contract used to distinguish imported images pushed into OpenStack via the back channel from snapshot-derived images, and to preserve organization ownership where display and deletion semantics differ.
  • Application, Version, and Revision are the canonical runtime identity for the binary in this repository.
  • ServiceDescriptor() must remain aligned with the shared core ServiceDescriptor shape so manager and runtime code can consume it generically.
  • VersionString() must remain suitable for wire-visible client identity such as HTTP User-Agent style reporting.

Caveats

  • Changing active metadata keys here is a compatibility change across multiple packages and, in some cases, across repositories. It is not a local refactor.
  • Application is derived from os.Args[0], so reported process identity depends partly on how the binary is packaged or invoked.
  • If the build does not inject Version or Revision, the package still compiles, but much of its deployment-debugging value is lost.
  • ServerPendingEntryTimeAnnotation records an entry timestamp, but its value is not corrected while the server stays pending. Manual edits therefore remain visible until the next state transition out of and back into Pending.
  • The image-origin contract is currently encoded in generic user-visible tags, which is a weak abstraction for service-owned semantics. A typed API field would be a safer long-term design than relying on mutable key/value metadata.
  • SecurityGroupLabel and ServerLabel are currently better treated as transitional vocabulary than as strong active contracts. If their remaining consumers disappear, they are plausible deletion candidates rather than keys that should be preserved indefinitely.
  • The package mixes two related but distinct concerns: runtime service identity and resource metadata contract. That is coherent today, but it means readers should not undersell the package because of its small size.

Cross-Repo Context

This package follows the same cross-repository pattern used elsewhere for runtime identity and service descriptors, but most of its metadata vocabulary is best understood first as a region-repository contract for resource linkage, in-place API migration, image-origin handling, and monitor-managed server timing.

Documentation

Index

Constants

View Source
const (
	// ResourceAPIVersionLabel defines what API version a resource belongs to
	// for filtering purposes.
	ResourceAPIVersionLabel = "resource.unikorn-cloud.org/api-version"
	// RegionLabel creates an indexable linkage between resources and their
	// owning region.
	RegionLabel = "regions.unikorn-cloud.org/region-id"
	// IdentityLabel creates an indexable linkage between resources and an
	// owning identity.
	IdentityLabel = "regions.unikorn-cloud.org/identity-id"
	// NetworkLabel creates an indexable linkage between resources
	// and an owning entity.
	NetworkLabel = "regions.unikorn-cloud.org/network-id"
	// SecurityGroupLabel creates an indexable linkage between resources
	// and an owning entity.
	SecurityGroupLabel = "regions.unikorn-cloud.org/security-group-id"
	// ServerLabel creates an indexable linkage between resources and an
	// owning entity.
	ServerLabel = "regions.unikorn-cloud.org/server-id"
	// ServerPendingEntryTimeAnnotation records when a server entered the Pending phase.
	// Value is an RFC 3339 UTC timestamp. The region monitor is the sole writer of this
	// annotation: it is stamped on Pending entry and removed on Pending exit. Manual edits
	// to the timestamp value while the server remains Pending are not corrected — the
	// existing annotation is left intact until the server next leaves or re-enters Pending.
	ServerPendingEntryTimeAnnotation = "regions.unikorn-cloud.org/pending-entry-time"
)
View Source
const (
	ImageTagPrefix = "images.unikorn-cloud.org:"

	ImageSourceTag      = ImageTagPrefix + "source" // for the kind of source, e.g., import
	ImageSourceImport   = "import"
	ImageSourceSnapshot = "snapshot"

	ImageOrganizationIDTag = ImageTagPrefix + "organization-id"
)

Variables

View Source
var (
	// Application is the application name.
	//nolint:gochecknoglobals
	Application = path.Base(os.Args[0])

	// Version is the application version set via the Makefile.
	//nolint:gochecknoglobals
	Version string

	// Revision is the git revision set via the Makefile.
	//nolint:gochecknoglobals
	Revision string
)

Functions

func MarshalAPIVersion added in v1.10.0

func MarshalAPIVersion(i int) string

func ServiceDescriptor added in v1.9.0

func ServiceDescriptor() util.ServiceDescriptor

func UnmarshalAPIVersion added in v1.10.0

func UnmarshalAPIVersion(s string) (int, error)

func VersionString

func VersionString() string

VersionString returns a canonical version string. It's based on HTTP's User-Agent so can be used to set that too, if this ever has to call out ot other micro services.

Types

This section is empty.

Jump to

Keyboard shortcuts

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