infrastructure

package
v4.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RandomSelector = func(ctx context.Context, groupName string, remain int, inventory *kkcorev1.Inventory) []string {
	var availableHosts []string
	groups := inventory.Spec.Groups[groupName]
	if remain > 0 {

		ungrouped, ok := variable.ConvertGroup(*inventory)[_const.VariableUnGrouped]
		if !ok {
			klog.ErrorS(nil, "Failed to get ungrouped hosts")

			return nil
		}
		shuffleHosts(ungrouped)
		availableHosts = ungrouped[:remain]
		groups.Hosts = append(groups.Hosts, availableHosts...)
		if inventory.Spec.Groups == nil {
			inventory.Spec.Groups = make(map[string]kkcorev1.InventoryGroup, 0)
		}
		inventory.Spec.Groups[groupName] = groups
	}

	return availableHosts
}

RandomSelector is a HostSelectorFunc that randomly selects hosts for a given group. If the number of requested hosts (groupHostNum) is less than the current number of hosts in the group, it shuffles the current hosts and trims the excess hosts. If the number of requested hosts is greater than the current number of hosts in the group, it adds hosts from the ungrouped hosts to meet the requested number. The function modifies the inventory to reflect the changes in the group hosts.

Returns:

HostSelectorFunc: A function that selects hosts for a group based on the specified criteria.
View Source
var SequenceSelector = func(ctx context.Context, groupName string, remain int, inventory *kkcorev1.Inventory) []string {
	var availableHosts []string
	groups := inventory.Spec.Groups[groupName]
	if remain > 0 {

		ungrouped, ok := variable.ConvertGroup(*inventory)[_const.VariableUnGrouped]
		if !ok {
			klog.ErrorS(nil, "Failed to get ungrouped hosts")

			return availableHosts
		}
		availableHosts = ungrouped[:remain]
		groups.Hosts = append(groups.Hosts, availableHosts...)
		if inventory.Spec.Groups == nil {
			inventory.Spec.Groups = make(map[string]kkcorev1.InventoryGroup, 0)
		}
		inventory.Spec.Groups[groupName] = groups
	}

	return availableHosts
}

SequenceSelector is a HostSelectorFunc that adjusts the number of hosts in a specified group within the inventory. If the specified number of hosts (groupHostNum) is less than the current number of hosts in the group, it removes the excess hosts. If the specified number is greater, it adds hosts from the ungrouped hosts to the group.

The returned function takes the following parameters: - ctx: The context for the operation. - groupName: The name of the group to adjust. - groupHostNum: The desired number of hosts in the group. - inventory: The inventory object containing the groups and hosts.

Functions

This section is empty.

Types

type HostSelectorFunc

type HostSelectorFunc = func(ctx context.Context, groupName string, groupHostNum int, inventory *kkcorev1.Inventory) []string

HostSelectorFunc is a type alias for a function that selects and synchronizes hosts from the given inventory.

This function is responsible for ensuring that the number of hosts in a specified group within the inventory matches the desired count provided by the groupHosts parameter.

Parameters: - ctx: The context for managing deadlines, cancelation signals, and other request-scoped values. - groupName: The name of the host group within the inventory to be synchronized. - groupHostNum: The number of hosts in the specified group. - inventory: A pointer to the Inventory object (kkcorev1.Inventory) from which hosts will be selected or synchronized.

type InventoryReconciler

type InventoryReconciler struct {
	ctrlclient.Client
	record.EventRecorder
}

InventoryReconciler reconciles a Inventory object

func (*InventoryReconciler) Name

func (r *InventoryReconciler) Name() string

Name implements controllers.typeController. Subtle: this method shadows the method (*Scheme).Name of InventoryReconciler.Scheme.

func (*InventoryReconciler) Reconcile

func (r *InventoryReconciler) Reconcile(ctx context.Context, req reconcile.Request) (_ reconcile.Result, retErr error)

Reconcile implements controllers.typeController.

func (*InventoryReconciler) SetupWithManager

SetupWithManager implements controllers.typeController.

type KKClusterReconciler

type KKClusterReconciler struct {
	*runtime.Scheme
	ctrlclient.Client
	record.EventRecorder
}

KKClusterReconciler reconciles a KKCluster object

func (*KKClusterReconciler) Name

func (r *KKClusterReconciler) Name() string

Name implements controllers.controller. Subtle: this method shadows the method (*Scheme).Name of KKClusterReconciler.Scheme.

func (*KKClusterReconciler) Reconcile

func (r *KKClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, retErr error)

func (*KKClusterReconciler) SetupWithManager

SetupWithManager implements controllers.controller.

type KKClusterWebhook

type KKClusterWebhook struct {
}

KKClusterWebhook reconciles a KKCluster object

func (*KKClusterWebhook) Default

func (w *KKClusterWebhook) Default(ctx context.Context, obj runtime.Object) error

Default implements admission.CustomDefaulter.

func (*KKClusterWebhook) Name

func (w *KKClusterWebhook) Name() string

Name implements controllers.Controller.

func (*KKClusterWebhook) SetupWithManager

type KKMachineReconciler

type KKMachineReconciler struct {
	ctrlclient.Client
	record.EventRecorder
	// contains filtered or unexported fields
}

KKMachineReconciler reconciles a KKMachine object. One KKMachine should have one Playbook running in time.

func (*KKMachineReconciler) Name

func (r *KKMachineReconciler) Name() string

Name implements controllers.controller.

func (*KKMachineReconciler) Reconcile

func (r *KKMachineReconciler) Reconcile(ctx context.Context, req reconcile.Request) (_ reconcile.Result, retErr error)

Reconcile implements controllers.controller.

func (*KKMachineReconciler) SetupWithManager

SetupWithManager implements controllers.controller.

Jump to

Keyboard shortcuts

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