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

feat(vm): autogenerate crd #350

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
16 changes: 14 additions & 2 deletions api/Taskfile.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ tasks:
deps:
- _ensure:k8s-codegen-mod
- _ensure:k8s-kube-openapi
cmd: ./scripts/update-codegen.sh all
cmds:
- ./scripts/update-codegen.sh all
- task: format:yaml

generate:core:
desc: "Regenerate code for core components."
Expand All @@ -40,7 +42,17 @@ tasks:
desc: "Regenerate crds"
deps:
- _ensure:k8s-controller-gen
cmd: ./scripts/update-codegen.sh crds
cmds:
- ./scripts/update-codegen.sh crds
- task: format:yaml

format:yaml:
desc: "Format non-templated YAML files, e.g. CRDs"
cmds:
- |
cd ../ && docker run --rm \
-v ./:/tmp/virt ghcr.io/deckhouse/virtualization/prettier:3.2.5 \
sh -c "cd /tmp/virt ; prettier -w \"**/*.yaml\" \"**/*.yml\""

_ci:verify-gen:
desc: "Check generated files are up-to-date."
Expand Down
30 changes: 22 additions & 8 deletions api/core/v1alpha2/block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,33 @@ package v1alpha2

type BlockDeviceSpecRef struct {
Kind BlockDeviceKind `json:"kind"`
Name string `json:"name"`
// The name of attached resource.
Name string `json:"name"`
}

type BlockDeviceStatusRef struct {
Kind BlockDeviceKind `json:"kind"`
Name string `json:"name"`
Size string `json:"size"`
Target string `json:"target"`
Attached bool `json:"attached"`
Hotplugged bool `json:"hotplugged,omitempty"`
VirtualMachineBlockDeviceAttachmentName string `json:"virtualMachineBlockDeviceAttachmentName,omitempty"`
Kind BlockDeviceKind `json:"kind"`
// The name of attached resource.
Name string `json:"name"`
// The size of attached block device.
Size string `json:"size"`
// The block device is attached to the virtual machine.
Attached bool `json:"attached"`
// The name of attached block device.
// +kubebuilder:example=sda
Target string `json:"target,omitempty"`
// Block device is attached via hot plug connection.
Hotplugged bool `json:"hotplugged,omitempty"`
// The name of the `VirtualMachineBlockDeviceAttachment` resource that defines hot plug disk connection to the virtual machine.
VirtualMachineBlockDeviceAttachmentName string `json:"virtualMachineBlockDeviceAttachmentName,omitempty"`
}

// The BlockDeviceKind is a type of the block device. Options are:
//
// * `ClusterVirtualImage` — Use `ClusterVirtualImage` as the disk. This type is always mounted in RO mode. If the image is an iso-image, it will be mounted as a CDROM device.
// * `VirtualImage` — Use `VirtualImage` as the disk. This type is always mounted in RO mode. If the image is an iso-image, it will be mounted as a CDROM device.
// * `VirtualDisk` — Use `VirtualDisk` as the disk. This type is always mounted in RW mode.
// +kubebuilder:validation:Enum:={ClusterVirtualImage,VirtualImage,VirtualDisk}
type BlockDeviceKind string

const (
Expand Down
296 changes: 226 additions & 70 deletions api/core/v1alpha2/virtual_machine.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/core/v1alpha2/virtual_machine_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
// +kubebuilder:object:root=true
// +kubebuilder:metadata:labels={heritage=deckhouse,module=virtualization}
// +kubebuilder:subresource:status
// +kubebuilder:resource:categories=virtualization,scope=Cluster,shortName={vmc,vmcs,vmclass,vmclasses},singular=virtualmachineclass
// +kubebuilder:resource:categories={virtualization},scope=Cluster,shortName={vmc,vmcs,vmclass,vmclasses},singular=virtualmachineclass
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="VirtualMachineClass phase."
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time of creation resource."
// +genclient
Expand All @@ -55,7 +55,7 @@ type VirtualMachineClassList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

// Items provides a list of CDIs
// Items provides a list of VirtualMachineClasses
Items []VirtualMachineClass `json:"items"`
}

Expand Down
5 changes: 5 additions & 0 deletions api/core/v1alpha2/vmaffinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// VMAffinity [The same](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity) as in the pods `spec.affinity` parameter in Kubernetes;
//
// The affinity setting is completely similar to the above documentation, the only difference is in the names of some parameters. In fact, the following analogs are used:
// * podAffinity -> virtualMachineAndPodAffinity
// * podAffinityTerm -> virtualMachineAndPodAffinityTerm
type VMAffinity struct {
NodeAffinity *corev1.NodeAffinity `json:"nodeAffinity,omitempty"`
VirtualMachineAndPodAffinity *VirtualMachineAndPodAffinity `json:"virtualMachineAndPodAffinity,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions api/core/v1alpha2/vmcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func (r Reason) String() string {
}

const (
ReasonUnknown Reason = "Unknown"

ReasonAgentNotReady Reason = "AgentNotReady"

ReasonClassReady Reason = "VirtualMachineClassReady"
Expand Down
76 changes: 76 additions & 0 deletions api/core/v1alpha2/zz_generated.deepcopy.go

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

Loading