component

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: Apache-2.0 Imports: 38 Imported by: 30

Documentation

Index

Constants

View Source
const (
	PhaseScheduledForApplication = "ScheduledForApplication"
	PhaseScheduledForDeletion    = "ScheduledForDeletion"
	PhaseScheduledForCompletion  = "ScheduledForCompletion"
	PhaseCreating                = "Creating"
	PhaseUpdating                = "Updating"
	PhaseDeleting                = "Deleting"
	PhaseCompleting              = "Completing"
	PhaseReady                   = "Ready"
	PhaseCompleted               = "Completed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component interface {
	client.Object
	// Return target namespace for the component deployment.
	// This is the value that will be passed to Generator.Generate() as namespace.
	// In addition, rendered namespaced resources without namespace will be placed in this namespace.
	GetDeploymentNamespace() string
	// Return target name for the component deployment.
	// This is the value that will be passed to Generator.Generator() as name.
	GetDeploymentName() string
	// Return a pointer accessor to the component's spec.
	// Which, as a consequence, obviously has to implement the types.Unstructurable interface.
	GetSpec() types.Unstructurable
	// Return a pointer accessor to the component's status,
	// resp. to the corresponding sub-struct if the status extends component.Status.
	GetStatus() *Status
}

Component is the central interface that component operators have to implement. Besides being a conroller-runtime client.Object, the implementing type has to include the Spec and Status structs defined in this package, and has to define according accessor methods, called GetComponentSpec() and GetComponentStatus(). In addition it has to expose its whole spec and status as Unstructurable objects, via methods GetSpec() and GetStatus().

type Condition

type Condition struct {
	Type ConditionType `json:"type"`
	// +kubebuilder:validation:Enum=True;False;Unknown
	Status ConditionStatus `json:"status"`
	// +optional
	LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
	// +optional
	Reason string `json:"reason,omitempty"`
	// +optional
	Message string `json:"message,omitempty"`
}

Component status Condition.

func (*Condition) DeepCopy

func (in *Condition) DeepCopy() *Condition

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

func (*Condition) DeepCopyInto

func (in *Condition) DeepCopyInto(out *Condition)

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

type ConditionStatus

type ConditionStatus string

Condition Status. Can be one of 'True', 'False', 'Unknown'.

const (
	// Condition status 'True'.
	ConditionTrue ConditionStatus = "True"
	// Condition status 'False'.
	ConditionFalse ConditionStatus = "False"
	// Condition status 'Unknown'.
	ConditionUnknown ConditionStatus = "Unknown"
)

type ConditionType

type ConditionType string

Condition type. Currently, only the 'Ready' type is used.

const (
	// Condition type representing the 'Ready' condition.
	ConditionTypeReady ConditionType = "Ready"
)

type HookFunc

type HookFunc[T Component] func(ctx context.Context, client client.Client, component T) error

HookFunc is the function signature that can be used to establish callbacks at certain points in the reconciliation logic. Hooks will be passed the current (potentially unsaved) state of the component. Post-hooks will only be called if the previous operator (read, reconcile, delete) has been successful.

type ImageSpec

type ImageSpec struct {
	// +kubebuilder:validation:MinLength=1
	Repository string `json:"repository,omitempty"`
	// +kubebuilder:validation:MinLength=1
	Tag string `json:"tag,omitempty"`
	// +kubebuilder:validation:Enum=Always;Never;IfNotPresent
	// +kubebuilder:default=IfNotPresent
	PullPolicy string `json:"pullPolicy,omitempty"`
	PullSecret string `json:"pullSecret,omitempty"`
}

ImageSpec defines the used OCI image

func (*ImageSpec) DeepCopy

func (in *ImageSpec) DeepCopy() *ImageSpec

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

func (*ImageSpec) DeepCopyInto

func (in *ImageSpec) DeepCopyInto(out *ImageSpec)

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

type IngressProperties

type IngressProperties struct {
	Class       string            `json:"class,omitempty"`
	Labels      map[string]string `json:"labels,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty"`
}

IngressProperties defines K8s properties to be applied to a managed ingress resource.

func (*IngressProperties) DeepCopy

func (in *IngressProperties) DeepCopy() *IngressProperties

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

func (*IngressProperties) DeepCopyInto

func (in *IngressProperties) DeepCopyInto(out *IngressProperties)

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

type InventoryItem

type InventoryItem struct {
	// Type of the dependent object.
	TypeInfo `json:",inline"`
	// Namespace and name of the dependent object.
	NameInfo `json:",inline"`
	// Managed types
	ManagedTypes []TypeInfo `json:"managedTypes,omitempty"`
	// Digest of the descriptor of the dependent object.
	Digest string `json:"digest"`
	// Phase of the dependent object.
	Phase string `json:"phase,omitempty"`
	// Observed status of the dependent object, as observed by kstatus.
	Status string `json:"status,omitempty"`
}

InventoryItem represents a dependent object managed by this operator.

func (*InventoryItem) DeepCopy

func (in *InventoryItem) DeepCopy() *InventoryItem

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

func (*InventoryItem) DeepCopyInto

func (in *InventoryItem) DeepCopyInto(out *InventoryItem)

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

func (InventoryItem) GetName

func (i InventoryItem) GetName() string

Get inventory item's name.

func (InventoryItem) GetNamespace

func (i InventoryItem) GetNamespace() string

Get inventory item's namespace.

func (*InventoryItem) GetObjectKind

func (i *InventoryItem) GetObjectKind() schema.ObjectKind

Get inventory item's ObjectKind accessor.

func (InventoryItem) GroupVersionKind

func (i InventoryItem) GroupVersionKind() schema.GroupVersionKind

Get inventory item's GroupVersionKind.

func (InventoryItem) Matches

func (i InventoryItem) Matches(key types.ObjectKey) bool

Check whether inventory item matches given ObjectKey, in the sense that Group, Kind, Namespace and Name are the same. Note that this does not compare the group's Version.

func (*InventoryItem) SetGroupVersionKind

func (i *InventoryItem) SetGroupVersionKind(gvk schema.GroupVersionKind)

Set inventory item's GroupVersionKind.

func (InventoryItem) String

func (i InventoryItem) String() string

Return a string representation of the inventory item; makes InventoryItem implement the Stringer interface.

type KubernetesContainerProperties

type KubernetesContainerProperties struct {
	SecurityContext *corev1.SecurityContext      `json:"securityContext,omitempty"`
	Resources       *corev1.ResourceRequirements `json:"resources,omitempty"`
}

KubernetesContainerProperties defines K8s properties to be applied to the created workloads (container level)

func (*KubernetesContainerProperties) DeepCopy

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

func (*KubernetesContainerProperties) DeepCopyInto

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

type KubernetesPodProperties

type KubernetesPodProperties struct {
	NodeSelector              map[string]string                 `json:"nodeSelector,omitempty"`
	Affinity                  *corev1.Affinity                  `json:"affinity,omitempty"`
	TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
	Tolerations               []corev1.Toleration               `json:"tolerations,omitempty"`
	PriorityClassName         *string                           `json:"priorityClassName,omitempty"`
	PodSecurityContext        *corev1.PodSecurityContext        `json:"podSecurityContext,omitempty"`
	Labels                    map[string]string                 `json:"podLabels,omitempty"`
	Annotations               map[string]string                 `json:"podAnnotations,omitempty"`
}

KubernetesPodProperties defines K8s properties to be applied to the created workloads (pod level)

func (*KubernetesPodProperties) DeepCopy

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

func (*KubernetesPodProperties) DeepCopyInto

func (in *KubernetesPodProperties) DeepCopyInto(out *KubernetesPodProperties)

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

type KubernetesProperties

type KubernetesProperties struct {
	KubernetesPodProperties       `json:",inline"`
	KubernetesContainerProperties `json:",inline"`
}

KubernetesProperties defines a union of KubernetesPodProperties and KubernetesContainerProperties. Useful in cases where a controller pod has exactly one container.

func (*KubernetesProperties) DeepCopy

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

func (*KubernetesProperties) DeepCopyInto

func (in *KubernetesProperties) DeepCopyInto(out *KubernetesProperties)

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

type NameInfo

type NameInfo struct {
	// Namespace of the referenced object; empty for non-namespaced objects
	Namespace string `json:"namespace,omitempty"`
	// Name of the referenced object.
	Name string `json:"name"`
}

NameInfo represents an object's namespace and name.

type Reconciler

type Reconciler[T Component] struct {
	// contains filtered or unexported fields
}

Reconciler provides the implementation of controller-runtime's Reconciler interface, for a given Component type T.

func NewReconciler

func NewReconciler[T Component](name string, client client.Client, discoveryClient discovery.DiscoveryInterface, recorder record.EventRecorder, scheme *runtime.Scheme, resourceGenerator manifests.Generator) *Reconciler[T]

Create a new Reconciler. Here:

  • name should be a meaningful and unique name identifying this reconciler with the Kubernetes cluster; it will be used in annotations, finalizers, and so on
  • client should be a controller-runtime client for the current cluster; it should have informer caching disabled for the reconciled type T, as well as for apiextensionsv1.CustomResourceDefinition and apiregistrationv1.APIService
  • discoveryClient should be a discovery client for the current cluster
  • scheme is required to recognize the core group (corev1), the api group containing T, and apiextensionsv1 and apiregistrationv1; in addition, scheme must know about all concrete (i.e. non-unstructured) types returned by the given resource generator
  • resourceGenerator must be an implementation of the manifests.Generator interface.

func (*Reconciler[T]) Reconcile

func (r *Reconciler[T]) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error)

Reconcile contains the actual reconciliation logic.

func (*Reconciler[T]) SetupWithManager

func (r *Reconciler[T]) SetupWithManager(mgr ctrl.Manager) error

Register the reconciler with a given controller-runtime Manager.

func (*Reconciler[T]) WithPostDeleteHook

func (r *Reconciler[T]) WithPostDeleteHook(hook HookFunc[T]) *Reconciler[T]

Register post-delete hook with reconciler. This hook will be called if the reconciled component is in deletion (has a deletionTimestamp set), right after the deletion of the dependent objects happened, and was successful.

func (*Reconciler[T]) WithPostReadHook

func (r *Reconciler[T]) WithPostReadHook(hook HookFunc[T]) *Reconciler[T]

Register post-read hook with reconciler. This hook will be called after the reconciled component object has been retrieved from the Kubernetes API.

func (*Reconciler[T]) WithPostReconcileHook

func (r *Reconciler[T]) WithPostReconcileHook(hook HookFunc[T]) *Reconciler[T]

Register post-reconcile hook with reconciler. This hook will be called if the reconciled component is not in deletion (has no deletionTimestamp set), right after the reconcilation of the dependent objects happened, and was successful.

func (*Reconciler[T]) WithPreDeleteHook

func (r *Reconciler[T]) WithPreDeleteHook(hook HookFunc[T]) *Reconciler[T]

Register pre-delete hook with reconciler. This hook will be called if the reconciled component is in deletion (has a deletionTimestamp set), right before the deletion of the dependent objects starts.

func (*Reconciler[T]) WithPreReconcileHook

func (r *Reconciler[T]) WithPreReconcileHook(hook HookFunc[T]) *Reconciler[T]

Register pre-reconcile hook with reconciler. This hook will be called if the reconciled component is not in deletion (has no deletionTimestamp set), right before the reconcilation of the dependent objects starts.

type ServiceProperties

type ServiceProperties struct {
	// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer;ExternalName
	// +kubebuilder:default=ClusterIP
	Type                     corev1.ServiceType `json:"type,omitempty"`
	LoadBalancerSourceRanges []string           `json:"loadBalancerSourceRanges,omitempty"`
	// +kubebuilder:validation:Enum=Cluster;Local
	// +kubebuilder:default=Cluster
	ExternalTrafficPolicy corev1.ServiceExternalTrafficPolicyType `json:"externalTrafficPolicy,omitempty"`
	Labels                map[string]string                       `json:"labels,omitempty"`
	Annotations           map[string]string                       `json:"annotations,omitempty"`
}

ServiceProperties defines K8s properties to be applied to a managed service resource.

func (*ServiceProperties) DeepCopy

func (in *ServiceProperties) DeepCopy() *ServiceProperties

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

func (*ServiceProperties) DeepCopyInto

func (in *ServiceProperties) DeepCopyInto(out *ServiceProperties)

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

type Spec

type Spec struct {
	Namespace string `json:"namespace,omitempty"`
	Name      string `json:"name,omitempty"`
}

Component Spec. Types implementing the Component interface may include this into their spec.

func (*Spec) DeepCopy

func (in *Spec) DeepCopy() *Spec

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

func (*Spec) DeepCopyInto

func (in *Spec) DeepCopyInto(out *Spec)

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

type State

type State string

Component state. Can be one of 'Ready', 'Processing', 'Error', 'Deleting'.

const (
	// Component state 'Ready'.
	StateReady State = "Ready"
	// Component state 'Processing'.
	StateProcessing State = "Processing"
	// Component state 'Error'.
	StateError State = "Error"
	// Component state 'Deleting'.
	StateDeleting State = "Deleting"
)

type Status

type Status struct {
	ObservedGeneration int64        `json:"observedGeneration"`
	AppliedGeneration  int64        `json:"appliedGeneration,omitempty"`
	LastObservedAt     *metav1.Time `json:"lastObservedAt,omitempty"`
	LastAppliedAt      *metav1.Time `json:"lastAppliedAt,omitempty"`
	Conditions         []Condition  `json:"conditions,omitempty"`
	// +kubebuilder:validation:Enum=Processing;Deleting;Ready;Error
	State     State            `json:"state,omitempty"`
	Inventory []*InventoryItem `json:"inventory,omitempty"`
}

Component Status. Types implementing the Component interface must include this into their status.

func (*Status) DeepCopy

func (in *Status) DeepCopy() *Status

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

func (*Status) DeepCopyInto

func (in *Status) DeepCopyInto(out *Status)

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

func (*Status) GetState

func (s *Status) GetState() (State, string, string)

Get state (and related details).

func (*Status) SetState

func (s *Status) SetState(state State, reason string, message string)

Set state and ready condition in status (according to the state value provided),

type TypeInfo

type TypeInfo struct {
	// API group.
	Group string `json:"group"`
	// API group version.
	Version string `json:"version"`
	// API kind.
	Kind string `json:"kind"`
}

TypeInfo represents a Kubernetes type.

Jump to

Keyboard shortcuts

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