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: Add short options for kernel and os versions #255

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 10 additions & 1 deletion api/v1alpha1/microvmmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"reflect"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -34,7 +35,15 @@ var (

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *MicrovmMachine) ValidateCreate() error {
return nil
var allErrs field.ErrorList

allErrs = append(allErrs, r.Spec.MicrovmSpec.Validate()...)

if len(allErrs) == 0 {
return nil
}

return apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
Expand Down
30 changes: 30 additions & 0 deletions api/v1alpha1/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,33 @@ func (p *Placement) Validate() []*field.Error {

return errs
}

func (s *MicrovmMachineSpec) Validate() []*field.Error {
var errs field.ErrorList

if s.VMSpec.OsVersion == "" {
if s.RootVolume.ID == "" {
errs = append(errs,
field.Required(field.NewPath("spec", "rootVolume", "id"), "must be set if osVersion is omitted"))
}

if s.RootVolume.Image == "" {
errs = append(errs,
field.Required(field.NewPath("spec", "rootVolume", "image"), "must be set if osVersion is omitted"))
}
}

if s.VMSpec.KernelVersion == "" {
if s.Kernel.Image == "" {
errs = append(errs,
field.Required(field.NewPath("spec", "kernel", "image"), "must be set if kernelVersion is omitted"))
}

if s.Kernel.Filename == "" {
errs = append(errs,
field.Required(field.NewPath("spec", "kernel", "filename"), "must be set if kernelVersion is omitted"))
}
}

return errs
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@ spec:
type: object
type: array
required:
- kernel
- memoryMb
- networkInterfaces
- rootVolume
- vcpu
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,8 @@ spec:
type: object
type: array
required:
- kernel
- memoryMb
- networkInterfaces
- rootVolume
- vcpu
type: object
required:
Expand Down
8 changes: 6 additions & 2 deletions templates/cluster-template-cilium.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ metadata:
spec:
template:
spec:
kernelVersion: "${KERNEL_VERSION}"
osVersion: "${OS_VERSION}"
vcpu: 2
memoryMb: 2048
rootVolume:
id: root
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-kubernetes:1.23.5}"
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-k8s-os:1.23.5}"
kernel:
filename: "boot/vmlinux"
image: "${MVM_KERNEL_IMAGE:=ghcr.io/weaveworks-liquidmetal/kernel-bin:5.10.77}"
Expand Down Expand Up @@ -119,11 +121,13 @@ metadata:
spec:
template:
spec:
kernelVersion: "${KERNEL_VERSION}"
osVersion: "${OS_VERSION}"
vcpu: 2
memoryMb: 2048
rootVolume:
id: root
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-kubernetes:1.23.5}"
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-k8s-os:1.23.5}"
kernel:
filename: "boot/vmlinux"
image: "${MVM_KERNEL_IMAGE:=ghcr.io/weaveworks-liquidmetal/kernel-bin:5.10.77}"
Expand Down
8 changes: 6 additions & 2 deletions templates/cluster-template-flannel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ metadata:
spec:
template:
spec:
kernelVersion: "${KERNEL_VERSION}"
osVersion: "${OS_VERSION}"
rootVolume:
id: root
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-kubernetes:1.23.5}"
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-k8s-os:1.23.5}"
kernel:
filename: boot/vmlinux
image: "${MVM_KERNEL_IMAGE:=ghcr.io/weaveworks-liquidmetal/kernel-bin:5.10.77}"
Expand Down Expand Up @@ -121,9 +123,11 @@ metadata:
spec:
template:
spec:
kernelVersion: "${KERNEL_VERSION}"
osVersion: "${OS_VERSION}"
rootVolume:
id: root
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-kubernetes:1.23.5}"
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-k8s-os:1.23.5}"
kernel:
filename: boot/vmlinux
image: "${MVM_KERNEL_IMAGE:=ghcr.io/weaveworks-liquidmetal/kernel-bin:5.10.77}"
Expand Down
8 changes: 6 additions & 2 deletions templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ spec:
spec:
vcpu: 2
memoryMb: 2048
kernelVersion: "${KERNEL_VERSION}"
osVersion: "${OS_VERSION}"
rootVolume:
id: root
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-kubernetes:1.23.5}"
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-k8s-os:1.23.5}"
kernel:
filename: "boot/vmlinux"
image: "${MVM_KERNEL_IMAGE:=ghcr.io/weaveworks-liquidmetal/kernel-bin:5.10.77}"
Expand Down Expand Up @@ -117,9 +119,11 @@ spec:
spec:
vcpu: 2
memoryMb: 2048
kernelVersion: "${KERNEL_VERSION}"
osVersion: "${OS_VERSION}"
rootVolume:
id: root
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-kubernetes:1.23.5}"
image: "${MVM_ROOT_IMAGE:=ghcr.io/weaveworks-liquidmetal/capmvm-k8s-os:1.23.5}"
kernel:
filename: "boot/vmlinux"
image: "${MVM_KERNEL_IMAGE:=ghcr.io/weaveworks-liquidmetal/kernel-bin:5.10.77}"
Expand Down