uniquename

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package uniquename features utility functions that help format unique names for exporting and importing cluster-scoped and fleet-scoped resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClusterScopedUniqueName

func ClusterScopedUniqueName(format Format, namespace, name string) (string, error)

ClusterScopedUniqueName returns a name that is guaranteed to be unique within a cluster. The name is formatted using an object's namespace, its name, and a 5 character long UUID suffix; the format is [NAMESPACE]-[NAME]-[SUFFIX], e.g. an object `app` from the namespace `work` will be assigned a unique name like `work-app-1x2yz`. The function may truncate name components as it sees fit. Note: this function assumes that

  • the input object namespace is a valid RFC 1123 DNS label; and
  • the input object name follows one of the three formats used in Kubernetes (RFC 1123 DNS subdomain, RFC 1123 DNS label, RFC 1035 DNS label).

func FleetScopedUniqueName

func FleetScopedUniqueName(format Format, clusterID, namespace, name string) (string, error)

FleetScopedUniqueName returns a name that is guaranteed to be unique within a cluster. The name is formatted using an object's origin cluster, an object's namespace, its name, and a 5 character long UUID suffix; the format is [CLUSTER ID]-[NAMESPACE]-[NAME]-[SUFFIX], e.g. an object `app` from the namespace `work` in cluster `bravelion` will be assigned a unique name like `bravelion-work-app-1x2yz`. The function may truncate name components as it sees fit. Note: this function assumes that

  • the input cluster ID is a valid RFC 1123 DNS subdomain; and
  • the input object namespace is a valid RFC 1123 DNS label; and
  • the input object name follows one of the three formats used in Kubernetes (RFC 1123 DNS subdomain, RFC 1123 DNS label, RFC 1035 DNS label).

func RandomLowerCaseAlphabeticString

func RandomLowerCaseAlphabeticString(n int) string

RandomLowerCaseAlphabeticString returns a string of lower case alphabetic characters only. This function is best used for fallback cases where one cannot format a unique name as expected, as a lower case alphabetic string of proper length is always a valid Kubernetes object name, regardless of the required name format for the object (RFC 1123 DNS subdomain, RFC 1123 DNS label, or RFC 1035 DNS label).

Types

type Format

type Format int
const (
	// DNS1123Subdomain dictates that the unique name should be a valid RFC 1123 DNS subdomain.
	DNS1123Subdomain Format = 1
	// DNS1123Label dictates that the unique name should be a valid RFC 1123 DNS label.
	DNS1123Label Format = 2
	// DNS1035Label dictates that the unique name should be a valid RFC 1035 DNS label.
	DNS1035Label Format = 3
)

Jump to

Keyboard shortcuts

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