Skip to content

Commit

Permalink
feat(api): improve crd conditions (#487)
Browse files Browse the repository at this point in the history
Make all crds have the same conditions
---------
Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat authored Nov 5, 2024
1 parent b649734 commit 44e2679
Show file tree
Hide file tree
Showing 59 changed files with 611 additions and 268 deletions.
1 change: 1 addition & 0 deletions api/core/v1alpha2/virtual_machine_block_disk_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type VirtualMachineBlockDeviceAttachmentStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

// A block device that will be connected to the VM as a hot Plug disk.
type VMBDAObjectRef struct {
// The type of the block device. Options are:
// * `VirtualDisk` — use `VirtualDisk` as the disk. This type is always mounted in RW mode.
Expand Down
4 changes: 3 additions & 1 deletion api/core/v1alpha2/virtual_machine_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ type NodeSelector struct {
// A map of {key,value} pairs.
// A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value".
// The requirements are ANDed.
MatchLabels map[string]string `json:"matchLabels,omitempty"`
MatchLabels map[string]string `json:"matchLabels,omitempty"`
// A list of node selector requirements by node's labels.
MatchExpressions []corev1.NodeSelectorRequirement `json:"matchExpressions,omitempty"`
}

Expand Down Expand Up @@ -206,6 +207,7 @@ type VirtualMachineClassStatus struct {
// The maximum amount of free CPU and Memory resources observed among all available nodes.
// +kubebuilder:example={"maxAllocatableResources: {\"cpu\": 1, \"memory\": \"10Gi\"}"}
MaxAllocatableResources corev1.ResourceList `json:"maxAllocatableResources,omitempty"`
// The latest detailed observations of the VirtualMachineClass resource.
Conditions []metav1.Condition `json:"conditions,omitempty"`
// The generation last processed by the controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Expand Down
5 changes: 3 additions & 2 deletions api/core/v1alpha2/virtual_machine_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ type VirtualMachineSnapshotStatus struct {
// The name of underlying `Secret`, created for virtual machine snapshotting.
VirtualMachineSnapshotSecretName string `json:"virtualMachineSnapshotSecretName,omitempty"`
// The list of `VirtualDiskSnapshot` names for the snapshots taken from the virtual disks of the associated virtual machine.
VirtualDiskSnapshotNames []string `json:"virtualDiskSnapshotNames,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
VirtualDiskSnapshotNames []string `json:"virtualDiskSnapshotNames,omitempty"`
// The latest detailed observations of the VirtualMachineSnapshot resource.
Conditions []metav1.Condition `json:"conditions,omitempty"`
// The generation last processed by the controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}
Expand Down
4 changes: 0 additions & 4 deletions api/core/v1alpha2/vm-restore-condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ type (
)

const (
// VirtualMachineSnapshotUnknown represents unknown condition state.
VirtualMachineSnapshotUnknown VirtualMachineSnapshotReadyToUseReason = "Unknown"
// VirtualMachineSnapshotNotFound indicates that the specified virtual machine snapshot is absent.
VirtualMachineSnapshotNotFound VirtualMachineSnapshotReadyToUseReason = "VirtualMachineSnapshotNotFound"
// VirtualMachineSnapshotNotReady indicates that the specified virtual machine snapshot is not ready.
VirtualMachineSnapshotNotReady VirtualMachineSnapshotReadyToUseReason = "VirtualMachineSnapshotNotReady"
// VirtualMachineSnapshotReadyToUse indicates that the specified virtual machine snapshot is ready to restore.
VirtualMachineSnapshotReadyToUse VirtualMachineSnapshotReadyToUseReason = "VirtualMachineSnapshotReadyToUse"

// VirtualMachineRestoreUnknown represents unknown condition state.
VirtualMachineRestoreUnknown VirtualMachineRestoreReadyReason = "Unknown"
// VirtualMachineSnapshotNotReadyToUse signifies that the virtual machine snapshot is not ready to use.
VirtualMachineSnapshotNotReadyToUse VirtualMachineRestoreReadyReason = "VirtualMachineSnapshotNotReadyToUse"
// VirtualMachineRestoreConflict signifies that the virtual machine cannot be restored as it's resources already exist.
Expand Down
6 changes: 0 additions & 6 deletions api/core/v1alpha2/vmbdacondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,16 @@ type (
)

const (
// BlockDeviceReadyUnknown represents unknown condition state.
BlockDeviceReadyUnknown BlockDeviceReadyReason = "Unknown"
// BlockDeviceReady signifies that the block device is ready to be hot-plugged, allowing the hot-plug process to start.
BlockDeviceReady BlockDeviceReadyReason = "BlockDeviceReady"
// BlockDeviceNotReady signifies that the block device is not ready, preventing the hot-plug process from starting.
BlockDeviceNotReady BlockDeviceReadyReason = "BlockDeviceNotReady"

// VirtualMachineReadyUnknown represents unknown condition state.
VirtualMachineReadyUnknown VirtualMachineReadyReason = "Unknown"
// VirtualMachineReady signifies that the virtual machine is ready for hot-plugging a disk, allowing the hot-plug process to start.
VirtualMachineReady VirtualMachineReadyReason = "VirtualMachineReady"
// VirtualMachineNotReady signifies that the virtual machine is not ready, preventing the hot-plug process from starting.
VirtualMachineNotReady VirtualMachineReadyReason = "VirtualMachineNotReady"

// AttachedUnknown represents unknown condition state.
AttachedUnknown BlockDeviceReadyReason = "Unknown"
// Attached signifies that the virtual disk is successfully hot-plugged into the virtual machine.
Attached AttachedReason = "Attached"
// NotAttached signifies that the virtual disk is not yet hot-plugged into the virtual machine.
Expand Down
2 changes: 0 additions & 2 deletions api/core/v1alpha2/vmclasscondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,4 @@ const (
ReasonDiscoverySucceeded Reason = "DiscoverySucceeded"
ReasonDiscoverySkip Reason = "DiscoverySkip"
ReasonDiscoveryFailed Reason = "DiscoveryFailed"

ReasonUnknown Reason = "Unknown"
)
2 changes: 0 additions & 2 deletions api/core/v1alpha2/vmcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func (r Reason) String() string {
}

const (
ReasonUnknown Reason = "Unknown"

ReasonAgentNotReady Reason = "AgentNotReady"

ReasonClassReady Reason = "VirtualMachineClassReady"
Expand Down
4 changes: 0 additions & 4 deletions api/core/v1alpha2/vmopcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func (r ReasonCompleted) String() string {
}

const (
ReasonCompletedUnknown ReasonCompleted = "Unknown"

// ReasonVirtualMachineNotFound is a ReasonCompleted indicating that the specified virtual machine is absent.
ReasonVirtualMachineNotFound ReasonCompleted = "VirtualMachineNotFound"

Expand Down Expand Up @@ -79,8 +77,6 @@ func (r ReasonSignalSent) String() string {
}

const (
ReasonSignalSentUnknown ReasonSignalSent = "Unknown"

// ReasonSignalSentError is a ReasonCompleted indicating an error occurred while sending powerstate signal to the VM.
ReasonSignalSentError ReasonSignalSent = "SignalSentError"

Expand Down
4 changes: 0 additions & 4 deletions api/core/v1alpha2/vmscondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ type (
)

const (
// VirtualMachineUnknown signifies that the state of virtual machine is unknown, preventing the snapshot process from starting.
VirtualMachineUnknown VirtualMachineReadyReason = "Unknown"
// VirtualMachineReady signifies that the virtual machine is ready for snapshotting, allowing the snapshot process to begin.
VirtualMachineReady VirtualMachineReadyReason = "VirtualMachineReady"
// VirtualMachineNotReadyForSnapshotting signifies that the virtual machine is not ready for snapshotting, preventing the snapshot process from starting.
VirtualMachineNotReadyForSnapshotting VirtualMachineReadyReason = "VirtualMachineNotReadyForSnapshotting"

// VirtualMachineSnapshotUnknown signifies that the state of virtual machine snapshot is unknown.
VirtualMachineSnapshotUnknown VirtualMachineSnapshotReadyReason = "Unknown"
// WaitingForTheVirtualMachine signifies that the snapshot process is waiting for the virtual machine to become ready for snapshotting.
WaitingForTheVirtualMachine VirtualMachineSnapshotReadyReason = "WaitingForTheVirtualMachine"
// RestartAwaitingChanges signifies that the snapshotting process cannot begin because the virtual machine has awaiting changes.
Expand Down
12 changes: 8 additions & 4 deletions api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go

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

65 changes: 53 additions & 12 deletions crds/clustervirtualimages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,34 +195,75 @@ spec:
conditions:
description: |
The latest available observations of an object's current state.
type: array
items:
type: object
description:
"Condition contains details for one aspect of the current
state of this API Resource.\n---\nThis struct is intended for
direct use as an array at the field path .status.conditions. For
example,\n\n\n\ttype FooStatus struct{\n\t // Represents the
observations of a foo's current state.\n\t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t //
+patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t
\ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
\ // other fields\n\t}"
properties:
lastProbeTime:
description: Last time the condition was checked.
format: date-time
type: string
lastTransitionTime:
description: Last time the condition transit from one status to another.
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: Human readable message indicating details about last transition.
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: (brief) reason for the condition's last transition.
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: Status of the condition, one of True, False, Unknown.
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
enum: ["True", "False", "Unknown"]
type:
description: Type of condition.
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
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])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
downloadSpeed:
type: object
description: |
Expand Down
11 changes: 6 additions & 5 deletions crds/doc-ru-clustervirtualimages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ spec:
description: ""
sha256:
description: ""
insecureSkipVerify:
description: |
Отключить проверку TLS-сертификата (небезопасно и не должно использоваться в производственных средах).
url:
description: |
Для образа расположенного по URL, поддерживаются следующие типы образов:
Expand Down Expand Up @@ -98,13 +95,17 @@ spec:
description: |
Последнее подтвержденное состояние данного ресурса.
items:
description: |
condition содержит подробные сведения об одном аспекте текущего состояния этого ресурса API.
properties:
lastProbeTime:
description: Время проверки условия.
lastTransitionTime:
description: Время перехода условия из одного состояния в другое.
message:
description: Удобочитаемое сообщение с подробной информацией о последнем переходе.
observedGeneration:
description: |
observedGeneration представляет собой .metadata.generation, на основе которого было установлено условие.
Например, если .metadata.generation в настоящее время имеет значение 12, а .status.conditions[x].observedgeneration имеет значение 9, то условие устарело.
reason:
description: Краткая причина последнего перехода состояния.
status:
Expand Down
8 changes: 6 additions & 2 deletions crds/doc-ru-virtualdisks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ spec:
description: |
Последнее подтвержденное состояние данного ресурса.
items:
description: |
condition содержит подробные сведения об одном аспекте текущего состояния этого ресурса API.
properties:
lastProbeTime:
description: Время проверки условия.
lastTransitionTime:
description: Время перехода условия из одного состояния в другое.
message:
description: Удобочитаемое сообщение с подробной информацией о последнем переходе.
observedGeneration:
description: |
observedGeneration представляет собой .metadata.generation, на основе которого было установлено условие.
Например, если .metadata.generation в настоящее время имеет значение 12, а .status.conditions[x].observedgeneration имеет значение 9, то условие устарело.
reason:
description: Краткая причина последнего перехода состояния.
status:
Expand Down
8 changes: 6 additions & 2 deletions crds/doc-ru-virtualdisksnapshots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ spec:
description: |
Последнее подтвержденное состояние данного ресурса.
items:
description: |
condition содержит подробные сведения об одном аспекте текущего состояния этого ресурса API.
properties:
lastProbeTime:
description: Время проверки условия.
lastTransitionTime:
description: Время перехода условия из одного состояния в другое.
message:
description: Удобочитаемое сообщение с подробной информацией о последнем переходе.
observedGeneration:
description: |
observedGeneration представляет собой .metadata.generation, на основе которого было установлено условие.
Например, если .metadata.generation в настоящее время имеет значение 12, а .status.conditions[x].observedgeneration имеет значение 9, то условие устарело.
reason:
description: Краткая причина последнего перехода состояния.
status:
Expand Down
Loading

0 comments on commit 44e2679

Please sign in to comment.