util

package
v0.0.0-...-5ccf328 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataAnnotation         = "nephio.org/metadata"
	MetadataAnnotationNever    = "Never"
	MetadataAnnotationHere     = "Here"
	MetadataAnnotationPostpone = "Postpone"

	MergeAnnotation         = "nephio.org/merge"
	MergeAnnotationReplace  = "Replace"
	MergeAnnotationOverride = "Override"

	RenameAnnotation = "nephio.org/rename"

	PrepareAnnotation         = "nephio.org/prepare"
	PrepareAnnotationNever    = "Never"
	PrepareAnnotationHere     = "Here"
	PrepareAnnotationPostpone = "Postpone"

	ApproveAnnotation        = "nephio.org/approve"
	ApproveAnnotationDefault = "Default"
	ApproveAnnotationAuto    = "Auto"
	ApproveAnnotationManual  = "Manual"

	PreparedAnnotation = "nephio.org/prepared"
	ApprovedAnnotation = "nephio.org/approved"

	AnnotationTrue = "true"
)
View Source
const KubernetesNameEscapeRune rune = '-'
View Source
const KubernetesNameMaxLength = 253

Variables

View Source
var DeploymentGVK = NewGVK("deployment.nephio.org", "v1alpha1", "Deployment")
View Source
var DeploymentResourceIdentifier = DeploymentGVK.NewResourceIdentifier("deployment")
View Source
var KubernetesNameAllowedRE = regexp.MustCompile(`[^0-9A-Za-z\.]`)
View Source
var KubernetesNameEscapeString = runeToString(KubernetesNameEscapeRune)

Functions

func AddToStringSet

func AddToStringSet(set []string, entry string) ([]string, bool)

func CloneStringList

func CloneStringList(list []string) []string

func CloneStringMap

func CloneStringMap(map_ map[string]string) map[string]string

func DialGRPCInsecure

func DialGRPCInsecure(address string, port int) (*grpc.ClientConn, error)

func EncodePackage

func EncodePackage(format string, package_ Package) ([]byte, error)

func FromKubernetesName

func FromKubernetesName(kubernetesName string) (string, error)

Converts names created by ToKubernetesName back to their original by unescaping the escape sequences.

Will return an error if an escape sequence is malformed.

func FromKubernetesNames

func FromKubernetesNames(kubernetesMap map[string]string) (map[string]string, error)

func GetApproveAnnotation

func GetApproveAnnotation(resource Resource) (string, bool)

func GetApprovedAnnotation

func GetApprovedAnnotation(resource Resource) (string, bool)

func GetMergeAnnotation

func GetMergeAnnotation(resource Resource) (string, bool)

func GetMetadataAnnotation

func GetMetadataAnnotation(resource Resource) (string, bool)

func GetPrepareAnnotation

func GetPrepareAnnotation(resource Resource) (string, bool)

func GetPreparedAnnotation

func GetPreparedAnnotation(resource Resource) (string, bool)

func GetRenameAnnotation

func GetRenameAnnotation(resource Resource) (string, bool)

func IsApprovedAnnotation

func IsApprovedAnnotation(resource Resource) bool

func IsPreparedAnnotation

func IsPreparedAnnotation(resource Resource) bool

func ParseApiVersion

func ParseApiVersion(apiVersion string) (string, string)

func RemoveFromStringSet

func RemoveFromStringSet(set []string, entry string) ([]string, bool)

func SecondsToDuration

func SecondsToDuration(seconds float64) time.Duration

func SetApprovedAnnotation

func SetApprovedAnnotation(resource Resource, approved bool) bool

func SetPrepareAnnotation

func SetPrepareAnnotation(resource Resource, value string) bool

func SetPreparedAnnotation

func SetPreparedAnnotation(resource Resource, prepared bool) bool

func StringMapEquals

func StringMapEquals(map1 map[string]string, map2 map[string]string) bool

func ToKubernetesName

func ToKubernetesName(name string) (string, error)

Converts an arbitrary string into a valid Kubernetes name, if possible. This works by escaping illegal characters using "-" plus the Unicode code in hex, left-padded with spaces to 4 characters.

If the result is longer than is allows (253 characters), returns an error.

func ToKubernetesNames

func ToKubernetesNames(map_ map[string]string) (map[string]string, error)

func ToMapList

func ToMapList(list []any) ([]ard.Map, bool)

func TriggerToAPI

func TriggerToAPI(trigger *GVK) *api.GVK

func TriggersToAPI

func TriggersToAPI(triggers []GVK) []*api.GVK

func UpdateAnnotationsForMerge

func UpdateAnnotationsForMerge(resource Resource)

Types

type Controller

type Controller struct {
	Run      func() error
	Interval time.Duration
	Log      commonlog.Logger
	// contains filtered or unexported fields
}

func NewController

func NewController(run func() error, interval time.Duration, log commonlog.Logger) *Controller

func (*Controller) Start

func (self *Controller) Start()

func (*Controller) Stop

func (self *Controller) Stop()

type GVK

type GVK struct {
	Group   string `json:"group" yaml:"group"`
	Version string `json:"version" yaml:"version"`
	Kind    string `json:"kind" yaml:"kind"`
}

func GetGVK

func GetGVK(resource any) (GVK, bool)

func NewGVK

func NewGVK(group string, version string, kind string) GVK

func NewGVK2

func NewGVK2(apiVersion string, kind string) GVK

func TriggerFromAPI

func TriggerFromAPI(apiTrigger *api.GVK) *GVK

func TriggersFromAPI

func TriggersFromAPI(apiTriggers []*api.GVK) []GVK

func (GVK) APIVersion

func (self GVK) APIVersion() string

func (GVK) Equals

func (self GVK) Equals(gvk GVK) bool

func (GVK) Equals3

func (self GVK) Equals3(group string, version string, kind string) bool

func (GVK) Is

func (self GVK) Is(resource Resource) bool

func (GVK) NewResourceIdentifier

func (self GVK) NewResourceIdentifier(name string) ResourceIdentifier

func (GVK) ShortString

func (self GVK) ShortString() string

func (GVK) String

func (self GVK) String() string

(fmt.Stringer interface)

type Package

type Package = []Resource

func ClonePackage

func ClonePackage(package_ Package) Package

func DecodePackage

func DecodePackage(format string, content []byte) (Package, error)

func GetReferentPackage

func GetReferentPackage(objectReferences ard.List, package_ Package) (Package, error)

func MergePackage

func MergePackage(package_ Package, mergePackage ...Resource) Package

func PreparePackageForMerge

func PreparePackageForMerge(package_ Package) Package

func ReadPackage

func ReadPackage(format string, reader io.Reader) (Package, error)

type Resource

type Resource = ard.Map

func NewDeploymentResource

func NewDeploymentResource(templateId string, siteId string, prepared bool, approved bool) Resource

type ResourceIdentifier

type ResourceIdentifier struct {
	GVK  GVK    `json:",inline" yaml:",inline"`
	Name string `json:"name" yaml:"name"`
}

func NewResourceIdentifierForObjectReference

func NewResourceIdentifierForObjectReference(objectReference ard.Map) (ResourceIdentifier, bool)

func NewResourceIdentifierForResource

func NewResourceIdentifierForResource(resource Resource) (ResourceIdentifier, bool)

func (ResourceIdentifier) GetResource

func (self ResourceIdentifier) GetResource(package_ Package) (Resource, bool)

func (ResourceIdentifier) Is

func (self ResourceIdentifier) Is(resource Resource) bool

func (ResourceIdentifier) String

func (self ResourceIdentifier) String() string

(fmt.Stringer interface)

type ResourceIdentifiers

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

func (*ResourceIdentifiers) Empty

func (self *ResourceIdentifiers) Empty() bool

func (*ResourceIdentifiers) Pop

func (*ResourceIdentifiers) Push

func (self *ResourceIdentifiers) Push(resourceIdentifier ResourceIdentifier)

type TOSCAParser

type TOSCAParser struct {
	Clout *clout.Clout
	// contains filtered or unexported fields
}

func NewTOSCAParser

func NewTOSCAParser() *TOSCAParser

func (*TOSCAParser) Coerce

func (self *TOSCAParser) Coerce() error

func (*TOSCAParser) Parse

func (self *TOSCAParser) Parse(context contextpkg.Context, url string) error

func (*TOSCAParser) Release

func (self *TOSCAParser) Release() error

type Ticker

type Ticker struct {
	F func()
	// contains filtered or unexported fields
}

func NewTicker

func NewTicker(duration time.Duration, f func()) *Ticker

func (*Ticker) Start

func (self *Ticker) Start()

func (*Ticker) Stop

func (self *Ticker) Stop()

Jump to

Keyboard shortcuts

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