Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Oldest and Newest delete policies and annotation-based Simple delete policy #726

Merged
merged 9 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/crds/cluster_v1alpha1_machine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ spec:
by the provider. This field must match the provider ID as seen on
the node object corresponding to this machine. This field is required
by higher level consumers of cluster-api. Example use case is cluster
autoscaler with cluster-api as provider. Clean-up login in the autoscaler
compares machines v/s nodes to find out machines at provider which
autoscaler with cluster-api as provider. Clean-up logic in the autoscaler
compares machines to nodes to find out machines at provider which
could not get registered as Kubernetes nodes. With cluster-api as
a generic out-of-tree provider for autoscaler, this field is required
by autoscaler to be able to have a provider view of the list of machines.
Another list of nodes is queries from the k8s apiserver and then comparison
Another list of nodes is queried from the k8s apiserver and then comparison
is done to find out unregistered machines and are marked for delete.
This field will be set by the actuators and consumed by higher level
entities like autoscaler who will be interfacing with cluster-api
entities like autoscaler that will be interfacing with cluster-api
as generic provider.
type: string
providerSpec:
Expand Down
10 changes: 5 additions & 5 deletions config/crds/cluster_v1alpha1_machinedeployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@ spec:
ID as seen on the node object corresponding to this machine.
This field is required by higher level consumers of cluster-api.
Example use case is cluster autoscaler with cluster-api as
provider. Clean-up login in the autoscaler compares machines
v/s nodes to find out machines at provider which could not
provider. Clean-up logic in the autoscaler compares machines
to nodes to find out machines at provider which could not
get registered as Kubernetes nodes. With cluster-api as a
generic out-of-tree provider for autoscaler, this field is
required by autoscaler to be able to have a provider view
of the list of machines. Another list of nodes is queries
from the k8s apiserver and then comparison is done to find
of the list of machines. Another list of nodes is queried
from the k8s apiserver and then a comparison is done to find
out unregistered machines and are marked for delete. This
field will be set by the actuators and consumed by higher
level entities like autoscaler who will be interfacing with
level entities like autoscaler that will be interfacing with
cluster-api as generic provider.
type: string
providerSpec:
Expand Down
19 changes: 14 additions & 5 deletions config/crds/cluster_v1alpha1_machineset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ spec:
type: object
spec:
properties:
deletePolicy:
description: DeletePolicy defines the policy used to identify nodes
to delete when downscaling. Defaults to "Random". Valid values are
"Random, "Newest", "Oldest"
enum:
- Random
- Newest
- Oldest
type: string
minReadySeconds:
description: MinReadySeconds is the minimum number of seconds for which
a newly created machine should be ready. Defaults to 0 (machine will
Expand Down Expand Up @@ -82,16 +91,16 @@ spec:
ID as seen on the node object corresponding to this machine.
This field is required by higher level consumers of cluster-api.
Example use case is cluster autoscaler with cluster-api as
provider. Clean-up login in the autoscaler compares machines
v/s nodes to find out machines at provider which could not
provider. Clean-up logic in the autoscaler compares machines
to nodes to find out machines at provider which could not
get registered as Kubernetes nodes. With cluster-api as a
generic out-of-tree provider for autoscaler, this field is
required by autoscaler to be able to have a provider view
of the list of machines. Another list of nodes is queries
from the k8s apiserver and then comparison is done to find
of the list of machines. Another list of nodes is queried
from the k8s apiserver and then a comparison is done to find
out unregistered machines and are marked for delete. This
field will be set by the actuators and consumed by higher
level entities like autoscaler who will be interfacing with
level entities like autoscaler that will be interfacing with
cluster-api as generic provider.
type: string
providerSpec:
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/cluster/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ type MachineSpec struct {
// ProviderID is the identification ID of the machine provided by the provider.
// This field must match the provider ID as seen on the node object corresponding to this machine.
// This field is required by higher level consumers of cluster-api. Example use case is cluster autoscaler
// with cluster-api as provider. Clean-up login in the autoscaler compares machines v/s nodes to find out
// with cluster-api as provider. Clean-up logic in the autoscaler compares machines to nodes to find out
// machines at provider which could not get registered as Kubernetes nodes. With cluster-api as a
// generic out-of-tree provider for autoscaler, this field is required by autoscaler to be
// able to have a provider view of the list of machines. Another list of nodes is queries from the k8s apiserver
// and then comparison is done to find out unregistered machines and are marked for delete.
// This field will be set by the actuators and consumed by higher level entities like autoscaler who will
// able to have a provider view of the list of machines. Another list of nodes is queried from the k8s apiserver
// and then a comparison is done to find out unregistered machines and are marked for delete.
// This field will be set by the actuators and consumed by higher level entities like autoscaler that will
// be interfacing with cluster-api as generic provider.
// +optional
ProviderID *string `json:"providerID,omitempty"`
Expand Down
35 changes: 35 additions & 0 deletions pkg/apis/cluster/v1alpha1/machineset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ type MachineSetSpec struct {
// +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.
Expand All @@ -70,6 +75,30 @@ type MachineSetSpec struct {
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
detiber marked this conversation as resolved.
Show resolved Hide resolved

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).
detiber marked this conversation as resolved.
Show resolved Hide resolved
// 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"
detiber marked this conversation as resolved.
Show resolved Hide resolved
)

/// [MachineSetSpec] // doxygen marker

/// [MachineTemplateSpec] // doxygen marker
Expand Down Expand Up @@ -170,6 +199,12 @@ func (m *MachineSet) Default() {
if len(m.Namespace) == 0 {
m.Namespace = metav1.NamespaceDefault
}

if m.Spec.DeletePolicy == "" {
randomPolicy := string(RandomMachineSetDeletePolicy)
log.Printf("Defaulting to %s\n", randomPolicy)
m.Spec.DeletePolicy = randomPolicy
}
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/cluster/v1alpha1/machineset_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,14 @@ func TestStorageMachineSet(t *testing.T) {
t.Error("expected error getting machineset")
}
}

func TestDefaults(t *testing.T) {
ms := &MachineSet{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
ms.Default()

expected := string(RandomMachineSetDeletePolicy)
got := ms.Spec.DeletePolicy
if got != expected {
t.Errorf("expected default machineset delete policy '%s', got '%s'", expected, got)
}
}
17 changes: 0 additions & 17 deletions pkg/client/clientset_generated/clientset/BUILD.bazel

This file was deleted.

27 changes: 0 additions & 27 deletions pkg/client/clientset_generated/clientset/fake/BUILD.bazel

This file was deleted.

19 changes: 0 additions & 19 deletions pkg/client/clientset_generated/clientset/scheme/BUILD.bazel

This file was deleted.

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions pkg/client/informers_generated/externalversions/BUILD.bazel

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions pkg/client/listers_generated/cluster/v1alpha1/BUILD.bazel

This file was deleted.

Loading