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

[OCPCLOUD-1349] Add Machine Deletion Hook consts to machine API #1050

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 40 additions & 0 deletions machine/v1beta1/0000_10_machine.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,46 @@ spec:
description: MachineSpec defines the desired state of Machine
type: object
properties:
lifecycleHooks:
description: LifecycleHooks allow users to pause operations on the machine at certain predefined points within the machine lifecycle.
type: object
properties:
preDrain:
description: PreDrain hooks prevent the machine from being drained. This also blocks further lifecycle events, such as termination.
type: array
items:
description: LifecycleHook represents a single instance of a lifecycle hook
type: object
properties:
name:
description: Name defines a unique name for the lifcycle hook. The name should be unique and descriptive, ideally 1-3 words, in CamelCase or it may be namespaced, eg. foo.example.com/CamelCase. Names must be unique and should only be managed by a single entity.
type: string
maxLength: 256
minLength: 3
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
owner:
description: Owner defines the owner of the lifecycle hook. This should be descriptive enough so that users can identify who/what is responsible for blocking the lifecycle. This could be the name of a controller (e.g. clusteroperator/etcd) or an administrator managing the hook.
type: string
maxLength: 512
minLength: 3
preTerminate:
description: PreTerminate hooks prevent the machine from being terminated. PreTerminate hooks be actioned after the Machine has been drained.
type: array
items:
description: LifecycleHook represents a single instance of a lifecycle hook
type: object
properties:
name:
description: Name defines a unique name for the lifcycle hook. The name should be unique and descriptive, ideally 1-3 words, in CamelCase or it may be namespaced, eg. foo.example.com/CamelCase. Names must be unique and should only be managed by a single entity.
type: string
maxLength: 256
minLength: 3
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
owner:
description: Owner defines the owner of the lifecycle hook. This should be descriptive enough so that users can identify who/what is responsible for blocking the lifecycle. This could be the name of a controller (e.g. clusteroperator/etcd) or an administrator managing the hook.
type: string
maxLength: 512
minLength: 3
metadata:
description: ObjectMeta will autopopulate the Node created. Use this to indicate what labels, annotations, name prefix, etc., should be used when creating the Node.
type: object
Expand Down
40 changes: 40 additions & 0 deletions machine/v1beta1/0000_10_machineset.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,46 @@ spec:
description: 'Specification of the desired behavior of the machine. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status'
type: object
properties:
lifecycleHooks:
description: LifecycleHooks allow users to pause operations on the machine at certain predefined points within the machine lifecycle.
type: object
properties:
preDrain:
description: PreDrain hooks prevent the machine from being drained. This also blocks further lifecycle events, such as termination.
type: array
items:
description: LifecycleHook represents a single instance of a lifecycle hook
type: object
properties:
name:
description: Name defines a unique name for the lifcycle hook. The name should be unique and descriptive, ideally 1-3 words, in CamelCase or it may be namespaced, eg. foo.example.com/CamelCase. Names must be unique and should only be managed by a single entity.
type: string
maxLength: 256
minLength: 3
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
owner:
description: Owner defines the owner of the lifecycle hook. This should be descriptive enough so that users can identify who/what is responsible for blocking the lifecycle. This could be the name of a controller (e.g. clusteroperator/etcd) or an administrator managing the hook.
type: string
maxLength: 512
minLength: 3
preTerminate:
description: PreTerminate hooks prevent the machine from being terminated. PreTerminate hooks be actioned after the Machine has been drained.
type: array
items:
description: LifecycleHook represents a single instance of a lifecycle hook
type: object
properties:
name:
description: Name defines a unique name for the lifcycle hook. The name should be unique and descriptive, ideally 1-3 words, in CamelCase or it may be namespaced, eg. foo.example.com/CamelCase. Names must be unique and should only be managed by a single entity.
type: string
maxLength: 256
minLength: 3
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
owner:
description: Owner defines the owner of the lifecycle hook. This should be descriptive enough so that users can identify who/what is responsible for blocking the lifecycle. This could be the name of a controller (e.g. clusteroperator/etcd) or an administrator managing the hook.
type: string
maxLength: 512
minLength: 3
metadata:
description: ObjectMeta will autopopulate the Node created. Use this to indicate what labels, annotations, name prefix, etc., should be used when creating the Node.
type: object
Expand Down
42 changes: 42 additions & 0 deletions machine/v1beta1/types_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ type MachineSpec struct {
// +optional
ObjectMeta `json:"metadata,omitempty"`

// LifecycleHooks allow users to pause operations on the machine at
// certain predefined points within the machine lifecycle.
// +optional
LifecycleHooks LifecycleHooks `json:"lifecycleHooks,omitempty"`

// The list of the taints to be applied to the corresponding Node in additive
// manner. This list will not overwrite any other taints added to the Node on
// an ongoing basis by other entities. These taints should be actively reconciled
Expand Down Expand Up @@ -194,6 +199,43 @@ type MachineSpec struct {
ProviderID *string `json:"providerID,omitempty"`
}

// LifecycleHooks allow users to pause operations on the machine at
// certain prefedined points within the machine lifecycle.
type LifecycleHooks struct {
// PreDrain hooks prevent the machine from being drained.
// This also blocks further lifecycle events, such as termination.
// +optional
PreDrain []LifecycleHook `json:"preDrain,omitempty"`

// PreTerminate hooks prevent the machine from being terminated.
// PreTerminate hooks be actioned after the Machine has been drained.
// +optional
PreTerminate []LifecycleHook `json:"preTerminate,omitempty"`
}

// LifecycleHook represents a single instance of a lifecycle hook
type LifecycleHook struct {
// Name defines a unique name for the lifcycle hook.
// The name should be unique and descriptive, ideally 1-3 words, in CamelCase or
// it may be namespaced, eg. foo.example.com/CamelCase.
// Names must be unique and should only be managed by a single entity.
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
// +kubebuilder:validation:MinLength:=3
// +kubebuilder:validation:MaxLength:=256
// +required
Name string `json:"name"`

// Owner defines the owner of the lifecycle hook.
// This should be descriptive enough so that users can identify
// who/what is responsible for blocking the lifecycle.
// This could be the name of a controller (e.g. clusteroperator/etcd)
// or an administrator managing the hook.
// +kubebuilder:validation:MinLength:=3
// +kubebuilder:validation:MaxLength:=512
// +required
Owner string `json:"owner"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this value be empty? if not can we add validation for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Value cannot be empty, it is expected to always be populated in each entry, though with what we don't specify. I think this can be free form text. Not sure what validation you had in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe some minimal length if it makes sense here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a minimum length is hard to quantify, we could put 5 characters, but then what if the owner is etcd, or something equivalently short. I think we should trust operators to put something useful within this field

Copy link
Contributor

@deads2k deads2k Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about min==3 max==512? otherwise it becomes a paragraph.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we typically have a maximum length for Condition Types? Since the name becomes part of the condition type, perhaps it's sensible to even limit at 256

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we typically have a maximum length for Condition Types? Since the name becomes part of the condition type, perhaps it's sensible to even limit at 256

We do, see comment below.

}

// MachineStatus defines the observed state of Machine
type MachineStatus struct {
// NodeRef will point to the corresponding Node if it exists.
Expand Down
15 changes: 15 additions & 0 deletions machine/v1beta1/types_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ const (
// ExternalRemediationRequestAvailable is set on machinehealthchecks when MachineHealthCheck controller uses external remediation.
// ExternalRemediationRequestAvailable is set to false if creating external remediation request fails.
ExternalRemediationRequestAvailable ConditionType = "ExternalRemediationRequestAvailable"
// MachineDrained is set on a machine to indicate that the machine has been drained. When an error occurs during
// the drain process, the condition will be added with a false status and details of the error.
MachineDrained ConditionType = "Drained"
// MachineDrainable is set on a machine to indicate whether or not the machine can be drained, or, whether some
// deletion hook is blocking the drain operation.
MachineDrainable ConditionType = "Drainable"
// MachineTerminable is set on a machine to indicate whether or not the machine can be terminated, or, whether some
// deletion hook is blocking the termination operation.
MachineTerminable ConditionType = "Terminable"
)

const (
Expand All @@ -165,6 +174,12 @@ const (
ExternalRemediationTemplateNotFound = "ExternalRemediationTemplateNotFound"
// ExternalRemediationRequestCreationFailed is the reason used when a machine health check fails to create external remediation request.
ExternalRemediationRequestCreationFailed = "ExternalRemediationRequestCreationFailed"
// MachineHookPresent indicates that a machine lifecycle hook is blocking part of the lifecycle of the machine.
// This should be used with the `Drainable` and `Terminable` machine condition types.
MachineHookPresent = "HookPresent"
// MachineDrainError indicates an error occurred when draining the machine.
// This should be used with the `Drained` condition type.
MachineDrainError = "DrainError"
)

// Condition defines an observation of a Machine API resource operational state.
Expand Down
43 changes: 43 additions & 0 deletions machine/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 26 additions & 5 deletions machine/v1beta1/zz_generated.swagger_doc_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.