genruntime

package
v2.0.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: MIT Imports: 19 Imported by: 18

Documentation

Overview

+kubebuilder:validation:Optional

Index

Constants

View Source
const (
	// ResourceKindNormal is a standard ARM resource.
	ResourceKindNormal = ResourceKind("normal")
	// ResourceKindExtension is an extension resource. Extension resources can have any resource as their parent.
	ResourceKindExtension = ResourceKind("extension")
)
View Source
const (
	ResourceHierarchyRootResourceGroup = ResourceHierarchyRoot("ResourceGroup")
	ResourceHierarchyRootSubscription  = ResourceHierarchyRoot("Subscription")
)
View Source
const ResourceGroupGroup = "microsoft.resources.azure.com"
View Source
const ResourceGroupKind = "ResourceGroup"

If we wanted to type-assert we'd have to solve some circular dependency problems... for now this is ok.

View Source
const (
	ResourceIDAnnotation = "resource-id.azure.com"
)

TODO: These should become Status properties at some point.

Variables

This section is empty.

Functions

func AddAnnotation

func AddAnnotation(obj MetaObject, k string, v string)

func CloneMapOfStringToString

func CloneMapOfStringToString(input map[string]string) map[string]string

CloneMapOfStringToString clones the given map[string]string. It is used (indirectly) by the generator when generating property conversions.

func ClonePointerToInt

func ClonePointerToInt(ptr *int) *int

ClonePointerToInt clones the given *int. It is used (indirectly) by the generator when generating property conversions.

func ClonePointerToString

func ClonePointerToString(ptr *string) *string

ClonePointerToString clones the given *string. It is used (indirectly) by the generator when generating property conversions.

func CloneSliceOfCondition

func CloneSliceOfCondition(slice []conditions.Condition) []conditions.Condition

CloneSliceOfCondition clones the given []conditions.Condition. It is used (indirectly) by the generator when generating property conversions.

func CloneSliceOfString

func CloneSliceOfString(slice []string) []string

CloneSliceOfString clones the given []string. It is used (indirectly) by the generator when generating property conversions.

func ExtractKubernetesResourceNameFromARMName

func ExtractKubernetesResourceNameFromARMName(armName string) string

ExtractKubernetesResourceNameFromARMName extracts the Kubernetes resource name from an ARM name. See https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/child-resource-name-type#outside-parent-resource for details on the format of the name field in ARM templates.

func GetOptionalIntValue

func GetOptionalIntValue(ptr *int) int

GetOptionalIntValue clones the given *int, or returns 0 if the pointer is nil. It is used (indirectly) by the generator when generating property conversions.

func GetOptionalStringValue

func GetOptionalStringValue(ptr *string) string

GetOptionalStringValue clones the given *string, or returns empty string if the pointer is nil. It is used (indirectly) by the generator when generating property conversions.

func GetResourceID

func GetResourceID(obj MetaObject) (string, bool)

TODO: We really want these methods to be on MetaObject itself -- should update code generator to make them at some point

func GetResourceIDOrDefault

func GetResourceIDOrDefault(obj MetaObject) string

func GetVersionedARMSpec

func GetVersionedARMSpec(metaObject MetaObject, resolved ConvertToARMResolvedDetails, scheme *runtime.Scheme) (interface{}, error)

GetVersionedARMSpec returns a spec object ready for serialization to ARM; the original API version used when the resource was first created is used to create the appropriate version for submission.

func InterleaveStrSlice

func InterleaveStrSlice(a []string, b []string) []string

InterleaveStrSlice interleaves the elements of the two provided slices. The resulting slice looks like: []{<element 1 from a>, <element 1 from b>, <element 2 from a>, <element 2 from b>...}. If one slice is longer than the other, the elements are interleaved until the shorter slice is out of elements, at which point all remaining elements are from the longer slice.

func LookupOwnerGroupKind

func LookupOwnerGroupKind(v interface{}) (string, string)

LookupOwnerGroupKind looks up an owners group and kind annotations using reflection. This is primarily used to convert from a KnownResourceReference to the more general ResourceReference

func MinInt

func MinInt(a int, b int) int

MinInt returns the minimum of the two provided ints. The fact that this doesn't exist in the Go standard library is depressing.

func NewObjectFromExemplar

func NewObjectFromExemplar(obj client.Object, scheme *runtime.Scheme) (client.Object, error)

NewObjectFromExemplar creates a new client.Object with the same GVK as the provided client.Object. The supplied client.Object is not changed and the returned client.Object is empty.

func SetResourceID

func SetResourceID(obj MetaObject, id string)

func ValidateResourceReferences

func ValidateResourceReferences(refs map[ResourceReference]struct{}) error

ValidateResourceReferences calls Validate on each ResourceReference

Types

type ARMResource

type ARMResource interface {
	Spec() ARMResourceSpec
	Status() ARMResourceStatus

	GetID() string // TODO: Should this be on Status instead?
}

func NewARMResource

func NewARMResource(spec ARMResourceSpec, status ARMResourceStatus, id string) ARMResource

type ARMResourceSpec

type ARMResourceSpec interface {
	GetAPIVersion() string

	GetType() string

	GetName() string
}

ARMResourceSpec is an ARM resource specification. This interface contains methods to access properties common to all ARM Resource Specs. An Azure Deployment is made of these.

type ARMResourceStatus

type ARMResourceStatus interface {
}

ARMResourceStatus is an ARM resource status

func NewEmptyARMStatus

func NewEmptyARMStatus(metaObject MetaObject, scheme *runtime.Scheme) (ARMResourceStatus, error)

NewEmptyARMStatus returns an empty ARM status object ready for deserialization from ARM; the original API version used when the resource was first created is used to create the appropriate version

type ARMTransformer

type ARMTransformer interface {
	ToARMConverter
	FromARMConverter
}

TODO: Consider ArmSpecTransformer and ARMTransformer, so we don't have to pass owningName/name through all the calls ARMTransformer is a type which can be converted to/from an Arm object shape. Each CRD resource must implement these methods.

type ArbitraryOwnerReference

type ArbitraryOwnerReference struct {
	// This is the name of the Kubernetes resource to reference.
	// +kubebuilder:validation:Required
	Name string `json:"name"`

	// +kubebuilder:validation:Required
	// Group is the Kubernetes group of the resource.
	Group string `json:"group"`

	// +kubebuilder:validation:Required
	// Kind is the Kubernetes kind of the resource.
	Kind string `json:"kind"`
}

ArbitraryOwnerReference is an owner reference to an unknown type. +kubebuilder:object:generate=true

func (ArbitraryOwnerReference) Copy

Copy makes an independent copy of the ArbitraryOwnerReference

func (*ArbitraryOwnerReference) DeepCopy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArbitraryOwnerReference.

func (*ArbitraryOwnerReference) DeepCopyInto

func (in *ArbitraryOwnerReference) DeepCopyInto(out *ArbitraryOwnerReference)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type ConvertToARMResolvedDetails

type ConvertToARMResolvedDetails struct {
	// Name is the name of the resource
	// TODO: We might be able to remove this in favor of using AzureName() everywhere in the future
	Name string

	// ResolvedReferences is a set of references which have been resolved to their ARM IDs.
	ResolvedReferences ResolvedReferences
}

ConvertToARMResolvedDetails contains resolved references and names for use in converting a Kubernetes type to an ARM type.

type ConvertibleSpec

type ConvertibleSpec interface {
	// ConvertSpecTo will populate the passed Spec by copying over all available information from this one
	ConvertSpecTo(destination ConvertibleSpec) error

	// ConvertSpecFrom will populate this spec by copying over all available information from the passed one
	ConvertSpecFrom(source ConvertibleSpec) error
}

ConvertibleSpec is implemented by Spec types to allow conversion among the different versions of a given spec

Why do we need both directions of conversion?

Each version of a resource is in a different package, so the implementations of this interface will necessarily be referencing types from other packages. If we tried to use an interface with a single method, we'd inevitably end up with circular package references:

+----------------+                    +----------------+
|       v1       |                    |       v2       |
|   PersonSpec   | --- import v2 ---> |   PersonSpec   |
|                |                    |                |
| ConvertTo()    | <--- import v1 --- | ConvertTo()    |
+----------------+                    +----------------+

Instead, we have to have support for both directions, so that we can always operate from one side of the package reference chain:

+----------------+                    +----------------+
|       v1       |                    |       v2       |
|   PersonSpec   |                    |   PersonSpec   |
|                |                    |                |
| ConvertTo()    | --- import v2 ---> |                |
| ConvertFrom()  |                    |                |
+----------------+                    +----------------+

func GetVersionedSpec

func GetVersionedSpec(metaObject MetaObject, scheme *runtime.Scheme) (ConvertibleSpec, error)

GetVersionedSpec returns a versioned spec for the provided resource; the original API version used when the resource was first created is used to identify the version to return

type ConvertibleStatus

type ConvertibleStatus interface {
	// ConvertStatusTo will populate the passed Status by copying over all available information from this one
	ConvertStatusTo(destination ConvertibleStatus) error

	// ConvertStatusFrom will populate this status by copying over all available information from the passed one
	ConvertStatusFrom(source ConvertibleStatus) error
}

ConvertibleStatus is implemented by status types to allow conversion among the different versions of a given status

Why do we need both directions of conversion? See ConvertibleSpec for details.

func GetVersionedStatus

func GetVersionedStatus(metaObject MetaObject, scheme *runtime.Scheme) (ConvertibleStatus, error)

GetVersionedStatus returns a versioned status for the provided resource; the original API version used when the resource was first created is used to identify the version to return

func NewEmptyVersionedStatus

func NewEmptyVersionedStatus(metaObject MetaObject, scheme *runtime.Scheme) (ConvertibleStatus, error)

NewEmptyVersionedStatus returns a blank versioned status for the provided resource; the original API version used when the resource was first created is used to identify the version to return

type Defaulter

type Defaulter interface {
	// CustomDefault performs custom defaults that are run in addition to the code generated defaults.
	CustomDefault()
}

Defaulter is similar to controller-runtime/pkg/webhook/admission Defaulter. Implementing this interface allows you to hook into the code generated defaults and add custom handcrafted defaults.

type FromARMConverter

type FromARMConverter interface {
	NewEmptyARMValue() ARMResourceStatus
	PopulateFromARM(owner ArbitraryOwnerReference, input interface{}) error
}

type GroupVersionKindAware

type GroupVersionKindAware interface {
	// OriginalGVK returns the GroupVersionKind originally used to create the resource (regardless of any conversions)
	OriginalGVK() *schema.GroupVersionKind
}

GroupVersionKindAware is implemented by resources that are aware of which version of the resource was originally specified. This allows us to interace with ARM using an API version specified by an end user.

type KnownResourceReference

type KnownResourceReference struct {
	// This is the name of the Kubernetes resource to reference.
	// +kubebuilder:validation:Required
	Name string `json:"name"`
}

KnownResourceReference is a resource reference to a known type. +kubebuilder:object:generate=true

func (KnownResourceReference) Copy

Copy makes an independent copy of the KnownResourceReference

func (*KnownResourceReference) DeepCopy

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KnownResourceReference.

func (*KnownResourceReference) DeepCopyInto

func (in *KnownResourceReference) DeepCopyInto(out *KnownResourceReference)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type KubernetesResource

type KubernetesResource interface {
	conditions.Conditioner

	// Owner returns the ResourceReference of the owner, or nil if there is no owner
	Owner() *ResourceReference

	// AzureName returns the Azure name of the resource
	AzureName() string

	// GetType returns the type of the resource according to Azure. For example Microsoft.Resources/resourceGroups or
	// Microsoft.Network/networkSecurityGroups/securityRules
	GetType() string

	// GetResourceKind returns the ResourceKind of the resource.
	GetResourceKind() ResourceKind

	// GetAPIVersion returns the API Version of the resource
	GetAPIVersion() string

	// GetSpec returns the specification of the resource
	GetSpec() ConvertibleSpec

	// GetStatus returns the current status of the resource
	GetStatus() ConvertibleStatus

	// NewEmptyStatus returns a blank status ready for population
	NewEmptyStatus() ConvertibleStatus

	// SetStatus updates the status of the resource
	SetStatus(status ConvertibleStatus) error
}

KubernetesResource is an Azure resource. This interface contains the common set of methods that apply to all ASO resources.

type LocatableResource

type LocatableResource interface {
	Location() string
}

TODO: The generated types should impl this

type MetaObject

type MetaObject interface {
	runtime.Object
	metav1.Object
	KubernetesResource
}

MetaObject represents an arbitrary ASO custom resource

func NewEmptyVersionedResource

func NewEmptyVersionedResource(metaObject MetaObject, scheme *runtime.Scheme) (MetaObject, error)

NewEmptyVersionedResource returns a new blank resource based on the passed metaObject; the original API version used (if available) from when the resource was first created is used to identify the version to return. Returns an empty resource.

type PropertyBag

type PropertyBag map[string]string

PropertyBag is an unordered set of stashed information that used for properties not directly supported by storage resources, allowing for full fidelity round trip conversions We store items in the bag as serialized JSON, which we can then deserialize in a just-in-time fashion once we know the type of the instance we're going to populate. Unlike other platforms, Go doesn't embed type information as it serializes to JSON or YAML, which means that deserialization requires a type hint that's not available when our containing resource is hydrated. We only have the required type available when we are doing the conversion to a related type.

func NewPropertyBag

func NewPropertyBag(originals ...PropertyBag) PropertyBag

PropertyBag returns a new property bag originals is a (potentially empty) sequence of existing property bags who's content will be copied into the new property bag. In the case of key overlaps, values from bags later in the parameter list overwrite the earlier value.

func (PropertyBag) Add

func (bag PropertyBag) Add(property string, value interface{}) error

Add is used to add a value into the bag; exact formatting depends on the type. Any existing value will be overwritten. property is the name of the item to put into the bag value is the instance to be stashed away for later

func (PropertyBag) Contains

func (bag PropertyBag) Contains(name string) bool

Contains returns true if the specified name is present in the bag; false otherwise

func (PropertyBag) Pull

func (bag PropertyBag) Pull(property string, destination interface{}) error

Pull removes a value from the bag, using it to populate the destination property is the name of the item to remove and return destination should be a pointer to where the value is to be placed If the item is present and successfully deserialized, returns no error (nil); otherwise returns an error. If an error happens deserializing an item from the bag, it is still removed from the bag.

type Reconciler

type Reconciler interface {
	Reconcile(ctx context.Context) (ctrl.Result, error)
}

type ReferenceNotFound

type ReferenceNotFound struct {
	NamespacedName types.NamespacedName
	// contains filtered or unexported fields
}

func NewReferenceNotFoundError

func NewReferenceNotFoundError(name types.NamespacedName, cause error) *ReferenceNotFound

func (*ReferenceNotFound) Cause

func (e *ReferenceNotFound) Cause() error

func (*ReferenceNotFound) Error

func (e *ReferenceNotFound) Error() string

func (*ReferenceNotFound) Format

func (e *ReferenceNotFound) Format(s fmt.State, verb rune)

This was adapted from the function in errors

func (*ReferenceNotFound) Is

func (e *ReferenceNotFound) Is(err error) bool

type ResolvedReferences

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

ResolvedReferences is a set of references which have been resolved for a particular resource. The special self field is the fully qualified ARM ID of the resource that this ResolvedReferences applies to.

func MakeResolvedReferences

func MakeResolvedReferences(references map[ResourceReference]string) ResolvedReferences

MakeResolvedReferences creates a ResolvedReferences from the fully qualified ARM ID of the resource and and ARM IDs that the resource refers to.

func (ResolvedReferences) ARMID

ARMID looks up the fully qualified ARM ID for the given reference. If it cannot be found, false is returned for the second parameter.

func (ResolvedReferences) ARMIDOrErr

func (r ResolvedReferences) ARMIDOrErr(ref ResourceReference) (string, error)

ARMIDOrErr looks up the fully qualified ARM ID for the given reference. If it cannot be found, an error is returned.

type Resolver

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

func NewResolver

func NewResolver(client *kubeclient.Client, reconciledResourceLookup map[schema.GroupKind]schema.GroupVersionKind) *Resolver

func (*Resolver) ResolveOwner

func (r *Resolver) ResolveOwner(ctx context.Context, obj MetaObject) (MetaObject, error)

ResolveOwner returns the MetaObject for the given resources owner. If the resource is supposed to have an owner but doesn't, this returns an ReferenceNotFound error. If the resource is not supposed to have an owner (for example, ResourceGroup), returns nil.

func (*Resolver) ResolveReference

func (r *Resolver) ResolveReference(ctx context.Context, ref ResourceReference) (MetaObject, error)

ResolveReference resolves a reference, or returns an error if the reference is not pointing to a KubernetesResource

func (*Resolver) ResolveReferenceToARMID

func (r *Resolver) ResolveReferenceToARMID(ctx context.Context, ref ResourceReference) (string, error)

ResolveReferenceToARMID gets a references ARM ID. If the reference is just pointing to an ARM resource then the ARMID is returned. If the reference is pointing to a Kubernetes resource, that resource is looked up and its ARM ID is computed.

func (*Resolver) ResolveReferencesToARMIDs

func (r *Resolver) ResolveReferencesToARMIDs(ctx context.Context, refs map[ResourceReference]struct{}) (ResolvedReferences, error)

ResolveReferencesToARMIDs resolves all provided references to their ARM IDs.

func (*Resolver) ResolveResourceHierarchy

func (r *Resolver) ResolveResourceHierarchy(ctx context.Context, obj MetaObject) (ResourceHierarchy, error)

ResolveResourceHierarchy gets the resource hierarchy for a given resource. The result is a slice of resources, with the uppermost parent at position 0 and the resource itself at position len(slice)-1

func (*Resolver) Scheme

func (r *Resolver) Scheme() *runtime.Scheme

Scheme returns the current scheme from our client

type ResourceHierarchy

type ResourceHierarchy []MetaObject

func (ResourceHierarchy) AzureName

func (h ResourceHierarchy) AzureName() string

AzureName returns the Azure name for use in creating a resource.

func (ResourceHierarchy) FullyQualifiedARMID

func (h ResourceHierarchy) FullyQualifiedARMID(subscriptionID string) (string, error)

FullyQualifiedARMID returns the fully qualified ARM ID of the resource

func (ResourceHierarchy) Location

func (h ResourceHierarchy) Location() (string, error)

Location returns the location root of the hierarchy, or an error if the root is not a subscription.

func (ResourceHierarchy) ResourceGroup

func (h ResourceHierarchy) ResourceGroup() (string, error)

ResourceGroup returns the resource group that the hierarchy is in, or an error if the hierarchy is not rooted in a resource group.

func (ResourceHierarchy) RootKind

type ResourceHierarchyRoot

type ResourceHierarchyRoot string

type ResourceKind

type ResourceKind string

type ResourceReference

type ResourceReference struct {
	// Group is the Kubernetes group of the resource.
	Group string `json:"group,omitempty"`
	// Kind is the Kubernetes kind of the resource.
	Kind string `json:"kind,omitempty"`
	// Namespace is the Kubernetes namespace of the resource.
	Namespace string `json:"namespace,omitempty"`
	// Name is the Kubernetes name of the resource.
	Name string `json:"name,omitempty"`

	// TODO: The below regex may be overly restrictive
	// +kubebuilder:validation:Pattern="(?i)^/subscriptions/([^/]+)(/resourcegroups/([^/]+))?/providers/([^/]+)/([^/]+/[^/]+)(/([^/]+/[^/]+))*$"
	// ARMID is a string of the form /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}.
	// The /resourcegroups/{resourceGroupName} bit is optional as some resources are scoped at the subscription level
	// ARMID is mutually exclusive with Group, Kind, Namespace and Name.
	ARMID string `json:"armId,omitempty"`
}

ResourceReference represents a resource reference, either to a Kubernetes resource or directly to an Azure resource via ARMID +kubebuilder:object:generate=true

func (ResourceReference) Copy

Copy makes an independent copy of the ResourceReference

func (*ResourceReference) DeepCopy

func (in *ResourceReference) DeepCopy() *ResourceReference

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceReference.

func (*ResourceReference) DeepCopyInto

func (in *ResourceReference) DeepCopyInto(out *ResourceReference)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (ResourceReference) IsDirectARMReference

func (ref ResourceReference) IsDirectARMReference() bool

func (ResourceReference) IsKubernetesReference

func (ref ResourceReference) IsKubernetesReference() bool

func (ResourceReference) String

func (ref ResourceReference) String() string

func (ResourceReference) Validate

func (ref ResourceReference) Validate() error

TODO: We wouldn't need this if controller-gen supported DUs or OneOf better, see: https://github.com/kubernetes-sigs/controller-tools/issues/461 Validate validates the ResourceReference to ensure that it is structurally valid.

type ToARMConverter

type ToARMConverter interface {
	// ConvertToARM converts this to an ARM resource.
	ConvertToARM(resolved ConvertToARMResolvedDetails) (interface{}, error)
}

type Validator

type Validator interface {
	// CreateValidations returns validation functions that should be run on create.
	CreateValidations() []func() error
	// UpdateValidations returns validation functions that should be run on update.
	UpdateValidations() []func(old runtime.Object) error
	// DeleteValidations returns validation functions taht should be run on delete.
	DeleteValidations() []func() error
}

Validator is similar to controller-runtime/pkg/webhook/admission Validator. Implementing this interface allows you to hook into the code generated validations and add custom handcrafted validations.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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