Skip to content

Commit

Permalink
feat: Add documentation for virtualMachineTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
alperencelik committed Sep 18, 2024
1 parent 982c0d8 commit 32cce3f
Show file tree
Hide file tree
Showing 6 changed files with 370 additions and 2 deletions.
11 changes: 11 additions & 0 deletions api/proxmox/v1alpha1/virtualmachinetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type VirtualMachineTemplateSpec struct {
Name string `json:"name"`
// NodeName is the node name
NodeName string `json:"node"`
// +kubebuilder:default:=false
DeletionProtection bool `json:"deletionProtection,omitempty"`

// VirtualMachineConfig is the configuration of the VM
VirtualMachineConfig VirtualMachineConfig `json:"virtualMachineConfig,omitempty"`
Expand Down Expand Up @@ -108,6 +110,15 @@ type VirtualMachineTemplateStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName="vmt"
//+kubebuilder:printcolumn:name="Node",type="string",JSONPath=".spec.node",description="The node name"
//+kubebuilder:printcolumn:name="Cores",type="string",JSONPath=".spec.virtualMachineConfig.cores",description="The number of cores"
//+kubebuilder:printcolumn:name="Memory",type="string",JSONPath=".spec.virtualMachineConfig.memory",description="The amount of memory"
//+kubebuilder:printcolumn:name="Image",type="string",JSONPath=".spec.imageConfig.filename",description="The name of the image"
//+kubebuilder:printcolumn:name="Username",type="string",JSONPath=".spec.cloudInitConfig.user",description="The username"
//+kubebuilder:printcolumn:name="Password",type="string",JSONPath=".spec.cloudInitConfig.password",description="The password"
//+kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.condition[0].type",description="The status of the VM"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// VirtualMachineTemplate is the Schema for the virtualmachinetemplates API
type VirtualMachineTemplate struct {
Expand Down
269 changes: 269 additions & 0 deletions charts/kubemox/templates/crds/virtualmachinetemplate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
name: virtualmachinetemplates.proxmox.alperen.cloud
spec:
conversion:
strategy: None
group: proxmox.alperen.cloud
names:
kind: VirtualMachineTemplate
listKind: VirtualMachineTemplateList
plural: virtualmachinetemplates
shortNames:
- vmt
singular: virtualmachinetemplate
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: The node name
jsonPath: .spec.node
name: Node
type: string
- description: The number of cores
jsonPath: .spec.virtualMachineConfig.cores
name: Cores
type: string
- description: The amount of memory
jsonPath: .spec.virtualMachineConfig.memory
name: Memory
type: string
- description: The name of the image
jsonPath: .spec.imageConfig.filename
name: Image
type: string
- description: The username
jsonPath: .spec.cloudInitConfig.user
name: Username
type: string
- description: The password
jsonPath: .spec.cloudInitConfig.password
name: Password
type: string
- description: The status of the VM
jsonPath: .status.condition[0].type
name: Status
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: VirtualMachineTemplate is the Schema for the virtualmachinetemplates
API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: VirtualMachineTemplateSpec defines the desired state of VirtualMachineTemplate
properties:
cloudInitConfig:
description: Cloud Init Config
properties:
dnsDomain:
description: DNS Domain
type: string
dnsServers:
description: DNS Servers
items:
type: string
type: array
ipConfig:
description: IPConfig is the IP configuration for the VM
properties:
cidr:
description: Subnet Mask
type: string
gateway:
description: Gateway
type: string
gatewayIPv6:
description: GatewayIPv6
type: string
ip:
description: IP Address
type: string
ipv6:
description: IPv6 Address
type: string
type: object
password:
description: Password is the password for the template
type: string
sshKeys:
description: SSH Keys -- suppose to be on openSSH format
items:
type: string
type: array
upgradePackages:
default: true
description: Upgrade Packages
type: boolean
user:
description: User is the user name for the template
type: string
type: object
deletionProtection:
default: false
type: boolean
imageConfig:
description: Image config
properties:
checksum:
description: Optional fields
type: string
checksumAlgorithm:
type: string
compression:
type: string
content:
pattern: \b(iso|vztmpl)\b
type: string
filename:
type: string
node:
type: string
storage:
default: local
type: string
url:
type: string
verifyCertificate:
type: boolean
required:
- content
- filename
- node
- url
type: object
name:
description: Name is the name of the VM
type: string
node:
description: NodeName is the node name
type: string
virtualMachineConfig:
description: VirtualMachineConfig is the configuration of the VM
properties:
cores:
default: 2
description: Cores
type: integer
memory:
default: 2048
description: Memory as MB
type: integer
network:
properties:
bridge:
default: vmbr0
type: string
model:
default: virtio
type: string
type: object
sockets:
default: 1
description: Sockets
type: integer
type: object
required:
- imageConfig
- name
- node
type: object
status:
description: VirtualMachineTemplateStatus defines the observed state of
VirtualMachineTemplate
properties:
condition:
description: 'INSERT ADDITIONAL STATUS FIELD - define observed state
of cluster Important: Run "make" to regenerate code after modifying
this file'
items:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
\n type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
// +listType=map // +listMapKey=type Conditions ]metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
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: 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: 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.
enum:
- "True"
- "False"
- Unknown
type: string
type:
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
status:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,44 @@ spec:
kind: VirtualMachineTemplate
listKind: VirtualMachineTemplateList
plural: virtualmachinetemplates
shortNames:
- vmt
singular: virtualmachinetemplate
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: The node name
jsonPath: .spec.node
name: Node
type: string
- description: The number of cores
jsonPath: .spec.virtualMachineConfig.cores
name: Cores
type: string
- description: The amount of memory
jsonPath: .spec.virtualMachineConfig.memory
name: Memory
type: string
- description: The name of the image
jsonPath: .spec.imageConfig.filename
name: Image
type: string
- description: The username
jsonPath: .spec.cloudInitConfig.user
name: Username
type: string
- description: The password
jsonPath: .spec.cloudInitConfig.password
name: Password
type: string
- description: The status of the VM
jsonPath: .status.condition[0].type
name: Status
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: VirtualMachineTemplate is the Schema for the virtualmachinetemplates
Expand Down Expand Up @@ -81,6 +115,9 @@ spec:
description: User is the user name for the template
type: string
type: object
deletionProtection:
default: false
type: boolean
imageConfig:
description: Image config
properties:
Expand Down
45 changes: 45 additions & 0 deletions docs/crds/virtualmachinetemplate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# VirtualMachineTemplate

`VirtualMachineTemplate` is a Kubernetes Custom Resource Definition (CRD) that defines a template for a VirtualMachine. It is used to create a VirtualMachine object and then converts that into a template for future use. It utilizes the 'CloudInit' behind the scenes to configure the VirtualMachine. `VirtualMachineTemplate` has three main specs that you can define:

- `cloudInitConfig`: This struct includes cloud-init configuration that will be used to configure the VirtualMachine. This field is mandatory to create a VirtualMachineTemplate.

- `imageConfig`: This struct includes the image configuration that will be used to create the VirtualMachine from the template. You should use cloud-init compatible images within this field.

- `virtualMachineConfig`: This struct includes the VirtualMachine configuration that will be used to create the VirtualMachine from the template. You can define the VirtualMachine configuration like cores, memory, disk, network, etc. within this field. This is non-mandatory struct and default values will be used if not defined.


## Creating VirtualMachineTemplate

To create a new VirtualMachineTemplate in Proxmox, you need to create a `VirtualMachineTemplate` object. This object should be generated by other VirtualMachineTemplate objects.

```yaml
apiVersion: proxmox.alperen.cloud/v1alpha1
kind: VirtualMachineTemplate
metadata:
name: virtualmachinetemplate-sample
spec:
name: virtualmachinetemplate-sample
node: lowtower
cloudInitConfig:
ipConfig:
cidr: "24"
gateway: 10.153.0.1
ip: 10.153.0.99
password: ubuntu
upgradePackages: true
user: ubuntu
imageConfig:
content: iso
filename: bionic-server-cloudimg-amd64.img
node: lowtower
storage: local
url: https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
virtualMachineConfig:
cores: 2
memory: 2048
network:
bridge: vmbr0
model: virtio
sockets: 1
```
Loading

0 comments on commit 32cce3f

Please sign in to comment.