Skip to content

Commit

Permalink
Merge pull request #1050 from JoelSpeed/mdh-consts
Browse files Browse the repository at this point in the history
[OCPCLOUD-1349] Add Machine Deletion Hook consts to machine API
  • Loading branch information
openshift-merge-robot authored Nov 22, 2021
2 parents 313e51e + e7f5dde commit bc2d3cf
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 5 deletions.
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"`
}

// 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.

0 comments on commit bc2d3cf

Please sign in to comment.