genruntime

package
v0.0.0-...-a37997b Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 18 Imported by: 0

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 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 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 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 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

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 fully qualified name of the resource in Azure ("a/b/c").
	Name string

	// Scope is the scope the resource is deployed at. This is nil for resources which are not
	// extension resources
	Scope *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()  |                    |                |
+----------------+                    +----------------+

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.

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 DeployableResource

type DeployableResource interface {
	Spec() ARMResourceSpec
}

type FromARMConverter

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

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

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

	// GetStatus returns the current status of the resource
	GetStatus() 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

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

type ResourceGroupResource

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

ResourceGroupResource represents a resource which can be deployed to Azure inside of a resource group.

func NewDeployableResourceGroupResource

func NewDeployableResourceGroupResource(resourceGroup string, spec ARMResourceSpec) *ResourceGroupResource

func (*ResourceGroupResource) ResourceGroup

func (r *ResourceGroupResource) ResourceGroup() string

func (*ResourceGroupResource) Spec

type ResourceHierarchy

type ResourceHierarchy []MetaObject

func (ResourceHierarchy) FullAzureName

func (h ResourceHierarchy) FullAzureName() string

FullAzureName returns the full Azure name for use in creating a resource. For normal resources this name is the full "path" to the resource being deployed. For example, a Virtual Network Subnet's name might be: "myvnet/mysubnet". For extension resources, this is the name of the last resource in the hierarchy (the extension resource itself).

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

func (ResourceHierarchy) Scope

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

Scope returns the scope of the resource hierarchy. An error is returned if the last resource in the hierarchy has any ResourceKind other than ResourceKindExtension.

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 SubscriptionResource

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

SubscriptionResource represents a resource which can be deployed to Azure directly in a subscription (not inside of a resource group).

func NewDeployableSubscriptionResource

func NewDeployableSubscriptionResource(location string, spec ARMResourceSpec) *SubscriptionResource

func (*SubscriptionResource) Location

func (r *SubscriptionResource) Location() string

func (*SubscriptionResource) Spec

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