MachineSet Controller

MachineSets are currently different from Cluster and Machine resources in that they do not define an actuator interface. They are generic controllers which implement their intent by modifying provider-specific Cluster and Machine resources.

MachineSet

// MachineSet ensures that a specified number of machines replicas are running at any given time.
// +k8s:openapi-gen=true
// +kubebuilder:resource:shortName=ms
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.labelSelector
type MachineSet struct {
    metav1.TypeMeta   `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty"`

    Spec   MachineSetSpec   `json:"spec,omitempty"`
    Status MachineSetStatus `json:"status,omitempty"`
}

MachineSetSpec

// MachineSetSpec defines the desired state of MachineSet
type MachineSetSpec struct {
    // Replicas is the number of desired replicas.
    // This is a pointer to distinguish between explicit zero and unspecified.
    // Defaults to 1.
    // +optional
    Replicas *int32 `json:"replicas,omitempty"`

    // MinReadySeconds is the minimum number of seconds for which a newly created machine should be ready.
    // Defaults to 0 (machine will be considered available as soon as it is ready)
    // +optional
    MinReadySeconds int32 `json:"minReadySeconds,omitempty"`

    // DeletePolicy defines the policy used to identify nodes to delete when downscaling.
    // Defaults to "Random".  Valid values are "Random, "Newest", "Oldest"
    // +kubebuilder:validation:Enum=Random,Newest,Oldest
    DeletePolicy string `json:"deletePolicy,omitempty"`

    // Selector is a label query over machines that should match the replica count.
    // Label keys and values that must match in order to be controlled by this MachineSet.
    // It must match the machine template's labels.
    // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
    Selector metav1.LabelSelector `json:"selector"`

    // Template is the object that describes the machine that will be created if
    // insufficient replicas are detected.
    // +optional
    Template MachineTemplateSpec `json:"template,omitempty"`
}

// MachineSetDeletePolicy defines how priority is assigned to nodes to delete when
// downscaling a MachineSet. Defaults to "Random".
type MachineSetDeletePolicy string

const (
    // RandomMachineSetDeletePolicy prioritizes both Machines that have the annotation
    // "cluster.k8s.io/delete-machine=yes" and Machines that are unhealthy
    // (Status.ErrorReason or Status.ErrorMessage are set to a non-empty value).
    // Finally, it picks Machines at random to delete.
    RandomMachineSetDeletePolicy MachineSetDeletePolicy = "Random"

    // NewestMachineSetDeletePolicy prioritizes both Machines that have the annotation
    // "cluster.k8s.io/delete-machine=yes" and Machines that are unhealthy
    // (Status.ErrorReason or Status.ErrorMessage are set to a non-empty value).
    // It then prioritizes the newest Machines for deletion based on the Machine's CreationTimestamp.
    NewestMachineSetDeletePolicy MachineSetDeletePolicy = "Newest"

    // OldestMachineSetDeletePolicy prioritizes both Machines that have the annotation
    // "cluster.k8s.io/delete-machine=yes" and Machines that are unhealthy
    // (Status.ErrorReason or Status.ErrorMessage are set to a non-empty value).
    // It then prioritizes the oldest Machines for deletion based on the Machine's CreationTimestamp.
    OldestMachineSetDeletePolicy MachineSetDeletePolicy = "Oldest"
)

MachineSetTemplateSpec

Error: marker `MachineSetTemplateSpec` not found

MachineSetStatus

// MachineSetStatus defines the observed state of MachineSet
type MachineSetStatus struct {
    // Replicas is the most recently observed number of replicas.
    Replicas int32 `json:"replicas"`

    // The number of replicas that have labels matching the labels of the machine template of the MachineSet.
    // +optional
    FullyLabeledReplicas int32 `json:"fullyLabeledReplicas,omitempty"`

    // The number of ready replicas for this MachineSet. A machine is considered ready when the node has been created and is "Ready".
    // +optional
    ReadyReplicas int32 `json:"readyReplicas,omitempty"`

    // The number of available replicas (ready for at least minReadySeconds) for this MachineSet.
    // +optional
    AvailableReplicas int32 `json:"availableReplicas,omitempty"`

    // ObservedGeneration reflects the generation of the most recently observed MachineSet.
    // +optional
    ObservedGeneration int64 `json:"observedGeneration,omitempty"`

    // In the event that there is a terminal problem reconciling the
    // replicas, both ErrorReason and ErrorMessage will be set. ErrorReason
    // will be populated with a succinct value suitable for machine
    // interpretation, while ErrorMessage will contain a more verbose
    // string suitable for logging and human consumption.
    //
    // These fields should not be set for transitive errors that a
    // controller faces that are expected to be fixed automatically over
    // time (like service outages), but instead indicate that something is
    // fundamentally wrong with the MachineTemplate's spec or the configuration of
    // the machine controller, and that manual intervention is required. Examples
    // of terminal errors would be invalid combinations of settings in the
    // spec, values that are unsupported by the machine controller, or the
    // responsible machine controller itself being critically misconfigured.
    //
    // Any transient errors that occur during the reconciliation of Machines
    // can be added as events to the MachineSet object and/or logged in the
    // controller's output.
    // +optional
    ErrorReason *common.MachineSetStatusError `json:"errorReason,omitempty"`
    // +optional
    ErrorMessage *string `json:"errorMessage,omitempty"`
}

MachineSet Controller Semantics

machineset object reconciliation logic

filter machine BLOCK

This code block examines all machines in the namespace of the machineset and filters out machines that do NOT have all the following conditions (in this order):

  1. The machine has a controller and is controlled by the machineset.
  2. The machine is not scheduled for deletion.
  3. The machine's label selector matches that of the machineset.

For machines that fails condition 1, an attempt is made to adopt the machine into the machineset. The result of this code block is a filtered list of machines that will be processed in the next code block.

sync replica BLOCK

This code block looks at the filtered machine list and determines whether to scale up or down the number of machines to match the replica count defined in the machineset.

results matching ""

    No results matching ""